screeps/objects/impls/symbol_container.rs
1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{
5    constants::ResourceType,
6    objects::{RoomObject, Store},
7    prelude::*,
8};
9
10#[wasm_bindgen]
11extern "C" {
12    /// An object representing a [`SymbolContainer`], which appears randomly
13    /// around the map and contains symbol resources which can be
14    /// collected.
15    ///
16    /// [Screeps documentation](https://docs-season.screeps.com/api/#SymbolContainer)
17    ///
18    /// [`ResourceType::Score`]: crate::constants::ResourceType::Score
19    #[wasm_bindgen(extends = RoomObject)]
20    #[derive(Clone, Debug)]
21    pub type SymbolContainer;
22
23    /// Object ID of the collector, which can be used to efficiently fetch a
24    /// fresh reference to the object on subsequent ticks.
25    ///
26    /// [Screeps documentation](https://docs-season.screeps.com/api/#SymbolContainer.id)
27    #[wasm_bindgen(method, getter = id)]
28    fn id_internal(this: &SymbolContainer) -> JsString;
29
30    /// The [`Store`] of the container, which contains information about what
31    /// resources it is it holding.
32    ///
33    /// [Screeps documentation](https://docs-season.screeps.com/api/#SymbolContainer.store)
34    #[wasm_bindgen(method, getter)]
35    pub fn store(this: &SymbolContainer) -> Store;
36
37    /// The number of ticks until the [`SymbolContainer`] will decay,
38    /// disappearing completely.
39    ///
40    /// [Screeps documentation](https://docs-season.screeps.com/api/#SymbolContainer.ticksToDecay)
41    #[wasm_bindgen(method, getter = ticksToDecay)]
42    pub fn ticks_to_decay(this: &SymbolContainer) -> u32;
43
44    /// The [`ResourceType`] contained within this [`SymbolContainer`] to score
45    /// points.
46    ///
47    /// [Screeps documentation](https://docs-season.screeps.com/api/#SymbolContainer.resourceType)
48    #[wasm_bindgen(method, getter = resourceType)]
49    pub fn resource_type(this: &SymbolContainer) -> ResourceType;
50
51}
52
53impl CanDecay for SymbolContainer {
54    fn ticks_to_decay(&self) -> u32 {
55        Self::ticks_to_decay(self)
56    }
57}
58
59impl HasId for SymbolContainer {
60    fn js_raw_id(&self) -> JsString {
61        Self::id_internal(self)
62    }
63}
64
65impl HasStore for SymbolContainer {
66    fn store(&self) -> Store {
67        Self::store(self)
68    }
69}
70
71impl Withdrawable for SymbolContainer {}