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