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
use std::cell::RefCell;
use crate::engine::d2::Entity;
use super::Action;
struct RepeatProps {
action: Box<dyn Action>,
count: i32,
remaining: i32,
}
pub struct Repeat {
props: RefCell<RepeatProps>,
}
impl Repeat {
pub fn new(action: Box<dyn Action>, count: i32) -> Self {
Self {
props: RefCell::new(RepeatProps {
action,
count,
remaining: count,
}),
}
}
}
impl Action for Repeat {
fn update(&self, dt: f32, actor: &mut Entity) -> f32 {
let mut props = self.props.borrow_mut();
if props.count == 0 {
return 0.0;
}
let spent = props.action.update(dt, actor);
props.remaining -= 1;
if props.count > 0 && spent >= 0.0 && props.remaining == 0 {
props.remaining = props.count;
return spent;
}
-1.0
}
}