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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::*;
use std::collections::HashMap;
use std::hash::Hash;
#[derive(new, Clone, Serialize, Deserialize, Debug, Builder)]
pub struct ItemTransitionDefinition<K, I, E, S> {
pub key: K,
pub name: String,
pub friendly_name: String,
pub icon_path: Option<String>,
pub input_items: Vec<(I, usize, UseMode)>,
pub stat_conditions: Vec<StatCondition<S>>,
pub stat_effectors: Vec<E>,
pub output_items: Vec<(I, usize)>,
pub on_condition_lost: ConditionLostReaction,
pub time_to_complete: f64,
pub consume_input_immediate: bool,
pub auto_trigger: bool,
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub enum UseMode {
Consume,
UseOnce {
durability: f64,
},
UsePerSecond {
rate: f64,
},
}
#[derive(Clone, Serialize, Deserialize, Debug)]
pub enum ConditionLostReaction {
None,
Pause,
Cancel,
}
#[derive(new, Clone, Serialize, Deserialize, Debug)]
pub struct ItemTransitionBatch<K> {
transition: K,
remaining: u32,
next_completion_remaining: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize, new)]
pub struct ItemTransitionDefinitions<K: Hash + Eq, I, E, S> {
pub defs: HashMap<K, ItemTransitionDefinition<K, I, E, S>>,
}
impl<K: Hash + Eq, I, E, S> Default for ItemTransitionDefinitions<K, I, E, S> {
fn default() -> Self {
Self {
defs: HashMap::default(),
}
}
}
impl<K: Hash + Eq + Clone, I, E, S> From<Vec<ItemTransitionDefinition<K, I, E, S>>>
for ItemTransitionDefinitions<K, I, E, S>
{
fn from(t: Vec<ItemTransitionDefinition<K, I, E, S>>) -> Self {
let defs = t
.into_iter()
.map(|s| (s.key.clone(), s))
.collect::<HashMap<_, _>>();
Self::new(defs)
}
}