From 82d742a7b3b599b1fd7899dff9aee8f09dca9ddb Mon Sep 17 00:00:00 2001 From: Shane Madden Date: Wed, 17 Jul 2024 20:00:32 -0600 Subject: [PATCH] Make ROOM_AREA public and move to extra constants (#525) --- CHANGELOG.md | 4 ++++ src/constants/extra.rs | 5 +++++ src/local/cost_matrix.rs | 3 ++- src/local/room_xy.rs | 4 +--- src/local/terrain.rs | 7 +++++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8d111d3..d4382c13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Unreleased ========== +### Misc: + +- Move crate constant `ROOM_AREA` to extra constants module and make public + 0.21.1 (2024-06-28) =================== diff --git a/src/constants/extra.rs b/src/constants/extra.rs index 561ea03f..a3e1a513 100644 --- a/src/constants/extra.rs +++ b/src/constants/extra.rs @@ -267,6 +267,11 @@ pub const ROOM_VISUAL_PER_ROOM_SIZE_LIMIT: u32 = 500 * 1024; /// [`Room`]: crate::objects::Room pub const ROOM_SIZE: u8 = 50; +/// The number of total tiles in each [`Room`] in the game +/// +/// [`Room`]: crate::objects::Room +pub const ROOM_AREA: usize = (ROOM_SIZE as usize) * (ROOM_SIZE as usize); + /// Owner username of hostile non-player structures and creeps which occupy /// sector center rooms. pub const SOURCE_KEEPER_USERNAME: &str = "Source Keeper"; diff --git a/src/local/cost_matrix.rs b/src/local/cost_matrix.rs index da9ca082..ede28ba0 100644 --- a/src/local/cost_matrix.rs +++ b/src/local/cost_matrix.rs @@ -3,11 +3,12 @@ use std::ops::{Index, IndexMut}; use serde::{Deserialize, Serialize}; use crate::{ + constants::ROOM_AREA, objects::CostMatrix, traits::{CostMatrixGet, CostMatrixSet}, }; -use super::{linear_index_to_xy, xy_to_linear_index, Position, RoomXY, ROOM_AREA}; +use super::{linear_index_to_xy, xy_to_linear_index, Position, RoomXY}; /// A matrix of pathing costs for a room, stored in Rust memory. /// diff --git a/src/local/room_xy.rs b/src/local/room_xy.rs index c11bb441..4f1e9699 100644 --- a/src/local/room_xy.rs +++ b/src/local/room_xy.rs @@ -3,14 +3,12 @@ use std::{cmp::Ordering, fmt}; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use super::room_coordinate::{OutOfBoundsError, RoomCoordinate}; -use crate::constants::{Direction, ROOM_SIZE}; +use crate::constants::{Direction, ROOM_AREA, ROOM_SIZE}; mod approximate_offsets; mod extra_math; mod game_math; -pub(crate) const ROOM_AREA: usize = (ROOM_SIZE as usize) * (ROOM_SIZE as usize); - /// Converts a [`RoomXY`] coordinate pair to a linear index appropriate for use /// with the internal representation of a [`CostMatrix`] or [`LocalCostMatrix`]. /// diff --git a/src/local/terrain.rs b/src/local/terrain.rs index 0462895d..8b8b8e14 100644 --- a/src/local/terrain.rs +++ b/src/local/terrain.rs @@ -2,9 +2,12 @@ use std::mem::MaybeUninit; use js_sys::Uint8Array; -use crate::{constants::Terrain, objects::RoomTerrain}; +use crate::{ + constants::{Terrain, ROOM_AREA}, + objects::RoomTerrain, +}; -use super::{xy_to_terrain_index, RoomXY, ROOM_AREA}; +use super::{xy_to_terrain_index, RoomXY}; #[derive(Debug, Clone)] pub struct LocalRoomTerrain {