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
use amethyst::ecs::World;
use super::{BoxedGameEvent, ExecutionConditions, GameEvent};
pub struct CyclicEvent {
prototype: BoxedGameEvent,
event: BoxedGameEvent,
called_start: bool,
}
impl CyclicEvent {
pub fn new(event: BoxedGameEvent) -> CyclicEvent {
CyclicEvent {
prototype: event.boxed_clone(),
event,
called_start: false,
}
}
}
impl Clone for CyclicEvent {
fn clone(&self) -> CyclicEvent {
CyclicEvent {
prototype: self.prototype.boxed_clone(),
event: self.event.boxed_clone(),
called_start: self.called_start,
}
}
}
impl GameEvent for CyclicEvent {
fn boxed_clone(&self) -> BoxedGameEvent {
Box::new(self.clone())
}
fn get_execution_conditions(&self) -> ExecutionConditions {
self.event.get_execution_conditions()
}
fn start(&mut self, world: &mut World) {
self.event.start(world);
self.called_start = true;
}
fn tick(&mut self, world: &mut World, disabled_inputs: bool) {
if !self.called_start {
self.event.start(world);
self.called_start = true;
}
self.event.tick(world, disabled_inputs);
if self.event.is_complete(world) {
self.event = self.prototype.boxed_clone();
self.called_start = false;
}
}
fn is_complete(&self, _world: &mut World) -> bool {
false
}
}