mod actions; mod collision; mod game_portals; mod map_file; mod movement; mod scripting; use crate::archetype::Archetype; use crate::board::Board; use crate::floor::Floor; use crate::game::GameState; use crate::glyph::Glyph; use crate::object_def::ObjectDef; use crate::utils::PlayerPos; use std::collections::{BTreeMap, HashMap}; /// 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) { let mut object = ObjectDef::new(0, 0); object.id = 1; object.script_name = object_script.map(str::to_string); let board = Board { name: "test".into(), width: 1, height: 1, grid: vec![(Glyph::transparent(), Archetype::Empty)], floor: Floor::Blank, decorations: Vec::new(), player: PlayerPos { x: 0, y: 0 }, objects: BTreeMap::from([(1, object)]), next_object_id: 2, portals: Vec::new(), board_script_name: None, load_errors: Vec::new(), registry: HashMap::new(), }; (board, scripts_from(scripts)) } /// Converts a `(name, source)` slice into a `HashMap` suitable for /// [`GameState::with_scripts`]. fn scripts_from(pairs: &[(&str, &str)]) -> HashMap { pairs .iter() .map(|(k, v)| (k.to_string(), v.to_string())) .collect() } /// 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 { game.log .iter() .map(|line| line.spans.iter().map(|s| s.text.as_str()).collect()) .collect() }