2026-06-07 00:46:38 -05:00
|
|
|
|
mod actions;
|
|
|
|
|
|
mod collision;
|
2026-06-13 16:24:29 -05:00
|
|
|
|
mod game_portals;
|
2026-06-07 00:46:38 -05:00
|
|
|
|
mod map_file;
|
|
|
|
|
|
mod movement;
|
|
|
|
|
|
mod scripting;
|
|
|
|
|
|
|
2026-06-13 01:25:58 -05:00
|
|
|
|
use std::collections::{BTreeMap, HashMap};
|
2026-06-07 00:46:38 -05:00
|
|
|
|
use crate::archetype::Archetype;
|
|
|
|
|
|
use crate::board::Board;
|
|
|
|
|
|
use crate::object_def::ObjectDef;
|
|
|
|
|
|
use crate::utils::Player;
|
|
|
|
|
|
use crate::game::GameState;
|
|
|
|
|
|
|
2026-06-13 01:25:58 -05:00
|
|
|
|
/// Builds a 1×1 board with a single object that optionally references a script,
|
|
|
|
|
|
/// and returns both the board and the `(name, source)` entries as a script map.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// Pass the returned scripts to [`GameState::with_scripts`] so they are compiled.
|
|
|
|
|
|
fn board_with_object(object_script: Option<&str>, scripts: &[(&str, &str)]) -> (Board, HashMap<String, String>) {
|
2026-06-07 00:46:38 -05:00
|
|
|
|
let mut object = ObjectDef::new(0, 0);
|
2026-06-07 01:26:18 -05:00
|
|
|
|
object.id = 1;
|
2026-06-07 00:46:38 -05:00
|
|
|
|
object.script_name = object_script.map(str::to_string);
|
2026-06-13 01:25:58 -05:00
|
|
|
|
let board = Board {
|
2026-06-07 00:46:38 -05:00
|
|
|
|
name: "test".into(),
|
|
|
|
|
|
width: 1,
|
|
|
|
|
|
height: 1,
|
|
|
|
|
|
cells: vec![(Archetype::Empty.default_glyph(), Archetype::Empty)],
|
|
|
|
|
|
floor: vec![Archetype::Empty.default_glyph()],
|
|
|
|
|
|
floor_spec: None,
|
|
|
|
|
|
player: Player { x: 0, y: 0 },
|
|
|
|
|
|
objects: BTreeMap::from([(1, object)]),
|
|
|
|
|
|
next_object_id: 2,
|
|
|
|
|
|
portals: Vec::new(),
|
|
|
|
|
|
board_script_name: None,
|
|
|
|
|
|
load_errors: Vec::new(),
|
2026-06-13 01:25:58 -05:00
|
|
|
|
};
|
|
|
|
|
|
(board, scripts_from(scripts))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Converts a `(name, source)` slice into a `HashMap` suitable for
|
|
|
|
|
|
/// [`GameState::with_scripts`].
|
|
|
|
|
|
fn scripts_from(pairs: &[(&str, &str)]) -> HashMap<String, String> {
|
|
|
|
|
|
pairs.iter().map(|(k, v)| (k.to_string(), v.to_string())).collect()
|
2026-06-07 00:46:38 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Returns an `ObjectDef` at `(x, y)` bound to the named script.
|
|
|
|
|
|
fn scripted_object(x: usize, y: usize, script: &str) -> ObjectDef {
|
|
|
|
|
|
let mut o = ObjectDef::new(x, y);
|
|
|
|
|
|
o.script_name = Some(script.to_string());
|
|
|
|
|
|
o
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Flattens each log line into a single string for easy assertions.
|
|
|
|
|
|
fn log_texts(game: &GameState) -> Vec<String> {
|
|
|
|
|
|
game.log
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
.map(|line| line.spans.iter().map(|s| s.text.as_str()).collect())
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
}
|