91 lines
2.0 KiB
Rust
91 lines
2.0 KiB
Rust
mod grid_errors;
|
||
mod object_placement;
|
||
mod player_placement;
|
||
mod portal_placement;
|
||
mod round_trip;
|
||
|
||
use crate::board::Board;
|
||
use crate::map_file::MapFile;
|
||
|
||
fn load_board(toml: &str) -> Board {
|
||
let mf: MapFile = toml::from_str(toml).expect("parse toml");
|
||
Board::try_from(mf).expect("convert to board")
|
||
}
|
||
|
||
/// A 3×1 map (`empty` palette `.`) whose grid is `grid`, plus the given
|
||
/// `[[objects]]` TOML appended. Keeps placement tests compact.
|
||
fn map_3x1(grid: &str, objects: &str) -> String {
|
||
format!(
|
||
r##"
|
||
[map]
|
||
name = "Test"
|
||
width = 3
|
||
height = 1
|
||
player_start = [2, 0]
|
||
|
||
[palette]
|
||
"." = {{ archetype = "empty", tile = 46, fg = "#000000", bg = "#000000" }}
|
||
"#" = {{ archetype = "wall", tile = 35, fg = "#808080", bg = "#606060" }}
|
||
|
||
[grid]
|
||
content = """
|
||
{grid}
|
||
"""
|
||
{objects}
|
||
"##
|
||
)
|
||
}
|
||
|
||
/// A standard `[[objects]]` block placed by palette char `ch`.
|
||
fn obj_palette(ch: &str, extra: &str) -> String {
|
||
format!(
|
||
"[[objects]]\npalette = \"{ch}\"\ntile = 64\nfg = \"#00FFFF\"\nbg = \"#000000\"\n{extra}"
|
||
)
|
||
}
|
||
|
||
/// A 1-row map of the given `width` with a raw `player_start` TOML value
|
||
/// (`start`, e.g. `[1, 0]` or `"@"`), grid, and objects block.
|
||
fn player_map(width: usize, start: &str, grid: &str, objects: &str) -> String {
|
||
format!(
|
||
r##"
|
||
[map]
|
||
name = "Test"
|
||
width = {width}
|
||
height = 1
|
||
player_start = {start}
|
||
|
||
[palette]
|
||
"." = {{ archetype = "empty", tile = 46, fg = "#000000", bg = "#000000" }}
|
||
"#" = {{ archetype = "wall", tile = 35, fg = "#808080", bg = "#606060" }}
|
||
|
||
[grid]
|
||
content = """
|
||
{grid}
|
||
"""
|
||
{objects}
|
||
"##
|
||
)
|
||
}
|
||
|
||
/// Minimal valid TOML with a configurable grid, used as a base for dimension tests.
|
||
fn minimal_toml(width: usize, height: usize, grid_rows: &[&str]) -> String {
|
||
let content = grid_rows.join("\n");
|
||
format!(
|
||
r##"
|
||
[map]
|
||
name = "Test"
|
||
width = {width}
|
||
height = {height}
|
||
player_start = [0, 0]
|
||
|
||
[palette]
|
||
"." = {{ archetype = "empty", tile = 46, fg = "#000000", bg = "#000000" }}
|
||
|
||
[grid]
|
||
content = """
|
||
{content}
|
||
"""
|
||
"##
|
||
)
|
||
}
|