This commit is contained in:
2026-07-14 23:48:50 -05:00
parent 03185c9c68
commit 5146cc9bcc
25 changed files with 380 additions and 272 deletions
+7 -5
View File
@@ -19,12 +19,14 @@ palette = { "#" = { kind = "wall", tile = 35, fg = "#808080", bg = "#606060" } }
let board = load_board(toml);
for y in 0..2 {
for x in 0..3 {
let expected = if (x, y) == (0, 0) {
Archetype::Empty // player won its fallback cell
if (x, y) == (0, 0) { // player won its fallback cell
assert!(board.solid_at(x, y).unwrap().player());
} else {
Archetype::Wall
};
assert_eq!(board.get(x, y).1, expected, "cell ({x}, {y})");
let obj = &board.objects[&board.object_ids_at(x, y)[0]];
let tag = obj.tags.iter().next().unwrap();
assert_eq!(tag, "BUILTIN_wall")
}
}
}
assert_eq!((board.player.x, board.player.y), (0, 0));
@@ -77,6 +77,6 @@ fn non_solid_object_and_wall_coexist_in_separate_cells() {
// never be authored onto a wall cell. A wall and a (separate-cell) non-solid
// object both load fine.
let board = load_board(&map_3x1_object("#G@", "G", "solid = false"));
assert_eq!(board.objects.len(), 1);
assert_eq!(board.objects.len(), 2); // The wall (for now) shows up as an object because it's a builtin, TODO
assert!(board.is_valid());
}
+6 -1
View File
@@ -7,6 +7,7 @@ use crate::game::GameState;
use crate::map_file::MapFile;
use crate::object_def::ObjectDef;
use std::time::Duration;
use crate::{Board, Builtin};
/// Finds the pusher object on a board (by its built-in tag).
fn pusher<'a>(board: &'a crate::board::Board, id: &mut u32) -> &'a ObjectDef {
@@ -42,6 +43,10 @@ fn pusher_loads_as_a_tagged_scripted_solid_object() {
assert!(!board.is_passable(0, 0), "pusher is solid");
}
fn is_tag(board: &Board, x: usize, y: usize, tag: &str) -> bool {
board.object_ids_at(x, y).iter().any(|id| board.objects[id].tags.contains(tag))
}
#[test]
fn pusher_advances_and_shoves_a_crate() {
// Pusher at (0,0), crate at (1,0), the player parked at the east edge.
@@ -74,7 +79,7 @@ fn pusher_advances_and_shoves_a_crate() {
"crate left its start cell"
);
assert!(
(2..b.width).any(|x| b.get(x, 0).1 == Archetype::Crate),
(2..b.width).any(|x| is_tag(&b, x, 0, "BUILTIN_crate")),
"crate was shoved east"
);
}
+1 -4
View File
@@ -10,7 +10,7 @@ use crate::utils::Direction;
use std::time::Duration;
#[test]
fn transporter_loads_as_a_tagged_scripted_solid_object() {
fn transporter_loads_as_a_tagged_scripted_object() {
let board = load_board(&map(
3,
1,
@@ -26,9 +26,6 @@ fn transporter_loads_as_a_tagged_scripted_solid_object() {
.expect("transporter object");
assert_eq!((obj.x, obj.y), (1, 0));
assert!(obj.builtin_script.is_some(), "carries the embedded script");
assert!(obj.solid, "transporter is solid");
assert!(!obj.opaque, "transporter is see-through");
assert!(!obj.pushable, "transporter cannot be pushed");
}
#[test]