Using enum to store characteristic data
This commit is contained in:
parent
e083634614
commit
058a9eeea4
1 changed files with 56 additions and 37 deletions
93
src/sheet.rs
93
src/sheet.rs
|
|
@ -15,10 +15,10 @@ pub enum Classe {
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
enum CharacteristicType {
|
enum CharacteristicType {
|
||||||
Address,
|
Address(Characteristic),
|
||||||
Stamina,
|
Stamina(Characteristic),
|
||||||
Luck,
|
Luck(Characteristic),
|
||||||
Skill,
|
Skill(Characteristic),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
|
@ -26,10 +26,10 @@ pub struct CharacterSheet {
|
||||||
character_class: Classe,
|
character_class: Classe,
|
||||||
/// Field to write the personality/
|
/// Field to write the personality/
|
||||||
pub character: String,
|
pub character: String,
|
||||||
address: Characteristic,
|
address: CharacteristicType,
|
||||||
stamina: Characteristic,
|
stamina: CharacteristicType,
|
||||||
luck: Characteristic,
|
luck: CharacteristicType,
|
||||||
skill: Characteristic,
|
skill: CharacteristicType,
|
||||||
health: u32,
|
health: u32,
|
||||||
armor: u32,
|
armor: u32,
|
||||||
damage: u32,
|
damage: u32,
|
||||||
|
|
@ -51,16 +51,32 @@ impl CharacterSheet {
|
||||||
&self.character
|
&self.character
|
||||||
}
|
}
|
||||||
pub fn address(&self) -> &Characteristic {
|
pub fn address(&self) -> &Characteristic {
|
||||||
&self.address
|
if let CharacteristicType::Address(addr) = &self.address {
|
||||||
|
addr
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn stamina(&self) -> &Characteristic {
|
pub fn stamina(&self) -> &Characteristic {
|
||||||
&self.stamina
|
if let CharacteristicType::Stamina(sta) = &self.stamina {
|
||||||
|
sta
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn luck(&self) -> &Characteristic {
|
pub fn luck(&self) -> &Characteristic {
|
||||||
&self.luck
|
if let CharacteristicType::Luck(luck) = &self.luck {
|
||||||
|
luck
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn skill(&self) -> &Characteristic {
|
pub fn skill(&self) -> &Characteristic {
|
||||||
&self.skill
|
if let CharacteristicType::Skill(sk) = &self.skill {
|
||||||
|
sk
|
||||||
|
} else {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn health(&self) -> u32 {
|
pub fn health(&self) -> u32 {
|
||||||
self.health
|
self.health
|
||||||
|
|
@ -151,7 +167,6 @@ impl SheetGui for CharacterSheet {
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct Characteristic {
|
pub struct Characteristic {
|
||||||
characteristic_type: CharacteristicType,
|
|
||||||
pub base: u32,
|
pub base: u32,
|
||||||
pub carac: u32,
|
pub carac: u32,
|
||||||
pub materiel: u32,
|
pub materiel: u32,
|
||||||
|
|
@ -163,33 +178,37 @@ impl Default for CharacterSheet {
|
||||||
Self {
|
Self {
|
||||||
character_class: Classe::Warrior,
|
character_class: Classe::Warrior,
|
||||||
character: "Billy".to_string(),
|
character: "Billy".to_string(),
|
||||||
address: Characteristic {
|
address: CharacteristicType::Address {
|
||||||
characteristic_type: CharacteristicType::Address,
|
0: Characteristic {
|
||||||
base: 0,
|
base: 0,
|
||||||
carac: 0,
|
carac: 0,
|
||||||
materiel: 0,
|
materiel: 0,
|
||||||
additional: 1,
|
additional: 1,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
stamina: Characteristic {
|
stamina: CharacteristicType::Stamina {
|
||||||
characteristic_type: CharacteristicType::Stamina,
|
0: Characteristic {
|
||||||
base: 2,
|
base: 2,
|
||||||
carac: 0,
|
carac: 0,
|
||||||
materiel: 0,
|
materiel: 0,
|
||||||
additional: 0,
|
additional: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
luck: Characteristic {
|
luck: CharacteristicType::Luck {
|
||||||
characteristic_type: CharacteristicType::Luck,
|
0: Characteristic {
|
||||||
base: 3,
|
base: 3,
|
||||||
carac: 0,
|
carac: 0,
|
||||||
materiel: 0,
|
materiel: 0,
|
||||||
additional: 0,
|
additional: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
skill: Characteristic {
|
skill: CharacteristicType::Skill {
|
||||||
characteristic_type: CharacteristicType::Skill,
|
0: Characteristic {
|
||||||
base: 2,
|
base: 2,
|
||||||
carac: 0,
|
carac: 0,
|
||||||
materiel: 0,
|
materiel: 0,
|
||||||
additional: 0,
|
additional: 0,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
health: 0,
|
health: 0,
|
||||||
armor: 0,
|
armor: 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue