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
77
78
79
80
81
82
83
84
//! Provides access to outposts.

use crate::players::PlayerID;
use crate::{prelude::*, CanFrom};
use crate::{Structure, StructureID};
use js_sys::Object;
use std::convert::TryFrom;
use wasm_bindgen::prelude::*;

// Outpost
#[wasm_bindgen]
extern "C" {
    /// The ID of an [`Outpost`].
    #[wasm_bindgen(extends = StructureID, typescript_type = "OutpostID")]
    #[derive(Clone, Debug, PartialEq, Eq)]
    pub type OutpostID;

    /// An outpost.
    ///
    /// [Yare.io Documentation](https://yare.io/documentation#doc_outpost)
    #[wasm_bindgen(extends = Structure, typescript_type = "Outpost")]
    #[derive(Clone, Debug, PartialEq, Eq)]
    pub type Outpost;

    #[wasm_bindgen(method, getter)]
    pub fn id(this: &Outpost) -> OutpostID;

    #[wasm_bindgen(method, getter)]
    pub fn range(this: &Outpost) -> f64;

    #[wasm_bindgen(method, getter)]
    pub fn sight(this: &Outpost) -> OutpostSight;

    #[wasm_bindgen(method, getter)]
    pub fn control(this: &Outpost) -> PlayerID;
}

impl CanFrom<Structure> for Outpost {
    #[inline]
    fn can_from(value: &Structure) -> bool {
        value.structure_type().to_str() == "outpost"
    }
}

try_can_from!(impl TryFrom<Structure>, Error = Structure for Outpost);

// `outposts`
#[wasm_bindgen]
extern "C" {
    #[wasm_bindgen(extends = Object, typescript_type = "(typeof outposts)")]
    #[derive(Clone, Debug)]
    pub type Outposts;

    /// `outposts`. Use the [`GetByID`] trait to retrieve individual outposts.
    ///
    /// [Yare.io Documentation](https://yare.io/documentation#doc_outpost)
    #[wasm_bindgen]
    pub static outposts: Outposts;
}

impl TryGetByID<EntityID, Outpost> for Outposts {}
impl TryGetByID<StructureID, Outpost> for Outposts {}
impl GetByID<OutpostID, Outpost> for Outposts {}
impl EnumerateByID<OutpostID, Outpost> for Outposts {}

// `outpost_mdo`
#[wasm_bindgen(js_name = "outpost_mdo")]
extern "C" {
    /// `outpost_mdo`
    ///
    /// [Yare.io Documentation](https://yare.io/documentation#doc_outpost)
    #[wasm_bindgen]
    pub static outpost_mdo: Outpost;
}

// `outpost`
#[wasm_bindgen]
extern "C" {
    /// `outpost` (the outpost).
    ///
    /// [Yare.io Documentation](https://yare.io/documentation#doc_intro)
    #[wasm_bindgen]
    pub static outpost: Outpost;
}