summaryrefslogtreecommitdiff
path: root/src/rules/magic_items.rs
diff options
context:
space:
mode:
authorDavid Gay <eapoems@riseup.net>2024-08-28 00:31:06 -0400
committerDavid Gay <eapoems@riseup.net>2024-08-28 00:31:06 -0400
commit1b3a7eb21e3fc4e9ebc0b6131011c064ec7fe95c (patch)
tree3adb32dc17867924036765097a33b9b14dcba1b5 /src/rules/magic_items.rs
parente63dbbde68f81f8a65b48608d41ef6bf6be799e6 (diff)
wipwip
Diffstat (limited to 'src/rules/magic_items.rs')
-rw-r--r--src/rules/magic_items.rs61
1 files 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<String, MagicItem> = load_magic_items();
+ pub static ref MAGIC_ITEMS: HashMap<String, Box<dyn 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> {
+fn load_magic_items() -> HashMap<String, Box<dyn MagicItem>> {
let yaml_data = include_str!("../data/rules/magic_items.yaml");
serde_yaml::from_str(yaml_data).expect("Failed to parse magic items YAML")
+
+ items
}