Change keys from bool array to Keys struct

This commit is contained in:
2026-03-12 19:09:05 -07:00
parent 1c0641e1d6
commit afcf0cd7e3
2 changed files with 39 additions and 15 deletions
+30 -6
View File
@@ -16,7 +16,7 @@ use super::error::{DecodeError, EncodeError};
pub struct World { pub struct World {
pub ammo: i16, pub ammo: i16,
pub gems: i16, pub gems: i16,
pub keys: [bool; 7], pub keys: Keys,
pub health: i16, pub health: i16,
pub starting_board: i16, pub starting_board: i16,
pub torches: i16, pub torches: i16,
@@ -36,7 +36,7 @@ impl Default for World {
World { World {
ammo: 0, ammo: 0,
gems: 0, gems: 0,
keys: [false; 7], keys: Keys::default(),
health: 100, health: 100,
starting_board: 0, starting_board: 0,
torches: 0, torches: 0,
@@ -53,6 +53,18 @@ impl Default for World {
} }
} }
/// The player's keys, as stored in the world header.
#[derive(Clone, Debug, Default)]
pub struct Keys {
pub blue: bool,
pub green: bool,
pub cyan: bool,
pub red: bool,
pub purple: bool,
pub yellow: bool,
pub white: bool,
}
/// A ZZT board. /// A ZZT board.
#[derive(Clone)] #[derive(Clone)]
pub struct Board { pub struct Board {
@@ -217,7 +229,15 @@ impl World {
Ok(World { Ok(World {
ammo, ammo,
gems, gems,
keys: keys.try_into().unwrap(), keys: Keys {
blue: keys[0],
green: keys[1],
cyan: keys[2],
red: keys[3],
purple: keys[4],
yellow: keys[5],
white: keys[6],
},
health, health,
starting_board, starting_board,
torches, torches,
@@ -240,9 +260,13 @@ impl World {
result.push_i16(self.boards.len() as i16 - 1); result.push_i16(self.boards.len() as i16 - 1);
result.push_i16(self.ammo); result.push_i16(self.ammo);
result.push_i16(self.gems); result.push_i16(self.gems);
for key in self.keys { result.push_bool(self.keys.blue);
result.push_bool(key); result.push_bool(self.keys.green);
} result.push_bool(self.keys.cyan);
result.push_bool(self.keys.red);
result.push_bool(self.keys.purple);
result.push_bool(self.keys.yellow);
result.push_bool(self.keys.white);
result.push_i16(self.health); result.push_i16(self.health);
result.push_i16(self.starting_board); result.push_i16(self.starting_board);
result.push_i16(self.torches); result.push_i16(self.torches);
@@ -5,15 +5,15 @@ expression: world
World { World {
ammo: 1000, ammo: 1000,
gems: 1001, gems: 1001,
keys: [ keys: Keys {
true, blue: true,
false, green: false,
false, cyan: false,
true, red: true,
false, purple: false,
false, yellow: false,
true, white: true,
], },
health: 1002, health: 1002,
starting_board: 1, starting_board: 1,
torches: 1003, torches: 1003,