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
use crate::*;
pub trait Action: Send + Sync + 'static {
fn on_start(&mut self, agent: Entity, world: &mut World, commands: &mut ActionCommands);
fn on_stop(&mut self, agent: Entity, world: &mut World, reason: StopReason);
}
impl<Start> Action for Start
where
Start: FnMut(Entity, &mut World, &mut ActionCommands) + Send + Sync + 'static,
{
fn on_start(&mut self, agent: Entity, world: &mut World, commands: &mut ActionCommands) {
(self)(agent, world, commands);
}
fn on_stop(&mut self, _agent: Entity, _world: &mut World, _reason: StopReason) {}
}
impl<Start, Stop> Action for (Start, Stop)
where
Start: FnMut(Entity, &mut World, &mut ActionCommands) + Send + Sync + 'static,
Stop: FnMut(Entity, &mut World, StopReason) + Send + Sync + 'static,
{
fn on_start(&mut self, agent: Entity, world: &mut World, commands: &mut ActionCommands) {
(self.0)(agent, world, commands);
}
fn on_stop(&mut self, agent: Entity, world: &mut World, reason: StopReason) {
(self.1)(agent, world, reason);
}
}
pub trait IntoBoxedAction: Send + Sync + 'static {
fn into_boxed(self) -> BoxedAction;
}
impl<T> IntoBoxedAction for T
where
T: Action,
{
fn into_boxed(self) -> BoxedAction {
Box::new(self)
}
}
impl IntoBoxedAction for BoxedAction {
fn into_boxed(self) -> BoxedAction {
self
}
}
pub trait BoxedActionIter: DoubleEndedIterator<Item = BoxedAction> + Send + Sync + 'static {}
impl<T> BoxedActionIter for T where
T: DoubleEndedIterator<Item = BoxedAction> + Send + Sync + 'static
{
}
pub trait ActionsProxy<'a> {
type Modifier: ModifyActions;
fn actions(&'a mut self, agent: Entity) -> Self::Modifier;
}
pub trait ModifyActions {
fn config(&mut self, config: AddConfig) -> &mut Self;
fn add(&mut self, action: impl IntoBoxedAction) -> &mut Self;
fn add_many(&mut self, mode: ExecutionMode, actions: impl BoxedActionIter) -> &mut Self;
fn next(&mut self) -> &mut Self;
fn cancel(&mut self) -> &mut Self;
fn pause(&mut self) -> &mut Self;
fn skip(&mut self) -> &mut Self;
fn clear(&mut self) -> &mut Self;
}