Struct screeps::objects::RoomPosition
source · pub struct RoomPosition { /* private fields */ }
Expand description
An object representing a position in a room, stored in JavaScript memory.
Use Position
to store and access the same data in Rust memory.
Implementations§
source§impl RoomPosition
impl RoomPosition
sourcepub fn set_room_name(&self) -> JsString
pub fn set_room_name(&self) -> JsString
Change the room the position refers to; must be a valid room name.
source§impl RoomPosition
impl RoomPosition
source§impl RoomPosition
impl RoomPosition
source§impl RoomPosition
impl RoomPosition
source§impl RoomPosition
impl RoomPosition
sourcepub fn set_packed(&self, val: u32)
pub fn set_packed(&self, val: u32)
Sets the position to a new one by passing an i32 that represents a packed position.
source§impl RoomPosition
impl RoomPosition
sourcepub fn get_direction_to(&self, goal: &JsValue) -> Direction
pub fn get_direction_to(&self, goal: &JsValue) -> Direction
Get the Direction
toward a position or room object.
source§impl RoomPosition
impl RoomPosition
source§impl RoomPosition
impl RoomPosition
sourcepub fn get_range_to(&self, goal: &JsValue) -> u32
pub fn get_range_to(&self, goal: &JsValue) -> u32
Get the range to a position or room object in the same room.
source§impl RoomPosition
impl RoomPosition
sourcepub fn get_range_to_xy(&self, x: u8, y: u8) -> u32
pub fn get_range_to_xy(&self, x: u8, y: u8) -> u32
Get the range to the given coordinates in the same room.
source§impl RoomPosition
impl RoomPosition
sourcepub fn in_range_to(&self, goal: &JsValue, range: u8) -> bool
pub fn in_range_to(&self, goal: &JsValue, range: u8) -> bool
Get the range to a position or room object in the same room.
source§impl RoomPosition
impl RoomPosition
source§impl RoomPosition
impl RoomPosition
sourcepub fn is_equal_to(&self, goal: &JsValue) -> bool
pub fn is_equal_to(&self, goal: &JsValue) -> bool
Determine whether this position is at the same position as another position or room object.
source§impl RoomPosition
impl RoomPosition
sourcepub fn is_equal_to_xy(&self, x: u8, y: u8) -> bool
pub fn is_equal_to_xy(&self, x: u8, y: u8) -> bool
Determine whether this position is at the given coordinates in the room.
source§impl RoomPosition
impl RoomPosition
sourcepub fn is_near_to(&self, goal: &JsValue) -> bool
pub fn is_near_to(&self, goal: &JsValue) -> bool
Determine whether this position is within 1 range of another position or room object.
source§impl RoomPosition
impl RoomPosition
sourcepub fn is_near_to_xy(&self, x: u8, y: u8) -> bool
pub fn is_near_to_xy(&self, x: u8, y: u8) -> bool
Determine whether this position is within 1 range of the given coordinates in the room.
source§impl RoomPosition
impl RoomPosition
sourcepub fn new(x: u8, y: u8, room_name: RoomName) -> RoomPosition
pub fn new(x: u8, y: u8, room_name: RoomName) -> RoomPosition
Create a new RoomPosition using the normal constructor, taking coordinates and the room name.
sourcepub fn room_name(&self) -> RoomName
pub fn room_name(&self) -> RoomName
Name of the room the position is in, as an owned JsString
reference
to a string in Javascript memory.
sourcepub fn create_construction_site(
&self,
ty: StructureType,
name: Option<&JsString>,
) -> Result<(), ErrorCode>
pub fn create_construction_site( &self, ty: StructureType, name: Option<&JsString>, ) -> Result<(), ErrorCode>
Creates a ConstructionSite
at this position. If it’s a
StructureSpawn
, a name can optionally be assigned for the structure.
sourcepub fn create_flag(
&self,
name: Option<&JsString>,
color: Option<Color>,
secondary_color: Option<Color>,
) -> Result<JsString, ErrorCode>
pub fn create_flag( &self, name: Option<&JsString>, color: Option<Color>, secondary_color: Option<Color>, ) -> Result<JsString, ErrorCode>
Creates a Flag
at this position. If successful, returns the name of
the created flag.
sourcepub fn find_closest_by_path<T>(
&self,
find: T,
options: Option<&Object>,
) -> Option<T::Item>where
T: FindConstant,
pub fn find_closest_by_path<T>(
&self,
find: T,
options: Option<&Object>,
) -> Option<T::Item>where
T: FindConstant,
Find the closest object by path among a list of objects, or use
a find
constant to search for all objects of that type in the room.
sourcepub fn find_closest_by_range<T>(&self, find: T) -> Option<T::Item>where
T: FindConstant,
pub fn find_closest_by_range<T>(&self, find: T) -> Option<T::Item>where
T: FindConstant,
Find the closest object by range among a list of objects, or use
a find
constant to search for all objects of that type in the room.
Will not work for objects in other rooms.
sourcepub fn find_in_range<T>(&self, find: T, range: u8) -> Vec<T::Item>where
T: FindConstant,
pub fn find_in_range<T>(&self, find: T, range: u8) -> Vec<T::Item>where
T: FindConstant,
Find all relevant objects within a certain range among a list of
objects, or use a find
constant to search all objects of that type
in the room.
sourcepub fn find_path_to<T, F, R>(
&self,
target: &T,
options: Option<FindPathOptions<F, R>>,
) -> Path
pub fn find_path_to<T, F, R>( &self, target: &T, options: Option<FindPathOptions<F, R>>, ) -> Path
Find a path from this position to a position or room object, with an optional options object
sourcepub fn find_path_to_xy<F, R>(
&self,
x: RoomCoordinate,
y: RoomCoordinate,
options: Option<FindPathOptions<F, R>>,
) -> Path
pub fn find_path_to_xy<F, R>( &self, x: RoomCoordinate, y: RoomCoordinate, options: Option<FindPathOptions<F, R>>, ) -> Path
Find a path from this position to the given coordinates in the same room, with an optional options object.
sourcepub fn look(&self) -> Result<Vec<LookResult>, ErrorCode>
pub fn look(&self) -> Result<Vec<LookResult>, ErrorCode>
Get all objects at this position. Will fail if the position is in a room that’s not visible during the current tick.
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>
pub fn as_string(&self) -> Option<String>
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 AsRef<JsValue> for RoomPosition
impl AsRef<JsValue> for RoomPosition
source§impl AsRef<RoomPosition> for RoomPosition
impl AsRef<RoomPosition> for RoomPosition
source§fn as_ref(&self) -> &RoomPosition
fn as_ref(&self) -> &RoomPosition
source§impl Clone for RoomPosition
impl Clone for RoomPosition
source§impl Deref for RoomPosition
impl Deref for RoomPosition
source§impl From<&Position> for RoomPosition
impl From<&Position> for RoomPosition
source§impl From<&RoomPosition> for Position
impl From<&RoomPosition> for Position
source§fn from(js_pos: &RoomPosition) -> Self
fn from(js_pos: &RoomPosition) -> Self
source§impl From<JsValue> for RoomPosition
impl From<JsValue> for RoomPosition
source§fn from(obj: JsValue) -> RoomPosition
fn from(obj: JsValue) -> RoomPosition
source§impl From<Position> for RoomPosition
impl From<Position> for RoomPosition
source§impl From<RoomPosition> for JsValue
impl From<RoomPosition> for JsValue
source§fn from(obj: RoomPosition) -> JsValue
fn from(obj: RoomPosition) -> JsValue
source§impl From<RoomPosition> for ObjectWithPosition
impl From<RoomPosition> for ObjectWithPosition
source§fn from(v: RoomPosition) -> ObjectWithPosition
fn from(v: RoomPosition) -> ObjectWithPosition
source§impl From<RoomPosition> for Position
impl From<RoomPosition> for Position
source§fn from(js_pos: RoomPosition) -> Self
fn from(js_pos: RoomPosition) -> Self
source§impl FromWasmAbi for RoomPosition
impl FromWasmAbi for RoomPosition
source§impl HasPosition for RoomPosition
impl HasPosition for RoomPosition
source§impl<'a> IntoWasmAbi for &'a RoomPosition
impl<'a> IntoWasmAbi for &'a RoomPosition
source§impl IntoWasmAbi for RoomPosition
impl IntoWasmAbi for RoomPosition
source§impl JsCast for RoomPosition
impl JsCast for RoomPosition
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 LongRefFromWasmAbi for RoomPosition
impl LongRefFromWasmAbi for RoomPosition
§type Abi = <JsValue as LongRefFromWasmAbi>::Abi
type Abi = <JsValue as LongRefFromWasmAbi>::Abi
RefFromWasmAbi::Abi
§type Anchor = RoomPosition
type Anchor = RoomPosition
RefFromWasmAbi::Anchor
source§unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor
RefFromWasmAbi::ref_from_abi
source§impl OptionFromWasmAbi for RoomPosition
impl OptionFromWasmAbi for RoomPosition
source§impl<'a> OptionIntoWasmAbi for &'a RoomPosition
impl<'a> OptionIntoWasmAbi for &'a RoomPosition
source§impl OptionIntoWasmAbi for RoomPosition
impl OptionIntoWasmAbi for RoomPosition
source§impl RefFromWasmAbi for RoomPosition
impl RefFromWasmAbi for RoomPosition
§type Abi = <JsValue as RefFromWasmAbi>::Abi
type Abi = <JsValue as RefFromWasmAbi>::Abi
Self
are recovered from.§type Anchor = ManuallyDrop<RoomPosition>
type Anchor = ManuallyDrop<RoomPosition>
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.source§impl TryInto<RoomPosition> for ObjectWithPosition
impl TryInto<RoomPosition> for ObjectWithPosition
Auto Trait Implementations§
impl Freeze for RoomPosition
impl RefUnwindSafe for RoomPosition
impl !Send for RoomPosition
impl !Sync for RoomPosition
impl Unpin for RoomPosition
impl UnwindSafe for RoomPosition
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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
.