Conform to serialization used by ALttpDoorRandomizer.
This commit is contained in:
parent
975d6fd420
commit
76ff991e8f
|
@ -9,6 +9,7 @@ use crate::bosses::BossType;
|
|||
use crate::InvalidEnumError;
|
||||
|
||||
#[derive(Debug, Default, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
pub struct ManualBosses {
|
||||
pub eastern_palace: String,
|
||||
pub desert_palace: String,
|
||||
|
@ -183,18 +184,22 @@ impl TryFrom<u8> for ShieldType {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
|
||||
#[serde(into = "u8", try_from = "u8")]
|
||||
pub enum AbsorbableType {
|
||||
Heart,
|
||||
GreenRupee,
|
||||
BlueRupee,
|
||||
RedRupee,
|
||||
#[serde(alias = "Bomb_1")]
|
||||
Bomb1,
|
||||
#[serde(alias = "Bomb_4")]
|
||||
Bomb4,
|
||||
#[serde(alias = "Bomb_8")]
|
||||
Bomb8,
|
||||
SmallMagic,
|
||||
FullMagic,
|
||||
#[serde(alias = "Arrow_5")]
|
||||
Arrow5,
|
||||
#[serde(alias = "Arrow_10")]
|
||||
Arrow10,
|
||||
Fairy,
|
||||
Key,
|
||||
|
@ -316,6 +321,7 @@ impl TryFrom<u8> for HeartBeepSpeed {
|
|||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||
#[serde(into = "u8", try_from = "u8")]
|
||||
pub enum BeeLevel {
|
||||
Level1,
|
||||
Level2,
|
||||
|
@ -380,26 +386,26 @@ pub struct OptionFlags {
|
|||
pub shuffle_enemy_damage_groups: bool,
|
||||
pub enemy_damage_chaos_mode: bool,
|
||||
|
||||
pub easy_mode_escape: bool,
|
||||
//pub easy_mode_escape: bool,
|
||||
|
||||
pub enemies_absorbable: bool,
|
||||
pub absorbable_spawn_rate: u8,
|
||||
pub absorbable_types: HashMap<AbsorbableType, bool>,
|
||||
|
||||
pub boss_madness: bool,
|
||||
//pub boss_madness: bool,
|
||||
|
||||
pub randomize_bosses: bool,
|
||||
pub randomize_bosses_type: RandomizeBossesType,
|
||||
|
||||
pub randomize_boss_health: bool,
|
||||
pub randomize_boss_health_min_amount: u8,
|
||||
pub randomize_boss_health_max_amount: u8,
|
||||
//pub randomize_boss_health: bool,
|
||||
//pub randomize_boss_health_min_amount: u8,
|
||||
//pub randomize_boss_health_max_amount: u8,
|
||||
|
||||
pub randomize_boss_damage: bool,
|
||||
pub randomize_boss_damage_min_amount: u8,
|
||||
pub randomize_boss_damage_max_amount: u8,
|
||||
//pub randomize_boss_damage: bool,
|
||||
//pub randomize_boss_damage_min_amount: u8,
|
||||
//pub randomize_boss_damage_max_amount: u8,
|
||||
|
||||
pub randomize_boss_behavior: bool,
|
||||
//pub randomize_boss_behavior: bool,
|
||||
|
||||
pub randomize_dungeon_palettes: bool,
|
||||
pub set_blackout_mode: bool,
|
||||
|
@ -418,7 +424,7 @@ pub struct OptionFlags {
|
|||
pub shuffle_music: bool,
|
||||
pub bootleg_magic: bool,
|
||||
pub debug_mode: bool,
|
||||
pub custom_bosses: bool,
|
||||
//pub custom_bosses: bool,
|
||||
pub heart_beep_speed: HeartBeepSpeed,
|
||||
pub alternate_gfx: bool,
|
||||
pub shield_graphics: PathBuf,
|
||||
|
@ -472,20 +478,20 @@ impl OptionFlags {
|
|||
randomize_enemy_health_type: bytes[4].try_into()?,
|
||||
randomize_enemy_damage: bytes[5] != 0,
|
||||
allow_enemy_zero_damage: bytes[6] != 0,
|
||||
easy_mode_escape: bytes[7] != 0,
|
||||
//easy_mode_escape: bytes[7] != 0,
|
||||
enemies_absorbable: bytes[8] != 0,
|
||||
absorbable_spawn_rate: bytes[9],
|
||||
absorbable_types,
|
||||
boss_madness: bytes[24] != 0,
|
||||
//boss_madness: bytes[24] != 0,
|
||||
randomize_bosses: bytes[25] != 0,
|
||||
randomize_bosses_type: bytes[26].try_into()?,
|
||||
randomize_boss_health: bytes[27] != 0,
|
||||
randomize_boss_health_min_amount: bytes[28],
|
||||
randomize_boss_health_max_amount: bytes[29],
|
||||
randomize_boss_damage: bytes[30] != 0,
|
||||
randomize_boss_damage_min_amount: bytes[31],
|
||||
randomize_boss_damage_max_amount: bytes[32],
|
||||
randomize_boss_behavior: bytes[33] != 0,
|
||||
//randomize_boss_health: bytes[27] != 0,
|
||||
//randomize_boss_health_min_amount: bytes[28],
|
||||
//randomize_boss_health_max_amount: bytes[29],
|
||||
//randomize_boss_damage: bytes[30] != 0,
|
||||
//randomize_boss_damage_min_amount: bytes[31],
|
||||
//randomize_boss_damage_max_amount: bytes[32],
|
||||
//randomize_boss_behavior: bytes[33] != 0,
|
||||
randomize_dungeon_palettes: bytes[34] != 0,
|
||||
set_blackout_mode: bytes[35] != 0,
|
||||
randomize_overworld_palettes: bytes[36] != 0,
|
||||
|
@ -500,7 +506,7 @@ impl OptionFlags {
|
|||
shuffle_music: bytes[45] != 0,
|
||||
bootleg_magic: bytes[46] != 0,
|
||||
debug_mode: bytes[47] != 0,
|
||||
custom_bosses: bytes[48] != 0,
|
||||
//custom_bosses: bytes[48] != 0,
|
||||
heart_beep_speed: bytes[49].try_into()?,
|
||||
alternate_gfx: bytes[50] != 0,
|
||||
// Skip byte 51 (shield_graphics)
|
||||
|
@ -539,7 +545,7 @@ impl OptionFlags {
|
|||
bytes.push(self.randomize_enemy_health_type as u8);
|
||||
bytes.push(self.randomize_enemy_damage as u8);
|
||||
bytes.push(self.allow_enemy_zero_damage as u8);
|
||||
bytes.push(self.easy_mode_escape as u8);
|
||||
bytes.push(0); //bytes.push(self.easy_mode_escape as u8);
|
||||
bytes.push(self.enemies_absorbable as u8);
|
||||
bytes.push(self.absorbable_spawn_rate);
|
||||
|
||||
|
@ -628,16 +634,16 @@ impl OptionFlags {
|
|||
.unwrap_or(false) as u8,
|
||||
);
|
||||
|
||||
bytes.push(self.boss_madness as u8);
|
||||
bytes.push(0); //bytes.push(self.boss_madness as u8);
|
||||
bytes.push(self.randomize_bosses as u8);
|
||||
bytes.push(self.randomize_bosses_type as u8);
|
||||
bytes.push(self.randomize_boss_health as u8);
|
||||
bytes.push(self.randomize_boss_health_min_amount);
|
||||
bytes.push(self.randomize_boss_health_max_amount);
|
||||
bytes.push(self.randomize_boss_damage as u8);
|
||||
bytes.push(self.randomize_boss_damage_min_amount);
|
||||
bytes.push(self.randomize_boss_damage_max_amount);
|
||||
bytes.push(self.randomize_boss_behavior as u8);
|
||||
bytes.push(0); //bytes.push(self.randomize_boss_health as u8);
|
||||
bytes.push(0); //bytes.push(self.randomize_boss_health_min_amount);
|
||||
bytes.push(0); //bytes.push(self.randomize_boss_health_max_amount);
|
||||
bytes.push(0); //bytes.push(self.randomize_boss_damage as u8);
|
||||
bytes.push(0); //bytes.push(self.randomize_boss_damage_min_amount);
|
||||
bytes.push(0); //bytes.push(self.randomize_boss_damage_max_amount);
|
||||
bytes.push(0); //bytes.push(self.randomize_boss_behavior as u8);
|
||||
bytes.push(self.randomize_dungeon_palettes as u8);
|
||||
bytes.push(self.set_blackout_mode as u8);
|
||||
bytes.push(self.randomize_overworld_palettes as u8);
|
||||
|
@ -652,7 +658,7 @@ impl OptionFlags {
|
|||
bytes.push(self.shuffle_music as u8);
|
||||
bytes.push(self.bootleg_magic as u8);
|
||||
bytes.push(self.debug_mode as u8);
|
||||
bytes.push(self.custom_bosses as u8);
|
||||
bytes.push(0); //bytes.push(self.custom_bosses as u8);
|
||||
bytes.push(self.heart_beep_speed as u8);
|
||||
bytes.push(self.alternate_gfx as u8);
|
||||
bytes.push(0); // self.shield_graphics
|
||||
|
@ -695,20 +701,20 @@ impl Default for OptionFlags {
|
|||
allow_enemy_zero_damage: false,
|
||||
shuffle_enemy_damage_groups: false,
|
||||
enemy_damage_chaos_mode: false,
|
||||
easy_mode_escape: false,
|
||||
//easy_mode_escape: false,
|
||||
enemies_absorbable: false,
|
||||
absorbable_spawn_rate: 0,
|
||||
absorbable_types: HashMap::new(),
|
||||
boss_madness: false,
|
||||
//boss_madness: false,
|
||||
randomize_bosses: true,
|
||||
randomize_bosses_type: RandomizeBossesType::Chaos,
|
||||
randomize_boss_health: false,
|
||||
randomize_boss_health_min_amount: 0,
|
||||
randomize_boss_health_max_amount: 0,
|
||||
randomize_boss_damage: false,
|
||||
randomize_boss_damage_min_amount: 0,
|
||||
randomize_boss_damage_max_amount: 0,
|
||||
randomize_boss_behavior: false,
|
||||
//randomize_boss_health: false,
|
||||
//randomize_boss_health_min_amount: 0,
|
||||
//randomize_boss_health_max_amount: 0,
|
||||
//randomize_boss_damage: false,
|
||||
//randomize_boss_damage_min_amount: 0,
|
||||
//randomize_boss_damage_max_amount: 0,
|
||||
//randomize_boss_behavior: false,
|
||||
randomize_dungeon_palettes: true,
|
||||
set_blackout_mode: false,
|
||||
randomize_overworld_palettes: true,
|
||||
|
@ -723,7 +729,7 @@ impl Default for OptionFlags {
|
|||
shuffle_music: false,
|
||||
bootleg_magic: false,
|
||||
debug_mode: false,
|
||||
custom_bosses: false,
|
||||
//custom_bosses: false,
|
||||
heart_beep_speed: HeartBeepSpeed::Half,
|
||||
alternate_gfx: false,
|
||||
shield_graphics: ["shield_gfx", "normal.gfx"].iter().collect(),
|
||||
|
@ -751,3 +757,17 @@ impl Default for OptionFlags {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_option_flags_serde() {
|
||||
let empty = "{}";
|
||||
let actual: OptionFlags = serde_json::from_str(empty).expect("Can't deserialize empty");
|
||||
let expected = serde_json::to_string(&OptionFlags::default()).expect("Can't serialize default");
|
||||
|
||||
assert_eq!(serde_json::to_string(&actual).expect("Can't roundtrip"), expected);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue