blob: aa38b69544ab7ff29959387910fdfa2e30e23eb6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
use lazy_static::lazy_static;
use serde::Deserialize;
use serde_yaml;
use std::collections::HashMap;
use std::string::String;
trait MagicItem {
fn name(&self) -> &str;
}
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, 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, 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
}
|