yareio_sys/structure/
base.rs1use crate::spirit::LivingSpirit;
4use crate::structure::{Structure, StructureID};
5use crate::{
6 prelude::*, CanFrom, Destructible, DestructibleID, LivingDestructible, LivingDestructibleID,
7};
8use js_sys::{Object, Reflect};
9use std::convert::TryFrom;
10use wasm_bindgen::prelude::*;
11
12#[wasm_bindgen]
14extern "C" {
15 #[wasm_bindgen(extends = StructureID, extends = LivingDestructibleID, typescript_type = "BaseID")]
17 #[derive(Clone, Debug, PartialEq, Eq)]
18 pub type BaseID;
19
20 #[wasm_bindgen(extends = Structure, extends = LivingDestructible, typescript_type = "Base")]
24 #[derive(Clone, Debug, PartialEq, Eq)]
25 pub type Base;
26
27 #[wasm_bindgen(method, getter)]
28 pub fn id(this: &Base) -> BaseID;
29
30 #[wasm_bindgen(method, getter)]
31 pub fn current_spirit_cost(this: &Base) -> i32;
32}
33
34impl CanFrom<Structure> for Base {
35 #[inline]
36 fn can_from(value: &Structure) -> bool {
37 value.structure_type().to_str() == "base"
38 }
39}
40
41try_can_from!(impl TryFrom<Structure>, Error = Structure for Base);
42
43impl CanFrom<Destructible> for Base {
44 #[inline]
45 fn can_from(value: &Destructible) -> bool {
46 Reflect::has(value, &"current_spirit_cost".into()).unwrap()
47 }
48}
49
50try_can_from!(impl TryFrom<Destructible>, Error = Spirit for Base);
51
52impl CanFrom<LivingDestructible> for Base {
53 #[inline]
54 fn can_from(value: &LivingDestructible) -> bool {
55 <Base as CanFrom<Destructible>>::can_from(value)
56 }
57}
58
59try_can_from!(impl TryFrom<LivingDestructible>, Error = LivingSpirit for Base);
60
61#[wasm_bindgen]
63extern "C" {
64 #[wasm_bindgen(extends = Object, typescript_type = "(typeof bases)")]
65 #[derive(Clone, Debug)]
66 pub type Bases;
67
68 #[wasm_bindgen(js_name = "bases")]
69 static _bases: Bases;
70}
71
72impl TryGetByID<EntityID, Base> for Bases {}
73impl TryGetByID<DestructibleID, Base> for Bases {}
74impl TryGetByID<LivingDestructibleID, Base> for Bases {}
75impl TryGetByID<StructureID, Base> for Bases {}
76impl GetByID<BaseID, Base> for Bases {}
77impl EnumerateByID<BaseID, Base> for Bases {}
78
79#[inline(always)]
83pub fn bases() -> &'static Bases {
84 &_bases
85}
86
87#[wasm_bindgen]
89extern "C" {
90 #[wasm_bindgen(js_name = "base")]
91 static _base: Base;
92}
93
94#[inline(always)]
98pub fn base() -> &'static Base {
99 &_base
100}
101
102#[wasm_bindgen]
104extern "C" {
105 #[wasm_bindgen(js_name = "enemy_base")]
106 static _enemy_base: Base;
107}
108
109#[inline(always)]
113pub fn enemy_base() -> &'static Base {
114 &_enemy_base
115}