Using enum to store characteristic data

This commit is contained in:
Pcornat 2026-02-04 21:25:57 +01:00
commit 058a9eeea4
Signed by: Pcornat
GPG key ID: E0326CC678A00BDD

View file

@ -15,10 +15,10 @@ pub enum Classe {
#[derive(Debug, Serialize, Deserialize)]
enum CharacteristicType {
Address,
Stamina,
Luck,
Skill,
Address(Characteristic),
Stamina(Characteristic),
Luck(Characteristic),
Skill(Characteristic),
}
#[derive(Debug, Serialize, Deserialize)]
@ -26,10 +26,10 @@ pub struct CharacterSheet {
character_class: Classe,
/// Field to write the personality/
pub character: String,
address: Characteristic,
stamina: Characteristic,
luck: Characteristic,
skill: Characteristic,
address: CharacteristicType,
stamina: CharacteristicType,
luck: CharacteristicType,
skill: CharacteristicType,
health: u32,
armor: u32,
damage: u32,
@ -51,16 +51,32 @@ impl CharacterSheet {
&self.character
}
pub fn address(&self) -> &Characteristic {
&self.address
if let CharacteristicType::Address(addr) = &self.address {
addr
} else {
unreachable!()
}
}
pub fn stamina(&self) -> &Characteristic {
&self.stamina
if let CharacteristicType::Stamina(sta) = &self.stamina {
sta
} else {
unreachable!()
}
}
pub fn luck(&self) -> &Characteristic {
&self.luck
if let CharacteristicType::Luck(luck) = &self.luck {
luck
} else {
unreachable!()
}
}
pub fn skill(&self) -> &Characteristic {
&self.skill
if let CharacteristicType::Skill(sk) = &self.skill {
sk
} else {
unreachable!()
}
}
pub fn health(&self) -> u32 {
self.health
@ -151,7 +167,6 @@ impl SheetGui for CharacterSheet {
#[derive(Debug, Serialize, Deserialize)]
pub struct Characteristic {
characteristic_type: CharacteristicType,
pub base: u32,
pub carac: u32,
pub materiel: u32,
@ -163,33 +178,37 @@ impl Default for CharacterSheet {
Self {
character_class: Classe::Warrior,
character: "Billy".to_string(),
address: Characteristic {
characteristic_type: CharacteristicType::Address,
base: 0,
carac: 0,
materiel: 0,
additional: 1,
address: CharacteristicType::Address {
0: Characteristic {
base: 0,
carac: 0,
materiel: 0,
additional: 1,
},
},
stamina: Characteristic {
characteristic_type: CharacteristicType::Stamina,
base: 2,
carac: 0,
materiel: 0,
additional: 0,
stamina: CharacteristicType::Stamina {
0: Characteristic {
base: 2,
carac: 0,
materiel: 0,
additional: 0,
},
},
luck: Characteristic {
characteristic_type: CharacteristicType::Luck,
base: 3,
carac: 0,
materiel: 0,
additional: 0,
luck: CharacteristicType::Luck {
0: Characteristic {
base: 3,
carac: 0,
materiel: 0,
additional: 0,
},
},
skill: Characteristic {
characteristic_type: CharacteristicType::Skill,
base: 2,
carac: 0,
materiel: 0,
additional: 0,
skill: CharacteristicType::Skill {
0: Characteristic {
base: 2,
carac: 0,
materiel: 0,
additional: 0,
},
},
health: 0,
armor: 0,