1use crate::{prelude::*, CanFrom, LivingEntity, LivingEntityID};
4use js_sys::Reflect;
5use std::convert::TryFrom;
6use wasm_bindgen::prelude::*;
7
8pub mod base;
9pub mod outpost;
10pub mod star;
11
12#[wasm_bindgen(typescript_type = "StructureType")]
16pub enum StructureType {
17 Base = "base",
18 Outpost = "outpost",
19 Star = "star",
20}
21
22#[wasm_bindgen]
24extern "C" {
25 #[wasm_bindgen(extends = LivingEntityID, typescript_type = "StructureID")]
27 #[derive(Clone, Debug, PartialEq, Eq)]
28 pub type StructureID;
29
30 #[wasm_bindgen(extends = LivingEntity, typescript_type = "Structure")]
34 #[derive(Clone, Debug, PartialEq, Eq)]
35 pub type Structure;
36
37 #[wasm_bindgen(method, getter)]
38 pub fn id(this: &Structure) -> StructureID;
39
40 #[wasm_bindgen(method, getter)]
41 pub fn structure_type(this: &Structure) -> StructureType;
42
43 #[wasm_bindgen(method, getter)]
44 pub fn collision_radius(this: &Structure) -> f64;
45}
46
47impl CanFrom<Entity> for Structure {
48 #[inline]
49 fn can_from(value: &Entity) -> bool {
50 Reflect::has(value, &"structure_type".into()).unwrap()
51 }
52}
53
54try_can_from!(impl TryFrom<Entity>, Error = Entity for Structure);
55
56impl CanFrom<LivingEntity> for Structure {
57 #[inline]
58 fn can_from(value: &LivingEntity) -> bool {
59 <Structure as CanFrom<Entity>>::can_from(value)
60 }
61}
62
63try_can_from!(impl TryFrom<LivingEntity>, Error = Entity for Structure);