screeps/objects/impls/
reactor.rs

1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{
5    objects::{Owner, RoomObject, Store},
6    prelude::*,
7};
8
9#[wasm_bindgen]
10extern "C" {
11    /// An object representing a [`Reactor`], which process [`Thorium`] to gain
12    /// season score.
13    ///
14    /// [Screeps documentation](https://docs-season.screeps.com/api/#Reactor)
15    ///
16    /// [`Thorium`]: crate::constants::ResourceType::Thorium
17    #[wasm_bindgen(extends = RoomObject)]
18    #[derive(Clone, Debug)]
19    pub type Reactor;
20
21    #[wasm_bindgen(method, getter = id)]
22    fn id_internal(this: &Reactor) -> JsString;
23
24    /// Ticks of continuous work this reactor has done.
25    ///
26    /// [Screeps documentation](https://docs-season.screeps.com/api/#Reactor.continuousWork)
27    #[wasm_bindgen(method, getter = continuousWork)]
28    pub fn continuous_work(this: &Reactor) -> u32;
29
30    /// The [`Store`] of the reactor, which contains information about what
31    /// [`Thorium`] it is it holding.
32    ///
33    /// [Screeps documentation](https://docs-season.screeps.com/api/#Reactor.store)
34    ///
35    /// [`Thorium`]: crate::constants::ResourceType::Thorium
36    #[wasm_bindgen(method, getter)]
37    pub fn store(this: &Reactor) -> Store;
38
39    // owner and my are on OwnedStructure and we'd usually inherit them, but since
40    // it inherits Structure, and Reactor is not a Structure, implementing these
41    // directly.
42    /// Whether this reactor is owned by the player.
43    ///
44    /// [Screeps documentation](https://docs-season.screeps.com/api/#Reactor.my)
45    #[wasm_bindgen(method, getter)]
46    pub fn my(this: &Reactor) -> bool;
47
48    /// The [`Owner`] of this reactor that contains the owner's username, or
49    /// `None` if it's currently not under a player's control.
50    ///
51    /// [Screeps documentation](https://docs-season.screeps.com/api/#Reactor.owner)
52    #[wasm_bindgen(method, getter)]
53    pub fn owner(this: &Reactor) -> Option<Owner>;
54}
55
56impl HasId for Reactor {
57    fn js_raw_id(&self) -> JsString {
58        Self::id_internal(self)
59    }
60}
61
62impl HasStore for Reactor {
63    fn store(&self) -> Store {
64        Self::store(self)
65    }
66}
67
68impl Transferable for Reactor {}