screeps/objects/impls/
mineral.rs

1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{
5    constants::{Density, ResourceType},
6    objects::RoomObject,
7    prelude::*,
8};
9
10#[wasm_bindgen]
11extern "C" {
12    /// A [`Mineral`], which can be harvested for resources with an extractor.
13    ///
14    /// [Screeps documentation](https://docs.screeps.com/api/#Mineral)
15    #[wasm_bindgen(extends = RoomObject)]
16    #[derive(Clone, Debug)]
17    pub type Mineral;
18
19    /// The density of the mineral on the next refill after it's depleted.
20    ///
21    /// [Screeps documentation](https://docs.screeps.com/api/#Mineral.density)
22    #[wasm_bindgen(method, getter)]
23    pub fn density(this: &Mineral) -> Density;
24
25    /// Type of resource contained in this mineral.
26    ///
27    /// [Screeps documentation](https://docs.screeps.com/api/#Mineral.mineralType)
28    #[wasm_bindgen(method, getter = mineralAmount)]
29    pub fn mineral_amount(this: &Mineral) -> u32;
30
31    /// Type of resource contained in this mineral.
32    ///
33    /// [Screeps documentation](https://docs.screeps.com/api/#Mineral.mineralType)
34    #[wasm_bindgen(method, getter = mineralType)]
35    pub fn mineral_type(this: &Mineral) -> ResourceType;
36
37    /// Object ID of the mineral, which can be used to efficiently fetch a fresh
38    /// reference to the object on subsequent ticks.
39    ///
40    /// [Screeps documentation](https://docs.screeps.com/api/#Mineral.id)
41    #[wasm_bindgen(method, getter = id)]
42    fn id_internal(this: &Mineral) -> JsString;
43
44    /// The number of ticks until this mineral regenerates from depletion, or
45    /// `None` if it's not currently regenerating.
46    ///
47    /// [Screeps documentation](https://docs.screeps.com/api/#Mineral.ticksToRegeneration)
48    #[wasm_bindgen(method, getter = ticksToRegeneration)]
49    pub fn ticks_to_regeneration(this: &Mineral) -> Option<u32>;
50}
51
52impl HasId for Mineral {
53    fn js_raw_id(&self) -> JsString {
54        Self::id_internal(self)
55    }
56}
57
58impl Harvestable for Mineral {}