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
|
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")
}
|