glyph serialization

This commit is contained in:
2026-07-26 23:29:43 -05:00
parent 9844671c46
commit ab5f22fe76
20 changed files with 408 additions and 143 deletions
+7 -7
View File
@@ -68,8 +68,8 @@ fn move_into_a_wall_or_edge_is_a_noop() {
#[test]
fn set_tile_command_changes_the_source_glyph() {
let (game, id) = game_with_mover(5, 3, (0, 0), (2, 1), "fn init(me) { set_tile(7); }");
assert_eq!(glyph(&game, id).tile, 7);
let (game, id) = game_with_mover(5, 3, (0, 0), (2, 1), "fn init(me) { set_tile(\"*\"); }");
assert_eq!(glyph(&game, id).tile, '*');
}
#[test]
@@ -164,10 +164,10 @@ fn queue_length_reports_pending_actions() {
1,
(0, 0),
(1, 0),
"fn init(me) { set_tile(5); set_tile(6); log(`len=${me.queue.length}`); }",
r#"fn init(me) { set_tile("5"); set_tile("6"); log(`len=${me.queue.length}`); }"#,
);
assert!(log_texts(&game).iter().any(|t| t == "len=2"));
assert_eq!(glyph(&game, id).tile, 6); // last set_tile won
assert_eq!(glyph(&game, id).tile, '6'); // last set_tile won
}
#[test]
@@ -186,7 +186,7 @@ fn queue_clear_drops_pending_actions() {
#[test]
fn blocked_reports_solid_and_clear() {
let src = "fn init(me) { if me.blocked(East) { set_tile(9); } else { set_tile(7); } }";
let src = r#"fn init(me) { if me.blocked(East) { set_tile("Y"); } else { set_tile("N"); } }"#;
// Solid ahead (a wall): blocked() is true.
let mut board = open_board(3, 1, (0, 0));
@@ -194,12 +194,12 @@ fn blocked_reports_solid_and_clear() {
wall_at(&mut board, 2, 0);
let mut game = GameState::with_scripts(board, scripts_from(&[("b", src)]));
game.run_init();
assert_eq!(glyph(&game, id).tile, 9);
assert_eq!(glyph(&game, id).tile, 'Y');
// Open ahead, nothing pending: blocked() is false.
let mut board = open_board(3, 1, (0, 0));
let id = object_at(&mut board, 1, 0, "b", EnterResponse::Block);
let mut game = GameState::with_scripts(board, scripts_from(&[("b", src)]));
game.run_init();
assert_eq!(glyph(&game, id).tile, 7);
assert_eq!(glyph(&game, id).tile, 'N');
}
+1 -1
View File
@@ -20,7 +20,7 @@ fn pushing_a_crate_reveals_the_floor_underneath() {
// reveal the floor glyph, not black.
let mut board = open_board(4, 1, (0, 0));
let floor_glyph = Glyph {
tile: ',' as u32,
tile: ',',
fg: Rgba8 { r: 40, g: 60, b: 40, a: 255 },
bg: Rgba8 { r: 5, g: 10, b: 5, a: 255 },
};
+2 -2
View File
@@ -167,8 +167,8 @@ fn start_map_greeter_runs_init() {
.all_ids()
.into_iter()
.filter_map(|id| game.board().get_hookable(id).map(|o| o.glyph().tile))
.any(|tile| tile == 2);
assert!(has_smiley, "greeter set_tile(2) should change its glyph");
.any(|tile| tile == '☻');
assert!(has_smiley, "greeter set_tile(\"\") should change its glyph");
}
#[test]