From 0e4ee1535c33febcd49ac8cb6bcd806ee0c5e58f Mon Sep 17 00:00:00 2001 From: David Gay Date: Mon, 22 Jan 2024 02:15:14 -0500 Subject: Magic item struct and kind enum --- Cargo.lock | 2 +- src/data/rules/magic_items.yaml | 11 +++++++++++ src/rules.rs | 1 + src/rules/magic_items.rs | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/data/rules/magic_items.yaml create mode 100644 src/rules/magic_items.rs diff --git a/Cargo.lock b/Cargo.lock index 739244d..1b2e3d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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 = load_magic_items(); +} + +// TODO: Is this actually needed? Is there a real race condition this is avoiding? +fn load_magic_items() -> HashMap { + let yaml_data = include_str!("../data/rules/magic_items.yaml"); + serde_yaml::from_str(yaml_data).expect("Failed to parse magic items YAML") +} -- cgit v1.2.3