Skip to content

Commit

Permalink
Merge branch 'main' into raw_buffer_dev_panics
Browse files Browse the repository at this point in the history
  • Loading branch information
shanemadden committed Nov 28, 2023
2 parents 480f91e + c96cff2 commit ffb89d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Unreleased
==========

### Breaking:

- Change `TOWER_OPTIMAL_RANGE` and `TOWER_FALLOFF_RANGE` types to `u8` and `TOWER_FALLOFF` type
to `f64`
- Changed `RoomTerrain::new` and `game::map::get_room_terrain` return type to
`Option<RoomTerrain>`, returning `None` when the specified room is outside the server's
map
- Changed `game::map::get_room_status` return type to `Option<RoomStatusResult>`, returning
`None` instead of the previous behavior of returning an artificial 'normal' status for rooms
outside the server's map

### Bugfixes:

- Implement `JsCollectionIntoValue` for `Direction`, making the `JsHashMap` returned by
Expand Down
6 changes: 3 additions & 3 deletions src/constants/numbers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ pub const TOWER_POWER_HEAL: u32 = 400;
pub const TOWER_POWER_REPAIR: u32 = 800;
/// Tower actions at a range beyond this distance suffer falloff penalties - see
/// [`TOWER_FALLOFF`].
pub const TOWER_OPTIMAL_RANGE: u32 = 5;
pub const TOWER_OPTIMAL_RANGE: u8 = 5;
/// Tower actions at a range greater than or equal to this distance suffer the
/// maxium falloff penalties - see [`TOWER_FALLOFF`].
pub const TOWER_FALLOFF_RANGE: u32 = 20;
pub const TOWER_FALLOFF_RANGE: u8 = 20;
/// Maximum percentage reduction in healing, repair, and attack effectiveness
/// for towers due to range.
///
Expand All @@ -415,7 +415,7 @@ pub const TOWER_FALLOFF_RANGE: u32 = 20;
/// ```
///
/// [source]: https://github.com/screeps/engine/blob/f02d16a44a00c35615ae227fc72a3c9a07a6a39a/src/processor/intents/towers/attack.js#L38
pub const TOWER_FALLOFF: f32 = 0.75;
pub const TOWER_FALLOFF: f64 = 0.75;

/// Initial hits for observer structures; consider using the
/// [`StructureType::initial_hits`] function.
Expand Down
25 changes: 7 additions & 18 deletions src/game/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ extern "C" {
#[wasm_bindgen(js_namespace = ["Game"], js_class = "map", static_method_of = Map, js_name = getRoomLinearDistance)]
fn get_room_linear_distance(room_1: &JsString, room_2: &JsString, continuous: bool) -> u32;

#[wasm_bindgen(js_namespace = ["Game"], js_class = "map", static_method_of = Map, js_name = getRoomTerrain)]
fn get_room_terrain(room_name: &JsString) -> RoomTerrain;
#[wasm_bindgen(js_namespace = ["Game"], js_class = "map", static_method_of = Map, js_name = getRoomTerrain, catch)]
fn get_room_terrain(room_name: &JsString) -> Result<RoomTerrain, JsValue>;

#[wasm_bindgen(js_namespace = ["Game"], js_class = "map", static_method_of = Map, js_name = getWorldSize)]
fn get_world_size() -> u32;
Expand Down Expand Up @@ -70,10 +70,10 @@ pub fn get_room_linear_distance(from_room: RoomName, to_room: RoomName, continuo
/// vision in.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Game.map.getRoomTerrain)
pub fn get_room_terrain(room_name: RoomName) -> RoomTerrain {
pub fn get_room_terrain(room_name: RoomName) -> Option<RoomTerrain> {
let name = room_name.into();

Map::get_room_terrain(&name)
Map::get_room_terrain(&name).ok()
}

/// Get the size of the world map.
Expand All @@ -95,6 +95,7 @@ extern "C" {
pub fn timestamp(this: &JsRoomStatusResult) -> Option<f64>;
}

#[derive(Clone, Debug)]
pub struct RoomStatusResult {
status: RoomStatus,
timestamp: Option<f64>,
Expand All @@ -110,15 +111,6 @@ impl RoomStatusResult {
}
}

impl Default for RoomStatusResult {
fn default() -> Self {
RoomStatusResult {
status: RoomStatus::Normal,
timestamp: None,
}
}
}

impl From<JsRoomStatusResult> for RoomStatusResult {
fn from(val: JsRoomStatusResult) -> Self {
RoomStatusResult {
Expand All @@ -141,13 +133,10 @@ pub enum RoomStatus {
/// area or currently inaccessible.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Game.map.getRoomStatus)
pub fn get_room_status(room_name: RoomName) -> RoomStatusResult {
pub fn get_room_status(room_name: RoomName) -> Option<RoomStatusResult> {
let name = room_name.into();

Map::get_room_status(&name)
.ok()
.map(RoomStatusResult::from)
.unwrap_or_default()
Map::get_room_status(&name).ok().map(RoomStatusResult::from)
}

#[wasm_bindgen]
Expand Down
8 changes: 4 additions & 4 deletions src/objects/impls/room_terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ extern "C" {
#[wasm_bindgen(js_namespace = Room, js_name = Terrain)]
pub type RoomTerrain;

#[wasm_bindgen(constructor, js_namespace = Room, js_class = Terrain)]
fn new_internal(room_name: &JsString) -> RoomTerrain;
#[wasm_bindgen(constructor, js_namespace = Room, js_class = Terrain, catch)]
fn new_internal(room_name: &JsString) -> Result<RoomTerrain, JsValue>;

/// Get the type of terrain at given coordinates.
///
Expand All @@ -38,10 +38,10 @@ impl RoomTerrain {
/// of the room.
///
/// [Screeps documentation](https://docs.screeps.com/api/#Room.Terrain.constructor)
pub fn new(room_name: RoomName) -> RoomTerrain {
pub fn new(room_name: RoomName) -> Option<RoomTerrain> {
let name = room_name.into();

Self::new_internal(&name)
Self::new_internal(&name).ok()
}

/// Get a copy of the underlying Uint8Array with the data about the room's
Expand Down

0 comments on commit ffb89d6

Please sign in to comment.