Different content grids

This commit is contained in:
2026-06-16 00:01:02 -05:00
parent 4929734212
commit 50d56aa428
5 changed files with 251 additions and 82 deletions
+112
View File
@@ -0,0 +1,112 @@
use super::load_board;
use crate::archetype::Archetype;
use crate::glyph::Glyph;
use crate::map_file::parse_color;
#[test]
fn fill_builds_a_full_grid_of_one_char() {
// Layer 0 is a solid fill of a fixed floor glyph; a later sparse layer places
// the player. Every cell of layer 0 must be that floor glyph.
let toml = r##"
[map]
name = "Test"
width = 3
height = 2
[[layers]]
fill = "f"
palette = { "f" = { kind = "floor", tile = ".", fg = "#112233", bg = "#445566" } }
[[layers]]
sparse = [ { x = 0, y = 0, ch = "@" } ]
palette = { " " = { kind = "empty" }, "@" = { kind = "player" } }
"##;
let board = load_board(toml);
assert!(board.is_valid());
let floor = Glyph {
tile: '.' as u32,
fg: parse_color("#112233"),
bg: parse_color("#445566"),
};
for y in 0..2 {
for x in 0..3 {
assert_eq!(*board.get(0, x, y), (floor, Archetype::Empty));
}
}
assert_eq!((board.player.x, board.player.y), (0, 0));
}
#[test]
fn sparse_places_only_listed_cells() {
// A grass floor underneath; a sparse layer holding just the player and one object.
let toml = r##"
[map]
name = "Test"
width = 4
height = 1
[[layers]]
fill = "g"
palette = { "g" = { kind = "floor", generator = "grass" } }
[[layers]]
sparse = [ { x = 0, y = 0, ch = "@" }, { x = 2, y = 0, ch = "O" } ]
palette = { " " = { kind = "empty" }, "@" = { kind = "player" }, "O" = { kind = "object", tile = 64, fg = "#00FFFF", bg = "#000000" } }
"##;
let board = load_board(toml);
assert!(board.is_valid());
assert_eq!((board.player.x, board.player.y), (0, 0));
assert_eq!(board.objects.len(), 1);
assert_eq!((board.objects[&1].x, board.objects[&1].y), (2, 0));
// An unlisted sparse cell is a transparent empty.
assert_eq!(board.get(1, 1, 0).1, Archetype::Empty);
}
#[test]
fn sparse_out_of_bounds_cell_is_nonfatal() {
let toml = r##"
[map]
name = "Test"
width = 2
height = 1
[[layers]]
sparse = [ { x = 5, y = 0, ch = "O" }, { x = 0, y = 0, ch = "@" } ]
palette = { " " = { kind = "empty" }, "@" = { kind = "player" }, "O" = { kind = "object", tile = 64, fg = "#00FFFF", bg = "#000000" } }
"##;
let board = load_board(toml);
assert!(
board.objects.is_empty(),
"out-of-bounds object cell is skipped"
);
assert!(
!board.is_valid(),
"out-of-bounds sparse cell is a nonfatal error"
);
assert_eq!((board.player.x, board.player.y), (0, 0));
}
#[test]
fn fill_must_be_a_single_char() {
// A multi-char fill falls back to a space (nonfatal); spaces resolve to empty.
let toml = r##"
[map]
name = "Test"
width = 2
height = 1
[[layers]]
fill = "xy"
palette = { " " = { kind = "empty" } }
[[layers]]
sparse = [ { x = 0, y = 0, ch = "@" } ]
palette = { " " = { kind = "empty" }, "@" = { kind = "player" } }
"##;
let board = load_board(toml);
assert!(
!board.is_valid(),
"a non-single-char fill is a nonfatal error"
);
assert_eq!(board.get(0, 1, 0).1, Archetype::Empty);
}
+1
View File
@@ -1,3 +1,4 @@
mod fill_sparse;
mod grid_errors;
mod object_placement;
mod player_placement;