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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use crate::{StatCondition, UseMode};
use std::collections::HashMap;
use std::hash::Hash;
#[derive(Debug, Clone, Serialize, Deserialize, new, Builder)]
pub struct Unlockable<U, K, S, I> {
pub id: U,
pub inner: K,
pub is_unlocked: bool,
#[new(default)]
pub unlock_stat_conditions: Vec<StatCondition<S>>,
#[new(default)]
pub unlock_item_conditions: Vec<(I, usize, UseMode)>,
#[new(default)]
pub unlock_dependencies: Vec<U>,
}
impl<U, K, S, I> Unlockable<U, K, S, I> {
pub fn try_get(&self) -> Option<&K> {
if self.is_unlocked {
Some(&self.inner)
} else {
None
}
}
pub fn try_get_mut(&mut self) -> Option<&mut K> {
if self.is_unlocked {
Some(&mut self.inner)
} else {
None
}
}
pub fn get(&self) -> &K {
&self.inner
}
pub fn get_mut(&mut self) -> &mut K {
&mut self.inner
}
pub fn set(&mut self, new: K) {
self.inner = new;
}
pub fn lock(&mut self) {
self.is_unlocked = true;
}
pub fn unlock(&mut self) {
self.is_unlocked = false;
}
pub fn is_unlocked(&self) -> bool {
self.is_unlocked
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize, new)]
pub struct Unlockables<U: Hash + Eq, K, S, I> {
pub unlockables: HashMap<U, Unlockable<U, K, S, I>>,
}