screeps/objects/impls/
structure_terminal.rs1use js_sys::JsString;
2use wasm_bindgen::prelude::*;
3
4use crate::{
5    constants::ResourceType,
6    enums::action_error_codes::structure_terminal::*,
7    local::RoomName,
8    objects::{OwnedStructure, RoomObject, Store, Structure},
9    prelude::*,
10};
11
12#[wasm_bindgen]
13extern "C" {
14    #[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
19    #[derive(Clone, Debug)]
20    pub type StructureTerminal;
21
22    #[wasm_bindgen(method, getter)]
27    pub fn cooldown(this: &StructureTerminal) -> u32;
28
29    #[wasm_bindgen(method, getter)]
34    pub fn store(this: &StructureTerminal) -> Store;
35
36    #[wasm_bindgen(method, js_name = send)]
37    fn send_internal(
38        this: &StructureTerminal,
39        resource_type: ResourceType,
40        amount: u32,
41        destination: &JsString,
42        description: Option<&JsString>,
43    ) -> i8;
44}
45
46impl StructureTerminal {
47    pub fn send(
51        &self,
52        resource_type: ResourceType,
53        amount: u32,
54        destination: RoomName,
55        description: Option<&str>,
56    ) -> Result<(), SendErrorCode> {
57        let desination = destination.into();
58        let description = description.map(JsString::from);
59
60        SendErrorCode::result_from_i8(self.send_internal(
61            resource_type,
62            amount,
63            &desination,
64            description.as_ref(),
65        ))
66    }
67}
68
69impl HasCooldown for StructureTerminal {
70    fn cooldown(&self) -> u32 {
71        Self::cooldown(self)
72    }
73}
74
75impl HasStore for StructureTerminal {
76    fn store(&self) -> Store {
77        Self::store(self)
78    }
79}
80
81impl Attackable for StructureTerminal {}
82impl Dismantleable for StructureTerminal {}
83impl Repairable for StructureTerminal {}
84impl Transferable for StructureTerminal {}
85impl Withdrawable for StructureTerminal {}