pub struct SequentialActionsPlugin;
Expand description
The Plugin
for this library that you can add to your App
.
This plugin adds the check_actions
system to the Last
schedule
for action queue advancement, and also two hooks
for cleaning up actions from despawned agents.
Finally, it also contains various static methods for modifying the action queue.
Implementations§
Source§impl SequentialActionsPlugin
impl SequentialActionsPlugin
Sourcepub fn check_actions<F: QueryFilter>(
action_q: Query<'_, '_, (Entity, &CurrentAction), F>,
world: &World,
commands: Commands<'_, '_>,
)
pub fn check_actions<F: QueryFilter>( action_q: Query<'_, '_, (Entity, &CurrentAction), F>, world: &World, commands: Commands<'_, '_>, )
The System
used by SequentialActionsPlugin
.
It is responsible for checking all agents for finished actions
and advancing the action queue.
The query filter F
is used for filtering agents.
Use the unit type ()
for no filtering.
§Example
App::new()
.add_systems(Last, SequentialActionsPlugin::check_actions::<()>)
.run();
Sourcepub fn add_action(
agent: Entity,
config: AddConfig,
action: impl IntoBoxedAction,
world: &mut World,
)
pub fn add_action( agent: Entity, config: AddConfig, action: impl IntoBoxedAction, world: &mut World, )
Adds a single action
to agent
with specified config
.
Sourcepub fn add_actions<I>(
agent: Entity,
config: AddConfig,
actions: I,
world: &mut World,
)
pub fn add_actions<I>( agent: Entity, config: AddConfig, actions: I, world: &mut World, )
Adds a collection of actions to agent
with specified config
.
An empty collection does nothing.
Sourcepub fn execute_actions(agent: Entity, world: &mut World)
pub fn execute_actions(agent: Entity, world: &mut World)
Sourcepub fn stop_current_action(agent: Entity, reason: StopReason, world: &mut World)
pub fn stop_current_action(agent: Entity, reason: StopReason, world: &mut World)
Examples found in repository?
145 fn check_actions_exclusive(
146 world: &mut World,
147 mut finished: Local<Vec<Entity>>,
148 mut agent_q: Local<QueryState<(Entity, &CurrentAction), F>>,
149 ) {
150 // Collect all agents with finished action
151 finished.extend(agent_q.iter(world).filter_map(|(agent, current_action)| {
152 current_action
153 .as_ref()
154 .and_then(|action| action.is_finished(agent, world).then_some(agent))
155 }));
156
157 // Do something with the finished list if you want.
158 // Perhaps sort by some identifier for deterministic behavior.
159
160 // Advance the action queue
161 for agent in finished.drain(..) {
162 SequentialActionsPlugin::stop_current_action(agent, StopReason::Finished, world);
163 SequentialActionsPlugin::start_next_action(agent, world);
164 }
165 }
Sourcepub fn start_next_action(agent: Entity, world: &mut World)
pub fn start_next_action(agent: Entity, world: &mut World)
Starts
the next action
in the queue for agent
.
This will loop until any next action is not immediately finished or the queue is empty. Since this may trigger an infinite loop, a counter is used in debug build that panics when reaching a sufficient target.
The loop will also break if agent
already has a current action.
This is likely a user error, and so a warning will be emitted.
Examples found in repository?
145 fn check_actions_exclusive(
146 world: &mut World,
147 mut finished: Local<Vec<Entity>>,
148 mut agent_q: Local<QueryState<(Entity, &CurrentAction), F>>,
149 ) {
150 // Collect all agents with finished action
151 finished.extend(agent_q.iter(world).filter_map(|(agent, current_action)| {
152 current_action
153 .as_ref()
154 .and_then(|action| action.is_finished(agent, world).then_some(agent))
155 }));
156
157 // Do something with the finished list if you want.
158 // Perhaps sort by some identifier for deterministic behavior.
159
160 // Advance the action queue
161 for agent in finished.drain(..) {
162 SequentialActionsPlugin::stop_current_action(agent, StopReason::Finished, world);
163 SequentialActionsPlugin::start_next_action(agent, world);
164 }
165 }
Sourcepub fn skip_actions(agent: Entity, n: usize, world: &mut World)
pub fn skip_actions(agent: Entity, n: usize, world: &mut World)
Skips the next n
actions in the queue for agent
.
Trait Implementations§
Source§impl Plugin for SequentialActionsPlugin
impl Plugin for SequentialActionsPlugin
Source§fn ready(&self, _app: &App) -> bool
fn ready(&self, _app: &App) -> bool
finish
should be called.Source§fn finish(&self, _app: &mut App)
fn finish(&self, _app: &mut App)
App
, once all plugins registered are ready. This can
be useful for plugins that depends on another plugin asynchronous setup, like the renderer.Source§fn cleanup(&self, _app: &mut App)
fn cleanup(&self, _app: &mut App)
Auto Trait Implementations§
impl Freeze for SequentialActionsPlugin
impl RefUnwindSafe for SequentialActionsPlugin
impl Send for SequentialActionsPlugin
impl Sync for SequentialActionsPlugin
impl Unpin for SequentialActionsPlugin
impl UnwindSafe for SequentialActionsPlugin
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.