screeps/objects/impls/ruin.rs
1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{
5    objects::{RoomObject, Store, Structure},
6    prelude::*,
7};
8
9#[wasm_bindgen]
10extern "C" {
11    /// A [`Ruin`], which represents a destroyed structure and can have
12    /// resources withdrawn from it.
13    ///
14    /// [Screeps documentation](https://docs.screeps.com/api/#Ruin)
15    #[wasm_bindgen(extends = RoomObject)]
16    #[derive(Clone, Debug)]
17    pub type Ruin;
18
19    /// The tick that the structure was destroyed
20    ///
21    /// [Screeps documentation](https://docs.screeps.com/api/#Ruin.destroyTime)
22    #[wasm_bindgen(method, getter = destroyTime)]
23    pub fn destroy_time(this: &Ruin) -> u32;
24
25    /// Object ID of the ruin, which can be used to efficiently fetch a fresh
26    /// reference to the object on subsequent ticks.
27    ///
28    /// [Screeps documentation](https://docs.screeps.com/api/#Ruin.id)
29    #[wasm_bindgen(method, getter = id)]
30    fn id_internal(this: &Ruin) -> JsString;
31
32    /// The [`Store`] of the ruin, which contains any resources in the ruin.
33    ///
34    /// [Screeps documentation](https://docs.screeps.com/api/#Ruin.store)
35    #[wasm_bindgen(method, getter)]
36    pub fn store(this: &Ruin) -> Store;
37
38    /// The destroyed [`Structure`] that this ruin represents. Note that this
39    /// object is not fully safe to use as a [`Structure`], missing critical
40    /// properties such as position; it's only safe to access basic information
41    /// about the structure on this object, like the structure type, owner name,
42    /// and id.
43    ///
44    /// [Screeps documentation](https://docs.screeps.com/api/#Ruin.structure)
45    #[wasm_bindgen(method, getter)]
46    pub fn structure(this: &Ruin) -> Structure;
47
48    /// The number of ticks until this ruin disappears.
49    ///
50    /// [Screeps documentation](https://docs.screeps.com/api/#Ruin.ticksToDecay)
51    #[wasm_bindgen(method, getter = ticksToDecay)]
52    pub fn ticks_to_decay(this: &Ruin) -> u32;
53}
54
55impl CanDecay for Ruin {
56    fn ticks_to_decay(&self) -> u32 {
57        Self::ticks_to_decay(self)
58    }
59}
60
61impl HasId for Ruin {
62    fn js_raw_id(&self) -> JsString {
63        Self::id_internal(self)
64    }
65}
66
67impl HasStore for Ruin {
68    fn store(&self) -> Store {
69        Self::store(self)
70    }
71}
72
73impl Withdrawable for Ruin {}