screeps/objects/impls/
structure_factory.rs

1use wasm_bindgen::prelude::*;
2
3use crate::{
4    constants::ResourceType,
5    enums::action_error_codes::structure_factory::*,
6    objects::{OwnedStructure, RoomObject, Store, Structure},
7    prelude::*,
8};
9
10#[wasm_bindgen]
11extern "C" {
12    /// An object representing a [`StructureFactory`], which can compress and
13    /// decompress resources and produce commodities for sale.
14    ///
15    /// [Screeps documentation](https://docs.screeps.com/api/#StructureFactory)
16    #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
17    #[derive(Clone, Debug)]
18    pub type StructureFactory;
19
20    /// Ticks until [`StructureFactory::produce`] can be used again.
21    ///
22    /// [Screeps documentation](https://docs.screeps.com/api/#StructureFactory.cooldown)
23    ///
24    /// [`StructureFactory::produce`]: crate::objects::StructureFactory::produce
25    #[wasm_bindgen(method, getter)]
26    pub fn cooldown(this: &StructureFactory) -> u32;
27
28    /// The level of the factory, which cannot be changed once set by a power
29    /// creep.
30    ///
31    /// [Screeps documentation](https://docs.screeps.com/api/#StructureFactory.level)
32    #[wasm_bindgen(method, getter)]
33    pub fn level(this: &StructureFactory) -> u8;
34
35    /// The [`Store`] of the factory, which contains information about what
36    /// resources it is it holding.
37    ///
38    /// [Screeps documentation](https://docs.screeps.com/api/#StructureFactory.store)
39    #[wasm_bindgen(method, getter)]
40    pub fn store(this: &StructureFactory) -> Store;
41
42    #[wasm_bindgen(method, js_name = produce)]
43    fn produce_internal(this: &StructureFactory, ty: ResourceType) -> i8;
44}
45
46impl StructureFactory {
47    /// Produce a commodity in the factory.
48    ///
49    /// [Screeps documentation](https://docs.screeps.com/api/#StructureFactory.produce)
50    pub fn produce(&self, ty: ResourceType) -> Result<(), ProduceErrorCode> {
51        ProduceErrorCode::result_from_i8(self.produce_internal(ty))
52    }
53}
54
55impl HasCooldown for StructureFactory {
56    fn cooldown(&self) -> u32 {
57        Self::cooldown(self)
58    }
59}
60
61impl HasStore for StructureFactory {
62    fn store(&self) -> Store {
63        Self::store(self)
64    }
65}
66
67impl Attackable for StructureFactory {}
68impl Dismantleable for StructureFactory {}
69impl Repairable for StructureFactory {}
70impl Transferable for StructureFactory {}
71impl Withdrawable for StructureFactory {}