This commit is contained in:
2026-08-10 22:13:21 -05:00
parent 30e09a40c4
commit a8444b25ad
11 changed files with 330 additions and 155 deletions
+25 -1
View File
@@ -2,7 +2,7 @@ use crate::floor::Floor;
use crate::fov::{color_to_rgb, FovCaster, Lighting};
use crate::glyph::Glyph;
use crate::log::LogLine;
use crate::utils::Direction;
use crate::utils::{Direction, Point};
use crate::utils::{ObjectId, RegistryValue};
use std::collections::{HashMap, HashSet};
use crate::portal::Portal;
@@ -619,6 +619,30 @@ impl Board {
}
}
}
/// Moves whatever is in `from` to `to`, leaving an empty cell behind. Silent no-op if either
/// `from` or `to` is out of bounds, or if they're the same cell.
pub fn move_cell(&mut self, from: Point, to: Point) {
if from != to && self.in_bounds(from.into()) && self.in_bounds(to.into()) {
let thing = self.get_mut(from.x as usize, from.y as usize).take();
self.grid[to.x as usize + to.y as usize * self.width] = thing;
}
}
/// Return whether the given point is empty
pub fn is_empty(&self, p: Point) -> bool {
self.get(p.x as usize, p.y as usize).is_none()
}
/// Return whether the given point contains the player
pub fn is_player(&self, p: Point) -> bool {
matches!(self.get(p.x as usize, p.y as usize), Some(Tile::Player))
}
/// Return whether the given point contains an object
pub fn is_object(&self, p: Point) -> bool {
matches!(self.get(p.x as usize, p.y as usize), Some(Tile::Object(_)))
}
}
#[cfg(test)]