screeps/objects/impls/deposit.rs
1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{constants::ResourceType, objects::RoomObject, prelude::*};
5
6#[wasm_bindgen]
7extern "C" {
8 /// A [`Deposit`], which can be harvested for resources used in commodities.
9 ///
10 /// [Screeps documentation](https://docs.screeps.com/api/#Deposit)
11 #[wasm_bindgen(extends = RoomObject)]
12 #[derive(Clone, Debug)]
13 pub type Deposit;
14
15 /// Ticks until the deposit can be harvested again.
16 ///
17 /// [Screeps documentation](https://docs.screeps.com/api/#Deposit.cooldown)
18 #[wasm_bindgen(method, getter)]
19 pub fn cooldown(this: &Deposit) -> u32;
20
21 /// Type of resource contained in this deposit.
22 ///
23 /// [Screeps documentation](https://docs.screeps.com/api/#Deposit.depositType)
24 #[wasm_bindgen(method, getter = depositType)]
25 pub fn deposit_type(this: &Deposit) -> ResourceType;
26
27 /// Object ID of the deposit, which can be used to efficiently fetch a fresh
28 /// reference to the object on subsequent ticks.
29 ///
30 /// [Screeps documentation](https://docs.screeps.com/api/#Deposit.id)
31 #[wasm_bindgen(method, getter = id)]
32 fn id_internal(this: &Deposit) -> JsString;
33
34 /// The cooldown caused by the most recent harvest action for this deposit.
35 ///
36 /// [Screeps documentation](https://docs.screeps.com/api/#Deposit.lastCooldown)
37 #[wasm_bindgen(method, getter = lastCooldown)]
38 pub fn last_cooldown(this: &Deposit) -> u32;
39
40 /// The number of ticks until this deposit disappears, which is reset if it
41 /// is harvested.
42 ///
43 /// [Screeps documentation](https://docs.screeps.com/api/#Deposit.ticksToDecay)
44 #[wasm_bindgen(method, getter = ticksToDecay)]
45 pub fn ticks_to_decay(this: &Deposit) -> u32;
46}
47
48impl CanDecay for Deposit {
49 fn ticks_to_decay(&self) -> u32 {
50 self.ticks_to_decay()
51 }
52}
53
54impl HasCooldown for Deposit {
55 fn cooldown(&self) -> u32 {
56 self.cooldown()
57 }
58}
59
60impl HasId for Deposit {
61 fn js_raw_id(&self) -> JsString {
62 self.id_internal()
63 }
64}
65
66impl Harvestable for Deposit {}