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