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 | |
parent | 8346c147faf11d99af370d2bfaa6a982d570f8df (diff) |
Magic item struct and kind enum
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | src/data/rules/magic_items.yaml | 11 | ||||
-rw-r--r-- | src/rules.rs | 1 | ||||
-rw-r--r-- | src/rules/magic_items.rs | 32 |
4 files changed, 45 insertions, 1 deletions
@@ -106,7 +106,7 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" [[package]] name = "dmn" -version = "0.0.3" +version = "0.0.2" dependencies = [ "clap", "env_logger", diff --git a/src/data/rules/magic_items.yaml b/src/data/rules/magic_items.yaml new file mode 100644 index 0000000..c474cf0 --- /dev/null +++ b/src/data/rules/magic_items.yaml @@ -0,0 +1,11 @@ +sword_plus_one: + name: "Sword +1" + kind: sword + +ring_of_animal_friendship: + name: "Ring of Animal Friendship" + kind: ring + +rod_of_absorption: + name: "Rod of Absorption (C, M)" + kind: rod_staff_wand diff --git a/src/rules.rs b/src/rules.rs index 1807fc3..7d33038 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -1,4 +1,5 @@ pub mod ability_scores; pub mod classes; +pub mod magic_items; pub mod npcs; pub mod races; 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") +} |