use bevy::prelude::*;
use bevy_sequential_actions::*;
use shared::{CountdownAction, PrintAction, SharedActionsPlugin};
fn main() {
App::new()
.add_plugins((MinimalPlugins, SequentialActionsPlugin, SharedActionsPlugin))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
let agent = commands.spawn(SequentialActions).id();
commands
.actions(agent)
.add(DemoAction)
.add((
PrintAction::new("hello"),
PrintAction::new("there"),
CountdownAction::new(5),
))
.add(actions![
PrintAction::new("it is possible to commit no mistakes and still lose"),
PrintAction::new("that is not a weakness"),
PrintAction::new("that is life"),
CountdownAction::new(10),
])
.add(|_agent, world: &mut World| -> bool {
world.write_message(AppExit::Success);
true
});
}
struct DemoAction;
impl Action for DemoAction {
fn is_finished(&self, _agent: Entity, _world: &World) -> bool {
println!("is_finished: called every frame in the Last schedule");
true
}
fn on_start(&mut self, _agent: Entity, _world: &mut World) -> bool {
println!("on_start: called when an action is started");
false
}
fn on_stop(&mut self, _agent: Option<Entity>, _world: &mut World, _reason: StopReason) {
println!("on_stop: called when an action is stopped");
}
fn on_add(&mut self, _agent: Entity, _world: &mut World) {
println!("on_add: called when an action is added to the queue");
}
fn on_remove(&mut self, _agent: Option<Entity>, _world: &mut World) {
println!("on_remove: called when an action is removed from the queue");
}
fn on_drop(self: Box<Self>, _agent: Option<Entity>, _world: &mut World, _reason: DropReason) {
println!("on_drop: the last method to be called with full ownership");
}
}