screeps/objects/impls/score.rs
1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{objects::RoomObject, prelude::*};
5
6#[wasm_bindgen]
7extern "C" {
8 /// An reference to a javascript object representing a [`Score`], which
9 /// appears randomly around the map and adds to your score when stepped on
10 /// by one of your creeps.
11 ///
12 /// [Screeps documentation](https://docs-season.screeps.com/api/#Score)
13 #[wasm_bindgen(extends = RoomObject)]
14 #[derive(Clone, Debug)]
15 pub type Score;
16
17 #[wasm_bindgen(method, getter = id)]
18 fn id_internal(this: &Score) -> JsString;
19
20 /// The amount of [`Score`] that this object is worth when collected by a
21 /// creep.
22 ///
23 /// [Screeps documentation](https://docs-season.screeps.com/api/#Score.score)
24 #[wasm_bindgen(method, getter)]
25 pub fn score(this: &Score) -> u32;
26
27 /// The number of ticks until the [`Score`] will decay, disappearing
28 /// completely.
29 ///
30 /// [Screeps documentation](https://docs-season.screeps.com/api/#Score.ticksToDecay)
31 #[wasm_bindgen(method, getter = ticksToDecay)]
32 pub fn ticks_to_decay(this: &Score) -> u32;
33}
34
35impl CanDecay for Score {
36 fn ticks_to_decay(&self) -> u32 {
37 Self::ticks_to_decay(self)
38 }
39}
40
41impl HasId for Score {
42 fn js_raw_id(&self) -> JsString {
43 Self::id_internal(self)
44 }
45}