pub struct Room { /* private fields */ }
Expand description
A reference to a Room
object, a 50x50 chunk of the Screeps game
world.
Implementations§
source§impl Room
impl Room
sourcepub fn controller(&self) -> Option<StructureController>
pub fn controller(&self) -> Option<StructureController>
The StructureController
for the room, or None
in rooms that cannot
be claimed.
source§impl Room
impl Room
sourcepub fn energy_available(&self) -> u32
pub fn energy_available(&self) -> u32
Energy available for spawning at the start of the current tick.
source§impl Room
impl Room
sourcepub fn energy_capacity_available(&self) -> u32
pub fn energy_capacity_available(&self) -> u32
Total energy capacity of all spawns and extensions in the room.
source§impl Room
impl Room
sourcepub fn set_memory(&self, val: &JsValue)
pub fn set_memory(&self, val: &JsValue)
Sets a new value to Memory.rooms[room.name]
.
source§impl Room
impl Room
sourcepub fn storage(&self) -> Option<StructureStorage>
pub fn storage(&self) -> Option<StructureStorage>
The StructureStorage
built in the room, or None
in rooms where
there isn’t one.
source§impl Room
impl Room
sourcepub fn terminal(&self) -> Option<StructureTerminal>
pub fn terminal(&self) -> Option<StructureTerminal>
The StructureTerminal
built in the room, or None
in rooms where
there isn’t one.
source§impl Room
impl Room
sourcepub fn get_position_at(&self, x: u8, y: u8) -> RoomPosition
pub fn get_position_at(&self, x: u8, y: u8) -> RoomPosition
Gets the RoomPosition
for the given coordinates.
source§impl Room
impl Room
sourcepub fn get_terrain(&self) -> RoomTerrain
pub fn get_terrain(&self) -> RoomTerrain
Gets the RoomTerrain
object for this room.
source§impl Room
impl Room
sourcepub fn serialize_path(path: &[Step]) -> String
pub fn serialize_path(path: &[Step]) -> String
Serialize a path array from Room::find_path
into a string
representation safe to store in memory.
sourcepub fn deserialize_path(path: &str) -> Vec<Step>
pub fn deserialize_path(path: &str) -> Vec<Step>
Deserialize a string representation from Room::serialize_path
back
to a path array.
pub fn visual(&self) -> RoomVisual
sourcepub fn create_construction_site(
&self,
x: u8,
y: u8,
ty: StructureType,
name: Option<&JsString>
) -> Result<(), ErrorCode>
pub fn create_construction_site( &self, x: u8, y: u8, ty: StructureType, name: Option<&JsString> ) -> Result<(), ErrorCode>
Creates a construction site at given coordinates within this room. If
it’s a StructureSpawn
, a name can optionally be assigned for the
structure.
See RoomPosition::create_construction_site
to create at a specified
position.
sourcepub fn create_flag(
&self,
x: u8,
y: u8,
name: Option<&JsString>,
color: Option<Color>,
secondary_color: Option<Color>
) -> Result<JsString, ErrorCode>
pub fn create_flag( &self, x: u8, y: u8, name: Option<&JsString>, color: Option<Color>, secondary_color: Option<Color> ) -> Result<JsString, ErrorCode>
Creates a Flag
at given coordinates within this room. The name of
the flag is returned if the creation is successful.
sourcepub fn find<T>(&self, ty: T, options: Option<&FindOptions>) -> Vec<T::Item>where
T: FindConstant,
pub fn find<T>(&self, ty: T, options: Option<&FindOptions>) -> Vec<T::Item>where
T: FindConstant,
Find all objects of the specified type in the room, without passing additional options.
Returns an Vec
containing the found objects, which should be
converted into the type of object you searched for.
sourcepub fn find_exit_to(&self, room: RoomName) -> ExitDirection
pub fn find_exit_to(&self, room: RoomName) -> ExitDirection
Find an exit from the current room which leads to a target room.
sourcepub fn find_path<F, R>(
&self,
origin: &RoomPosition,
goal: &RoomPosition,
options: Option<FindPathOptions<F, R>>
) -> Path
pub fn find_path<F, R>( &self, origin: &RoomPosition, goal: &RoomPosition, options: Option<FindPathOptions<F, R>> ) -> Path
Find a path within the room from one position to another.
pub fn get_event_log(&self) -> Vec<Event>
pub fn get_event_log_raw(&self) -> String
sourcepub fn look_at(&self, target: &RoomPosition) -> Vec<LookResult>
pub fn look_at(&self, target: &RoomPosition) -> Vec<LookResult>
Get all objects at a position.
sourcepub fn look_at_xy(&self, x: u8, y: u8) -> Vec<LookResult>
pub fn look_at_xy(&self, x: u8, y: u8) -> Vec<LookResult>
Get all objects at the given room coordinates.
sourcepub fn look_at_area(
&self,
top_y: u8,
left_x: u8,
bottom_y: u8,
right_x: u8
) -> Vec<PositionedLookResult>
pub fn look_at_area( &self, top_y: u8, left_x: u8, bottom_y: u8, right_x: u8 ) -> Vec<PositionedLookResult>
Get all objects in a certain area.
sourcepub fn look_for_at<T, U>(&self, _ty: T, target: &U) -> Vec<T::Item>where
T: LookConstant,
U: HasPosition,
pub fn look_for_at<T, U>(&self, _ty: T, target: &U) -> Vec<T::Item>where
T: LookConstant,
U: HasPosition,
Get all objects of a given type at this position, if any.
sourcepub fn look_for_at_xy<T>(&self, _ty: T, x: u8, y: u8) -> Vec<T::Item>where
T: LookConstant,
pub fn look_for_at_xy<T>(&self, _ty: T, x: u8, y: u8) -> Vec<T::Item>where
T: LookConstant,
Get all objects of a given type at the given coordinates, if any.
sourcepub fn look_for_at_area<T>(
&self,
_ty: T,
top_y: u8,
left_x: u8,
bottom_y: u8,
right_x: u8
) -> Vec<PositionedLookResult>where
T: LookConstant,
pub fn look_for_at_area<T>(
&self,
_ty: T,
top_y: u8,
left_x: u8,
bottom_y: u8,
right_x: u8
) -> Vec<PositionedLookResult>where
T: LookConstant,
Get all objects of a certain type in a certain area.
Methods from Deref<Target = JsValue>§
pub const NULL: JsValue = _
pub const UNDEFINED: JsValue = _
pub const TRUE: JsValue = _
pub const FALSE: JsValue = _
sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the f64
value of this JS value if it’s an instance of a
number.
If this JS value is not an instance of a number then this returns
None
.
sourcepub fn as_string(&self) -> Option<String>
Available on crate feature std
only.
pub fn as_string(&self) -> Option<String>
std
only.If this JS value is a string value, this function copies the JS string
value into wasm linear memory, encoded as UTF-8, and returns it as a
Rust String
.
To avoid the copying and re-encoding, consider the
JsString::try_from()
function from js-sys
instead.
If this JS value is not an instance of a string or if it’s not valid
utf-8 then this returns None
.
UTF-16 vs UTF-8
JavaScript strings in general are encoded as UTF-16, but Rust strings
are encoded as UTF-8. This can cause the Rust string to look a bit
different than the JS string sometimes. For more details see the
documentation about the str
type which contains a few
caveats about the encodings.
sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the bool
value of this JS value if it’s an instance of a
boolean.
If this JS value is not an instance of a boolean then this returns
None
.
sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Tests whether this JS value is undefined
sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Tests whether the type of this JS value is function
.
sourcepub fn js_in(&self, obj: &JsValue) -> bool
pub fn js_in(&self, obj: &JsValue) -> bool
Applies the binary in
JS operator on the two JsValue
s.
sourcepub fn loose_eq(&self, other: &JsValue) -> bool
pub fn loose_eq(&self, other: &JsValue) -> bool
Compare two JsValue
s for equality, using the ==
operator in JS.
sourcepub fn unsigned_shr(&self, rhs: &JsValue) -> u32
pub fn unsigned_shr(&self, rhs: &JsValue) -> u32
Applies the binary >>>
JS operator on the two JsValue
s.
sourcepub fn checked_div(&self, rhs: &JsValue) -> JsValue
pub fn checked_div(&self, rhs: &JsValue) -> JsValue
Applies the binary /
JS operator on two JsValue
s, catching and returning any RangeError
thrown.
sourcepub fn pow(&self, rhs: &JsValue) -> JsValue
pub fn pow(&self, rhs: &JsValue) -> JsValue
Applies the binary **
JS operator on the two JsValue
s.
sourcepub fn lt(&self, other: &JsValue) -> bool
pub fn lt(&self, other: &JsValue) -> bool
Applies the binary <
JS operator on the two JsValue
s.
sourcepub fn le(&self, other: &JsValue) -> bool
pub fn le(&self, other: &JsValue) -> bool
Applies the binary <=
JS operator on the two JsValue
s.
sourcepub fn ge(&self, other: &JsValue) -> bool
pub fn ge(&self, other: &JsValue) -> bool
Applies the binary >=
JS operator on the two JsValue
s.
sourcepub fn gt(&self, other: &JsValue) -> bool
pub fn gt(&self, other: &JsValue) -> bool
Applies the binary >
JS operator on the two JsValue
s.
sourcepub fn unchecked_into_f64(&self) -> f64
pub fn unchecked_into_f64(&self) -> f64
Applies the unary +
JS operator on a JsValue
. Can throw.
Trait Implementations§
source§impl FromWasmAbi for Room
impl FromWasmAbi for Room
source§impl<'a> IntoWasmAbi for &'a Room
impl<'a> IntoWasmAbi for &'a Room
source§impl IntoWasmAbi for Room
impl IntoWasmAbi for Room
source§impl JsCast for Room
impl JsCast for Room
source§fn instanceof(val: &JsValue) -> bool
fn instanceof(val: &JsValue) -> bool
instanceof
check to see whether the JsValue
provided is an instance of this type. Read moresource§fn unchecked_from_js(val: JsValue) -> Self
fn unchecked_from_js(val: JsValue) -> Self
source§fn unchecked_from_js_ref(val: &JsValue) -> &Self
fn unchecked_from_js_ref(val: &JsValue) -> &Self
source§fn has_type<T>(&self) -> boolwhere
T: JsCast,
fn has_type<T>(&self) -> boolwhere
T: JsCast,
T
. Read moresource§fn dyn_into<T>(self) -> Result<T, Self>where
T: JsCast,
fn dyn_into<T>(self) -> Result<T, Self>where
T: JsCast,
T
. Read moresource§fn dyn_ref<T>(&self) -> Option<&T>where
T: JsCast,
fn dyn_ref<T>(&self) -> Option<&T>where
T: JsCast,
T
. Read moresource§fn unchecked_into<T>(self) -> Twhere
T: JsCast,
fn unchecked_into<T>(self) -> Twhere
T: JsCast,
source§fn unchecked_ref<T>(&self) -> &Twhere
T: JsCast,
fn unchecked_ref<T>(&self) -> &Twhere
T: JsCast,
source§impl JsCollectionFromValue for Room
impl JsCollectionFromValue for Room
fn from_value(val: JsValue) -> Self
source§impl LongRefFromWasmAbi for Room
impl LongRefFromWasmAbi for Room
source§impl OptionFromWasmAbi for Room
impl OptionFromWasmAbi for Room
source§impl<'a> OptionIntoWasmAbi for &'a Room
impl<'a> OptionIntoWasmAbi for &'a Room
source§impl OptionIntoWasmAbi for Room
impl OptionIntoWasmAbi for Room
source§impl PartialEq for Room
impl PartialEq for Room
source§impl RefFromWasmAbi for Room
impl RefFromWasmAbi for Room
§type Abi = <JsValue as RefFromWasmAbi>::Abi
type Abi = <JsValue as RefFromWasmAbi>::Abi
Self
are recovered from.§type Anchor = ManuallyDrop<Room>
type Anchor = ManuallyDrop<Room>
Self
for the duration of the
invocation of the function that has an &Self
parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.impl Eq for Room
Auto Trait Implementations§
impl RefUnwindSafe for Room
impl !Send for Room
impl !Sync for Room
impl Unpin for Room
impl UnwindSafe for Room
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::Abi
source§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.