summaryrefslogtreecommitdiff
path: root/src/rules/ability_scores.rs
blob: 205c1a3c559820ec0686590a84969c10f91d9485 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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, Vec<u32>>,
}

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<u32>> {
        self.scores.get(&ability_score)
    }
}