From 1b3a7eb21e3fc4e9ebc0b6131011c064ec7fe95c Mon Sep 17 00:00:00 2001 From: David Gay Date: Wed, 28 Aug 2024 00:31:06 -0400 Subject: wip --- src/rules/magic_items.rs | 61 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/src/rules/magic_items.rs b/src/rules/magic_items.rs index d074b0b..aa38b69 100644 --- a/src/rules/magic_items.rs +++ b/src/rules/magic_items.rs @@ -4,30 +4,59 @@ use serde_yaml; use std::collections::HashMap; use std::string::String; -#[derive(Deserialize)] -pub struct MagicItem { - pub name: String, - pub kind: MagicItemKind, +trait MagicItem { + fn name(&self) -> &str; } -#[derive(Debug, Deserialize, Eq, Hash, PartialEq, Clone, Copy)] -pub enum MagicItemKind { - Sword, - Potion, - Scroll, - Ring, - RodStaffWand, - Misc, - ArmorShield, - MiscWeapon, +struct Sword { + name: String, } +struct Potion { + name: String, +} + +struct Scroll { + name: String, +} + +struct Ring { + name: String, +} + +struct RodStaffWand { + name: String, +} + +struct Misc { + name: String, +} + +struct ArmorShield { + name: String, +} + +struct MiscWeapon { + name: String, +} + +impl MagicItem for Sword {} +impl MagicItem for Potion {} +impl MagicItem for Scroll {} +impl MagicItem for Ring {} +impl MagicItem for RodStaffWand {} +impl MagicItem for Misc {} +impl MagicItem for ArmorShield {} +impl MagicItem for MiscWeapon {} + lazy_static! { - pub static ref MAGIC_ITEMS: HashMap = load_magic_items(); + 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 { +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") + + items } -- cgit v1.2.3