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
use std::cell::RefCell;
use crate::engine::d2::Entity;
use super::Action;
struct FirstOfProps {
running_actions: Vec<Box<dyn Action>>,
}
pub struct FirstOf {
props: RefCell<FirstOfProps>,
}
impl FirstOf {
pub fn new<A: Action>(actions: Option<Vec<Box<dyn Action>>>) -> Self {
Self {
props: RefCell::new(FirstOfProps {
running_actions: actions.unwrap_or_default(),
}),
}
}
pub fn add(&self, action: Box<dyn Action>) {
let mut props = self.props.borrow_mut();
props.running_actions.push(action);
}
pub fn remove_all(&self) {
let mut props = self.props.borrow_mut();
props.running_actions.clear();
}
}
impl Action for FirstOf {
fn update(&self, dt: f32, actor: &mut Entity) -> f32 {
let mut props = self.props.borrow_mut();
for action in props.running_actions.iter_mut() {
let spent = action.update(dt, actor);
if spent >= 0.0 {
return spent;
}
}
-1.0
}
}