use serde::Deserialize; use std::collections::HashMap; #[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Copy)] pub enum AbilityScore { Strength, Intelligence, Wisdom, Dexterity, Constitution, Charisma, } impl AbilityScore { pub fn abbr(&self) -> &'static str { match *self { AbilityScore::Strength => "STR", AbilityScore::Intelligence => "INT", AbilityScore::Wisdom => "WIS", AbilityScore::Dexterity => "DEX", AbilityScore::Constitution => "CON", AbilityScore::Charisma => "CHA", } } } #[derive(Debug)] pub struct AbilityScoreCollection { scores: HashMap>, } impl AbilityScoreCollection { pub fn new() -> Self { AbilityScoreCollection { scores: HashMap::new(), } } pub fn add_score(&mut self, ability_score: AbilityScore, bonus: u32) { self.scores .entry(ability_score) .or_insert_with(Vec::new) .push(bonus); } pub fn get_score(&self, ability_score: AbilityScore) -> Option<&Vec> { self.scores.get(&ability_score) } }