screeps/objects/impls/
construction_site.rs1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{
5 constants::StructureType,
6 enums::action_error_codes::construction_site::*,
7 objects::{Owner, RoomObject},
8 prelude::*,
9};
10
11#[wasm_bindgen]
12extern "C" {
13 #[wasm_bindgen(extends = RoomObject)]
18 #[derive(Clone, Debug)]
19 pub type ConstructionSite;
20
21 #[wasm_bindgen(method, getter = id)]
22 fn id_internal(this: &ConstructionSite) -> Option<JsString>;
23
24 #[wasm_bindgen(method, getter = my)]
25 fn my_internal(this: &ConstructionSite) -> bool;
26
27 #[wasm_bindgen(method, getter = owner)]
28 fn owner_internal(this: &ConstructionSite) -> Owner;
29
30 #[wasm_bindgen(method, getter = progress)]
31 fn progress_internal(this: &ConstructionSite) -> u32;
32
33 #[wasm_bindgen(method, getter = progressTotal)]
34 fn progress_total_internal(this: &ConstructionSite) -> u32;
35
36 #[wasm_bindgen(method, getter = structureType)]
37 fn structure_type_internal(this: &ConstructionSite) -> StructureType;
38
39 #[wasm_bindgen(method, js_name = remove)]
40 fn remove_internal(this: &ConstructionSite) -> i8;
41}
42
43impl ConstructionSite {
44 pub fn my(&self) -> bool {
48 self.my_internal()
49 }
50
51 pub fn owner(&self) -> Owner {
56 self.owner_internal()
57 }
58
59 pub fn progress(&self) -> u32 {
63 self.progress_internal()
64 }
65
66 pub fn progress_total(&self) -> u32 {
71 self.progress_total_internal()
72 }
73
74 pub fn structure_type(&self) -> StructureType {
78 self.structure_type_internal()
79 }
80
81 pub fn remove(&self) -> Result<(), ConstructionSiteRemoveErrorCode> {
85 ConstructionSiteRemoveErrorCode::result_from_i8(self.remove_internal())
86 }
87}
88
89impl MaybeHasId for ConstructionSite {
90 fn try_js_raw_id(&self) -> Option<JsString> {
95 self.id_internal()
96 }
97}
98
99impl JsCollectionFromValue for ConstructionSite {
100 fn from_value(val: JsValue) -> Self {
101 val.unchecked_into()
102 }
103}