refactoring

This commit is contained in:
2026-06-07 00:19:53 -05:00
parent ea18fe8fc2
commit ea79dc20f9
13 changed files with 805 additions and 749 deletions
+11 -6
View File
@@ -1,11 +1,16 @@
use crate::floor::{FloorSpec, build_floor};
use crate::game::{Archetype, Board, FontSpec, Glyph, ObjectDef, ObjectId, Player, PortalDef};
use crate::floor::{build_floor, FloorSpec};
use crate::board::Board;
use crate::log::LogLine;
use color::Rgba8;
use serde::{Deserialize, Serialize};
use std::collections::{BTreeMap, HashMap};
use std::convert::TryFrom;
use std::path::Path;
use crate::archetype::Archetype;
use crate::font::FontSpec;
use crate::glyph::Glyph;
use crate::object_def::ObjectDef;
use crate::utils::{ObjectId, Player, PortalDef};
/// The top-level serialization/deserialization type for a `.toml` map file.
///
@@ -701,7 +706,7 @@ pub fn save(board: &Board, path: &Path) -> Result<(), Box<dyn std::error::Error>
#[cfg(test)]
mod tests {
use super::*;
use crate::game::Archetype;
use crate::archetype::Archetype;
/// Parses `toml` and converts it to a [`Board`], panicking on any hard error.
/// (Object/placement validation failures are non-fatal `eprintln`s, so the
@@ -981,7 +986,7 @@ O.
let mf: MapFile = toml::from_str(toml).unwrap();
let board = Board::try_from(mf).unwrap();
let (_, arch) = board.get(0, 0);
assert_eq!(*arch, crate::game::Archetype::ErrorBlock);
assert_eq!(*arch, Archetype::ErrorBlock);
}
#[test]
@@ -1087,12 +1092,12 @@ g.
bg: parse_color("#040506"),
};
// (1,0) is the fixed `.` floor glyph (the cell archetype is Empty).
assert_eq!(board.display_glyph(1, 0), fixed);
assert_eq!(board.glyph_at(1, 0), fixed);
// Save back to TOML and reload; the floor declaration must be preserved.
let toml_out = toml::to_string_pretty(&MapFile::from(&board)).unwrap();
let board2 = load_board(&toml_out);
assert!(board2.floor_spec.is_some());
assert_eq!(board2.display_glyph(1, 0), fixed);
assert_eq!(board2.glyph_at(1, 0), fixed);
}
}