summaryrefslogtreecommitdiff
path: root/src/rules/races.rs
blob: 6c9b00f6ecaadd24f538a15150327522da3b988c (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
use crate::rules::ability_scores::AbilityScore;
use lazy_static::lazy_static;
use serde::Deserialize;
use serde_yaml;
use std::collections::HashMap;
use std::string::String;

#[derive(Deserialize)]
pub struct Race {
    pub name: String,
    pub ability_score_modifiers: HashMap<AbilityScore, i32>,
    pub npc_ability_score_modifiers: HashMap<AbilityScore, i32>,
    pub ability_score_ranges: HashMap<AbilityScore, AbilityScoreRange>,
}

// TODO: Allow configuration of whether to use female ranges or not.
#[derive(Deserialize)]
pub struct AbilityScoreRange {
    pub male: [u8; 2],
    // pub female: [u8; 2], // TODO: Enable female ranges.
}

lazy_static! {
    pub static ref RACES: HashMap<String, Race> = load_races();
}

// TODO: Is this actually needed? Is there a real race condition this is avoiding?
fn load_races() -> HashMap<String, Race> {
    let yaml_data = include_str!("../data/rules/races.yaml");
    serde_yaml::from_str(yaml_data).expect("Failed to parse races YAML")
}