bevy_sequential_actions/
world.rs1use super::*;
2
3impl ActionsProxy for World {
4 fn actions(&mut self, agent: Entity) -> impl ModifyActions {
5 AgentActions {
6 agent,
7 config: AddConfig::default(),
8 world: self,
9 }
10 }
11}
12
13pub struct AgentActions<'w> {
15 agent: Entity,
16 config: AddConfig,
17 world: &'w mut World,
18}
19
20impl ModifyActions for AgentActions<'_> {
21 fn config(&mut self, config: AddConfig) -> &mut Self {
22 self.config = config;
23 self
24 }
25
26 fn start(&mut self, start: bool) -> &mut Self {
27 self.config.start = start;
28 self
29 }
30
31 fn order(&mut self, order: AddOrder) -> &mut Self {
32 self.config.order = order;
33 self
34 }
35
36 fn add(&mut self, actions: impl IntoBoxedActions) -> &mut Self {
37 let mut actions = actions.into_boxed_actions();
38 match actions.len() {
39 0 => {}
40 1 => {
41 SequentialActionsPlugin::add_action(
42 self.agent,
43 self.config,
44 actions.next().unwrap(),
45 self.world,
46 );
47 }
48 _ => {
49 SequentialActionsPlugin::add_actions(self.agent, self.config, actions, self.world);
50 }
51 }
52 self
53 }
54
55 fn execute(&mut self) -> &mut Self {
56 SequentialActionsPlugin::execute_actions(self.agent, self.world);
57 self
58 }
59
60 fn next(&mut self) -> &mut Self {
61 SequentialActionsPlugin::stop_current_action(self.agent, StopReason::Canceled, self.world);
62 SequentialActionsPlugin::start_next_action(self.agent, self.world);
63 self
64 }
65
66 fn cancel(&mut self) -> &mut Self {
67 SequentialActionsPlugin::stop_current_action(self.agent, StopReason::Canceled, self.world);
68 self
69 }
70
71 fn pause(&mut self) -> &mut Self {
72 SequentialActionsPlugin::stop_current_action(self.agent, StopReason::Paused, self.world);
73 self
74 }
75
76 fn skip(&mut self, n: usize) -> &mut Self {
77 SequentialActionsPlugin::skip_actions(self.agent, n, self.world);
78 self
79 }
80
81 fn clear(&mut self) -> &mut Self {
82 SequentialActionsPlugin::clear_actions(self.agent, self.world);
83 self
84 }
85}