dmn 0.0.2

CLI and library for DMs and other players of Advanced Dungeons & Dragons (AD&D)
Documentation
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<AbilityScore, i32>,
}

impl AbilityScoreCollection {
    pub fn new() -> Self {
        AbilityScoreCollection {
            scores: HashMap::new(),
        }
    }

    pub fn add_score(&mut self, ability_score: AbilityScore, value: i32) {
        self.scores.insert(ability_score, value);
    }

    pub fn get_score(&self, ability_score: AbilityScore) -> Option<&i32> {
        self.scores.get(&ability_score)
    }
}