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
85
86
87
88
89
90
91
92
93
94
95
use js_sys::JsString;
use wasm_bindgen::prelude::*;
use crate::{
constants::Color,
enums::action_error_codes::flag::*,
objects::{RoomObject, RoomPosition},
prelude::*,
};
#[wasm_bindgen]
extern "C" {
/// A [`Flag`], which can be placed by the player or created automatically
/// and are only visible to their owners. You can't create more than
/// [`FLAGS_LIMIT`].
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag)
///
/// [`FLAGS_LIMIT`]: crate::constants::FLAGS_LIMIT
#[wasm_bindgen(extends = RoomObject)]
#[derive(Clone, Debug)]
pub type Flag;
/// Primary color of the flag.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag.color)
#[wasm_bindgen(method, getter)]
pub fn color(this: &Flag) -> Color;
/// A shortcut to `Memory.flags[flag.name]`.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag.memory)
#[wasm_bindgen(method, getter)]
pub fn memory(this: &Flag) -> JsValue;
/// Sets a new value to `Memory.flags[flag.name]`.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag.memory)
#[wasm_bindgen(method, setter)]
pub fn set_memory(this: &Flag, val: &JsValue);
/// The flag's name as a [`String`].
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag.name)
#[wasm_bindgen(method, getter)]
pub fn name(this: &Flag) -> String;
/// The flag's name as a [`JsString`].
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag.name)
#[wasm_bindgen(method, getter = name)]
pub fn name_jsstring(this: &Flag) -> JsString;
#[wasm_bindgen(method, js_name = remove)]
fn remove_internal(this: &Flag) -> i8;
#[wasm_bindgen(method, js_name = setColor)]
fn set_color_internal(this: &Flag, color: Color, secondary_color: Option<Color>) -> i8;
#[wasm_bindgen(method, js_name = setPosition)]
fn set_position_internal(this: &Flag, pos: RoomPosition) -> i8;
}
impl Flag {
/// Remove the flag.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag.remove)
pub fn remove(&self) -> Result<(), FlagRemoveErrorCode> {
FlagRemoveErrorCode::result_from_i8(self.remove_internal())
}
/// Set the color (and optionally, the secondary color) of the flag.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag.setColor)
pub fn set_color(
&self,
color: Color,
secondary_color: Option<Color>,
) -> Result<(), SetColorErrorCode> {
SetColorErrorCode::result_from_i8(self.set_color_internal(color, secondary_color))
}
/// Set the position of the flag
///
/// [Screeps documentation](https://docs.screeps.com/api/#Flag.setPosition)
pub fn set_position(&self, pos: RoomPosition) -> Result<(), SetPositionErrorCode> {
SetPositionErrorCode::result_from_i8(self.set_position_internal(pos))
}
}
impl JsCollectionFromValue for Flag {
fn from_value(val: JsValue) -> Self {
val.unchecked_into()
}
}