screeps/objects/impls/
resource.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 [`Resource`] is an object representing resources that have been
9    /// dropped and can be picked up.
10    ///
11    /// [Screeps documentation](https://docs.screeps.com/api/#Resource)
12    #[wasm_bindgen(extends = RoomObject)]
13    #[derive(Clone, Debug)]
14    pub type Resource;
15
16    /// Amount of resource this contains.
17    ///
18    /// [Screeps documentation](https://docs.screeps.com/api/#Resource.amount)
19    #[wasm_bindgen(method, getter)]
20    pub fn amount(this: &Resource) -> u32;
21
22    /// Object ID of the resource, which can be used to efficiently fetch a
23    /// fresh reference to the object on subsequent ticks.
24    ///
25    /// [Screeps documentation](https://docs.screeps.com/api/#Resource.id)
26    #[wasm_bindgen(method, getter = id)]
27    fn id_internal(this: &Resource) -> JsString;
28
29    /// The type of resource this contains.
30    ///
31    /// [Screeps documentation](https://docs.screeps.com/api/#Resource.resourceType)
32    #[wasm_bindgen(method, getter = resourceType)]
33    pub fn resource_type(this: &Resource) -> ResourceType;
34}
35
36impl HasId for Resource {
37    fn js_raw_id(&self) -> JsString {
38        Self::id_internal(self)
39    }
40}