Fixed game.rs tests

This commit is contained in:
2026-07-25 00:09:53 -05:00
parent 855b287a88
commit a80155188f
2 changed files with 127 additions and 112 deletions
+44 -2
View File
@@ -633,10 +633,10 @@ pub(crate) mod tests {
use crate::builtin::Builtin;
use crate::floor::Floor;
use crate::glyph::Glyph;
use crate::utils::Direction;
use crate::utils::{Direction, ObjectId};
use color::Rgba8;
use std::collections::HashMap;
use crate::tile::{DrawLayer, IntoTile, Optics, ScriptAttributes, Sensor, Tile, TileSpec};
use crate::tile::{DrawLayer, IntoTile, Optics, ScriptAttributes, Sensor, SensorSpec, Tile, TileSpec};
/// Builds an all-empty `w×h` board.
///
@@ -685,6 +685,48 @@ pub(crate) mod tests {
*board.get_mut(x, y) = Some(TileSpec::gem().into_tile(&mut board.next_object_id).unwrap());
}
/// Stamps the builtin named `kind` (any alias accepted by [`Builtin::from_name`],
/// e.g. `"spinner_cw"`, `"pusher_east"`) onto the grid, returning its id.
///
/// The generic counterpart to [`crate_at`]/[`wall_at`]/[`gem_at`]: `into_tile`
/// attaches the family's [`ScriptKey`](crate::tile::ScriptKey) and the
/// `BUILTIN_<kind>` tag, so the object is fully live with no world script pool.
/// Panics on an unknown `kind`.
pub(crate) fn builtin_at(board: &mut Board, x: usize, y: usize, kind: &str) -> ObjectId {
let tile = TileSpec::Builtin { kind: kind.to_string(), glyph: None }
.into_tile(&mut board.next_object_id)
.unwrap_or_else(|e| panic!("{e}"));
let id = match &tile {
Tile::Object(obj) => obj.scripting.id,
Tile::Player => unreachable!("a builtin never resolves to the player"),
};
*board.get_mut(x, y) = Some(tile);
id
}
/// Adds an invisible, script-only [`Sensor`] at `(x, y)` running the world script
/// named `script`, returning its id.
///
/// This is how a test gets "a scripted thing that doesn't get in the way": every
/// object on the grid is solid now, so a script host that must not block movement
/// (or must share a cell) has to live off-grid in [`Board::sensors`].
pub(crate) fn sensor_at(board: &mut Board, x: usize, y: usize, script: &str) -> ObjectId {
let sensor = SensorSpec {
x,
y,
script: Some(script.to_string()),
glyph: Glyph::transparent(),
optics: Optics::default(),
name: None,
tags: Vec::new(),
draw_layer: DrawLayer::Below,
}
.into_sensor(&mut board.next_object_id);
let id = sensor.scripting.id;
board.sensors.push(sensor);
id
}
/// Stamps a player cell onto the grid.
pub(crate) fn player_at(board: &mut Board, x: usize, y: usize) {
*board.get_mut(x, y) = Some(TileSpec::player().into_tile(&mut board.next_object_id).unwrap());