screeps/objects/impls/
structure_factory.rs1use 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 #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
17 #[derive(Clone, Debug)]
18 pub type StructureFactory;
19
20 #[wasm_bindgen(method, getter)]
26 pub fn cooldown(this: &StructureFactory) -> u32;
27
28 #[wasm_bindgen(method, getter)]
33 pub fn level(this: &StructureFactory) -> u8;
34
35 #[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 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 {}