From 5d1efac842657a49ac28be97adf3590d19b8386e Mon Sep 17 00:00:00 2001 From: David Gay Date: Sun, 15 Oct 2023 00:42:39 -0400 Subject: Races struct and data --- src/data/rules/races.yaml | 50 +++++++++++++++++++++++++++++++++++++++++++++++ src/rules.rs | 1 + src/rules/races.rs | 23 ++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100644 src/data/rules/races.yaml create mode 100644 src/rules/races.rs diff --git a/src/data/rules/races.yaml b/src/data/rules/races.yaml new file mode 100644 index 0000000..96e0142 --- /dev/null +++ b/src/data/rules/races.yaml @@ -0,0 +1,50 @@ +dwarf: + name: "Dwarf" + ability_score_modifiers: + Constitution: +1 + Charisma: -1 + npc_ability_score_modifiers: + Strength: +1 + Constitution: +1 + Charisma: -1 + +elf: + name: "Elf" + ability_score_modifiers: + Dexterity: +1 + Constitution: -1 + npc_ability_score_modifiers: + Intelligence: +1 + Dexterity: +1 + +gnome: + name: "Gnome" + npc_ability_score_modifiers: + Wisdom: +1 + Constitution: +1 + Charisma: -1 + +half-elf: + name: "Half-elf" + +halfling: + name: "Halfling" + ability_score_modifiers: + Strength: -1 + Dexterity: +1 + npc_ability_score_modifiers: + Dexterity: +1 + Constitution: +1 + +half-orc: + name: "Half-orc" + ability_score_modifiers: + Strength: +1 + Constitution: +1 + Charisma: -1 + npc_ability_score_modifiers: + Dexterity: +1 + Constitution: +1 + +human: + name: "Human" diff --git a/src/rules.rs b/src/rules.rs index 68f12f7..1807fc3 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -1,3 +1,4 @@ pub mod ability_scores; pub mod classes; pub mod npcs; +pub mod races; diff --git a/src/rules/races.rs b/src/rules/races.rs new file mode 100644 index 0000000..700c7ea --- /dev/null +++ b/src/rules/races.rs @@ -0,0 +1,23 @@ +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, + pub npc_ability_score_modifiers: HashMap, +} + +lazy_static! { + pub static ref RACES: HashMap = load_races(); +} + +// TODO: Is this actually needed? Is there a real race condition this is avoiding? +fn load_races() -> HashMap { + let yaml_data = include_str!("../data/rules/races.yaml"); + serde_yaml::from_str(yaml_data).expect("Failed to parse races YAML") +} -- cgit v1.2.3