1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
use js_sys::JsString;
use wasm_bindgen::{prelude::*, JsCast};
use crate::{
constants::{ReturnCode, StructureType},
objects::{Owner, RoomObject},
prelude::*,
};
#[wasm_bindgen]
extern "C" {
/// A [`ConstructionSite`] which is an object representing a structure under
/// construction.
///
/// [Screeps documentation](https://docs.screeps.com/api/#ConstructionSite)
#[wasm_bindgen(extends = RoomObject)]
#[derive(Clone, Debug)]
pub type ConstructionSite;
/// The Object ID of the [`ConstructionSite`], or `None` if it was created
/// this tick.
///
/// [Screeps documentation](https://docs.screeps.com/api/#ConstructionSite.id)
#[wasm_bindgen(method, getter = id)]
fn id_internal(this: &ConstructionSite) -> Option<JsString>;
/// Whether you own the [`ConstructionSite`].
///
/// [Screeps documentation](https://docs.screeps.com/api/#ConstructionSite.my)
#[wasm_bindgen(method, getter)]
pub fn my(this: &ConstructionSite) -> bool;
/// The [`Owner`] of this construction site, which contains the owner's
/// username.
///
/// [Screeps documentation](https://docs.screeps.com/api/#ConstructionSite.owner)
#[wasm_bindgen(method, getter)]
pub fn owner(this: &ConstructionSite) -> Owner;
/// The current progress toward completion of the structure being built.
///
/// [Screeps documentation](https://docs.screeps.com/api/#ConstructionSite.progress)
#[wasm_bindgen(method, getter)]
pub fn progress(this: &ConstructionSite) -> u32;
/// The total progess toward constuction progress needed for the structure
/// to be completed.
///
/// [Screeps documentation](https://docs.screeps.com/api/#ConstructionSite.progressTotal)
#[wasm_bindgen(method, getter = progressTotal)]
pub fn progress_total(this: &ConstructionSite) -> u32;
/// The type of structure being constructed.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Structure.structureType)
#[wasm_bindgen(method, getter = structureType)]
pub fn structure_type(this: &ConstructionSite) -> StructureType;
/// Remove the [`ConstructionSite`].
///
/// [Screeps documentation](https://docs.screeps.com/api/#ConstructionSite.remove)
#[wasm_bindgen(method)]
pub fn remove(this: &ConstructionSite) -> ReturnCode;
}
impl MaybeHasNativeId for ConstructionSite {
fn try_native_id(&self) -> Option<JsString> {
Self::id_internal(self)
}
}
impl JsCollectionFromValue for ConstructionSite {
fn from_value(val: JsValue) -> Self {
val.unchecked_into()
}
}