Using enum to store characteristic data
This commit is contained in:
parent
e083634614
commit
058a9eeea4
1 changed files with 56 additions and 37 deletions
61
src/sheet.rs
61
src/sheet.rs
|
|
@ -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,34 +178,38 @@ impl Default for CharacterSheet {
|
|||
Self {
|
||||
character_class: Classe::Warrior,
|
||||
character: "Billy".to_string(),
|
||||
address: Characteristic {
|
||||
characteristic_type: CharacteristicType::Address,
|
||||
address: CharacteristicType::Address {
|
||||
0: Characteristic {
|
||||
base: 0,
|
||||
carac: 0,
|
||||
materiel: 0,
|
||||
additional: 1,
|
||||
},
|
||||
stamina: Characteristic {
|
||||
characteristic_type: CharacteristicType::Stamina,
|
||||
},
|
||||
stamina: CharacteristicType::Stamina {
|
||||
0: Characteristic {
|
||||
base: 2,
|
||||
carac: 0,
|
||||
materiel: 0,
|
||||
additional: 0,
|
||||
},
|
||||
luck: Characteristic {
|
||||
characteristic_type: CharacteristicType::Luck,
|
||||
},
|
||||
luck: CharacteristicType::Luck {
|
||||
0: Characteristic {
|
||||
base: 3,
|
||||
carac: 0,
|
||||
materiel: 0,
|
||||
additional: 0,
|
||||
},
|
||||
skill: Characteristic {
|
||||
characteristic_type: CharacteristicType::Skill,
|
||||
},
|
||||
skill: CharacteristicType::Skill {
|
||||
0: Characteristic {
|
||||
base: 2,
|
||||
carac: 0,
|
||||
materiel: 0,
|
||||
additional: 0,
|
||||
},
|
||||
},
|
||||
health: 0,
|
||||
armor: 0,
|
||||
damage: 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue