diff options
author | David Gay <eapoems@riseup.net> | 2024-01-22 02:15:14 -0500 |
---|---|---|
committer | David Gay <eapoems@riseup.net> | 2024-01-22 02:15:14 -0500 |
commit | 0e4ee1535c33febcd49ac8cb6bcd806ee0c5e58f (patch) | |
tree | a7857ae603d3f4738b792338fc760a4688d29d58 /src/rules | |
parent | 8346c147faf11d99af370d2bfaa6a982d570f8df (diff) |
Magic item struct and kind enum
Diffstat (limited to 'src/rules')
-rw-r--r-- | src/rules/magic_items.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/rules/magic_items.rs b/src/rules/magic_items.rs new file mode 100644 index 0000000..6806a60 --- /dev/null +++ b/src/rules/magic_items.rs @@ -0,0 +1,32 @@ +use lazy_static::lazy_static; +use serde::Deserialize; +use serde_yaml; +use std::collections::HashMap; +use std::string::String; + +#[derive(Deserialize)] +pub struct MagicItem { + pub name: String, + pub kind: MagicItemKind, +} + +#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Copy)] +pub enum MagicItemKind { + Potion, + Scroll, + Ring, + RodStaffWand, + Misc, + ArmorShield, + MiscWeapon, +} + +lazy_static! { + pub static ref MAGIC_ITEMS: HashMap<String, MagicItem> = load_magic_items(); +} + +// TODO: Is this actually needed? Is there a real race condition this is avoiding? +fn load_magic_items() -> HashMap<String, MagicItem> { + let yaml_data = include_str!("../data/rules/magic_items.yaml"); + serde_yaml::from_str(yaml_data).expect("Failed to parse magic items YAML") +} |