use js_sys::JsString;
use wasm_bindgen::prelude::*;
use crate::{
constants::{ErrorCode, ResourceType},
local::RoomName,
objects::{OwnedStructure, RoomObject, Store, Structure},
prelude::*,
};
#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends = RoomObject, extends = Structure, extends = OwnedStructure)]
#[derive(Clone, Debug)]
pub type StructureTerminal;
#[wasm_bindgen(method, getter)]
pub fn cooldown(this: &StructureTerminal) -> u32;
#[wasm_bindgen(method, getter)]
pub fn store(this: &StructureTerminal) -> Store;
#[wasm_bindgen(method, js_name = send)]
fn send_internal(
this: &StructureTerminal,
resource_type: ResourceType,
amount: u32,
destination: &JsString,
description: Option<&JsString>,
) -> i8;
}
impl StructureTerminal {
pub fn send(
&self,
resource_type: ResourceType,
amount: u32,
destination: RoomName,
description: Option<&str>,
) -> Result<(), ErrorCode> {
let desination = destination.into();
let description = description.map(JsString::from);
ErrorCode::result_from_i8(self.send_internal(
resource_type,
amount,
&desination,
description.as_ref(),
))
}
}
impl HasCooldown for StructureTerminal {
fn cooldown(&self) -> u32 {
Self::cooldown(self)
}
}
impl HasStore for StructureTerminal {
fn store(&self) -> Store {
Self::store(self)
}
}
impl Attackable for StructureTerminal {}
impl Dismantleable for StructureTerminal {}
impl Repairable for StructureTerminal {}
impl Transferable for StructureTerminal {}
impl Withdrawable for StructureTerminal {}