bevy_sequential_actions is a library for the Bevy game engine that aims to execute a list of actions in a sequential manner.

Overview

Bevy Sequential Actions

bevy_sequential_actions is a library for the Bevy game engine that aims to execute a list of actions in a sequential manner. This generally means that one action runs at a time, and when it is done, the next action will start, and so on until the list is empty.

Getting Started

An action is anything that implements the Action trait, and can be added to any Entity that contains the ActionsBundle. Each action must signal when they are finished, which is done by calling next_action on either Commands or ActionCommands.

use bevy::prelude::*;

use bevy_sequential_actions::*;

fn main() {
    App::new()
        .add_plugins(MinimalPlugins)
        .add_startup_system(setup)
        .add_system(wait)
        .run();
}

fn setup(mut commands: Commands) {
    // Create entity with ActionsBundle
    let id = commands.spawn_bundle(ActionsBundle::default()).id();

    // Add a single action with default config
    commands.add_action(id, WaitAction(1.0), AddConfig::default());

    // Add multiple actions with custom config
    commands
        .action_builder(
            id,
            AddConfig {
                // Add each action to the back of the queue
                order: AddOrder::Back,
                // Start action if nothing is currently running
                start: false,
                // Repeat the action         
                repeat: false,
            },
        )
        .push(WaitAction(2.0))
        .push(WaitAction(3.0))
        .submit();
}

struct WaitAction(f32);

impl Action for WaitAction {
    fn add(&mut self, actor: Entity, world: &mut World, _commands: &mut ActionCommands) {
        world.entity_mut(actor).insert(Wait(self.0));
    }

    fn remove(&mut self, actor: Entity, world: &mut World) {
        world.entity_mut(actor).remove::();
    }

    fn stop(&mut self, actor: Entity, world: &mut World) {
        self.remove(actor, world);
    }
}

#[derive(Component)]
struct Wait(f32);

fn wait(mut wait_q: Query<(Entity, &mut Wait)>, time: Res

Examples

See the examples for more usage. Each example can be run with cargo run --example .

Example Description
basic Shows the basic usage of the library by adding a bunch of actions.
stop Shows how to stop a running action, and then add a new action to the front of the queue.
repeat Shows how to add actions that basically loop forever in the added order.
demo A more comprehensive and practical example showcasing how this library can be used in a turn-based board game. Includes lots of custom actions that can be reused throughout the game.

Compatibility

bevy bevy_sequential_actions
0.7 0.1
You might also like...
Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions
Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions

Introduction Proof-of-concept of getting OpenXR rendering support for Bevy game engine using gfx-rs abstractions. (hand interaction with boxes missing

A physics lib for the bevy game engine based on physme

physimple Physimple aims to be the simplest(and capable) physics engine(currently for bevy) WARNING Beware for breaking changes with each update for n

An immediate mode 2D drawing API for Bevy game engine

Bevy Canvas API prototype An unofficial immediate mode 2D drawing API for Bevy game engine. Check the documentation or the examples to know how to use

Simple RUST game with the Bevy Engine

Simple RUST Game using the Bevy Engine YouTube videos for this code base: Episode 1 - Rust Game Development tutorial from Scratch with Bevy Engine Epi

A vdom-free reactive UI lib for the bevy game engine

ui4 ui4 is my fourth major attempt at making a UI dataflow library for the Bevy game engine. More specifically, it's a vdom-less UI library which uses

Hanabi — a particle system plugin for the Bevy game engine.

Hanabi — a particle system plugin for the Bevy game engine

Brine is my attempt at writing a Minecraft client in Rust using the Bevy game engine.
Brine is my attempt at writing a Minecraft client in Rust using the Bevy game engine.

Brine Brine is my attempt at writing a Minecraft client in Rust using the Bevy game engine. It's EXTREMELY work-in-progress. The thing that makes Brin

Bevy is a refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Utilities for creating strictly ordered execution graphs of systems for the Bevy game engine

bevy_system_graph This crate provides the utilities for creating strictly ordered execution graphs of systems for the Bevy game engine. Bevy Version S

Comments
  • Add parallel actions

    Add parallel actions

    This PR adds the ability to add a collection of actions that is treated as "one". This means that they all start and stop at the same time, and the actions queue will only advance when all actions are finished within the same frame.

    commands
        .actions(agent)
        .add_many(
            ExecutionMode::Parallel,
            [
                action_d.into_boxed(),
                action_e.into_boxed(),
                action_f.into_boxed(),
            ].into_iter()
        );
    

    For this to work, this library now requires that you add the SequentialActionsPlugin to your app, as a system at the end of the frame now needs to check for all finished actions.

    This PR also includes some internal rework and other stuff. The finish method has been removed in favor of using the new ActionFinished component on an agent. This approach composes well with other actions running in parallel. For short one-at-a-time actions the next method can still be used. The README file has been updated with examples.

    opened by hikikones 0
  • Replace repeat bool with a `Repeat` enum

    Replace repeat bool with a `Repeat` enum

    You can now specify how many times an action should repeat.

    pub enum Repeat {
        Amount(u32),
        Forever,
    }
    

    A value of Repeat::Amount(0) means it will repeat zero times, i.e. only run once as before when the repeat bool was set to false.

    opened by hikikones 0
  • Add an anonymous action using a closure

    Add an anonymous action using a closure

    commands
            .actions(actor)
            // Single closure for only the on_start method
            .add(
                |entity, _world: &mut World, commands: &mut ActionCommands| {
                    // on_start
                    commands.actions(entity).finish();
                },
            )
            // Tuple closure for both the on_start and on_stop methods
            .add((
                |entity, _world: &mut World, commands: &mut ActionCommands| {
                    // on_start
                    commands.actions(entity).finish();
                },
                |_entity, _world: &mut World, _reason| {
                    // on_stop
                },
            ));
    
    opened by hikikones 0
Releases(v0.6.0)
  • v0.6.0(Nov 15, 2022)

    Changes:

    • Update to Bevy 0.9. (#55)
    • Add a collection of actions that run in parallel with the add_many method. The collection is treated as "one action", meaning that they all start and stop at the same time, and the action queue will only advance when all actions are finished within the same frame. For this to work, this library now requires that you add the SequentialActionsPlugin to your app, as a set of systems at the end of the frame now needs to check for all finished actions. The finish method has been removed, as declaring an action as finished is now done with the ActionFinished component on an agent. The explicit stop(reason) method has also been removed. (#45)
    • Add SequentialActionsPlugin::get_systems if you want to schedule the systems yourself. (#53)
    • Add actions! helper macro for creating a collection of boxed actions. (#47)
    • Add Repeat::None variant. (#50)
    • Add ActionsBundle::new method. (#52)
    • Rename ActionCommands::custom method to add. (#48)
    • Remove ActionMarker component. (#49)
    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Sep 8, 2022)

    Changes:

    • Replace builder constructs for adding a list of actions with a simple add_many method that takes an iterator of boxed actions. Reversing the list before adding to the front is no longer needed. (#40)
    • Replace the repeat bool in AddConfig with a Repeat enum. You can now specify how many times an action should be repeated before it is permanently removed from the queue. A value of zero means that it will only run once. (#41)
    Source code(tar.gz)
    Source code(zip)
  • v0.4.0(Aug 19, 2022)

    Changes:

    • Building a list of actions is now done through the builder method when modifying actions. (#28)
    • Add skip method for skipping the next action. (#30)
    • Add ActionMarker component to ActionsBundle. (#31)
    • Add an anonymous action using a closure. (#34)
    • Add custom method to ActionCommands for deferred World mutation after Action::on_start has been called. Used for modifying actions using World inside the Action trait. (#36)
    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Jul 30, 2022)

    Changes:

    • Update to Bevy 0.8.
    • Remove the Action::remove trait method.
    • Rename Action::start method to Action::on_start.
    • Rename Action::stop method to Action::on_stop.
    • Add StopReason enum and use it as parameter in Action::on_stop method.
    • Rename action(entity) method to actions(entity) for modifying actions.
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(May 12, 2022)

  • v0.1.0(Apr 28, 2022)

Owner
hikikones
hikikones
Bevy Simple Portals is a Bevy game engine plugin aimed to create portals.

Portals for Bevy Bevy Simple Portals is a Bevy game engine plugin aimed to create portals. Those portals are (for now) purely visual and can be used t

Sélène Amanita 11 May 28, 2023
2d Endless Runner Game made with Bevy Game Engine

Cute-runner A 2d Endless Runner Game made with Bevy Game Engine. Table of contents Project Infos Usage Screenshots Disclaimer Project Infos Date: Sept

JoaoMarinho 2 Jul 15, 2022
A game of snake written in Rust using the Bevy game engine, targeting WebGL2

Snake using the Bevy Game Engine Prerequisites cargo install cargo-make Build and serve WASM version Set your local ip address in Makefile.toml (loca

Michael Dorst 0 Dec 26, 2021
A game made in one week for the Bevy engine's first game jam

¿Quien es el MechaBurro? An entry for the first Bevy game jam following the theme of "Unfair Advantage." It was made in one week using the wonderful B

mike 20 Dec 23, 2022
A Client/Server game networking plugin using QUIC, for the Bevy game engine.

Bevy Quinnet A Client/Server game networking plugin using QUIC, for the Bevy game engine. Bevy Quinnet QUIC as a game networking protocol Features Roa

Gilles Henaux 65 Feb 20, 2023
Plotting library for the Bevy game engine with a focus on esthetics and interactivity

Plotting library for the Bevy game engine with a focus on esthetics and interactivity. It can handle both data points (see the "minimal", "markers", a

Eli 40 Dec 25, 2022
Basic first-person fly camera for the Bevy game engine

bevy_flycam A basic first-person fly camera for Bevy 0.4 Controls WASD to move horizontally SPACE to ascend LSHIFT to descend ESC to grab/release curs

Spencer Burris 85 Dec 23, 2022
Inspector plugin for the bevy game engine

bevy-inspector-egui This crate provides the ability to annotate structs with a #[derive(Inspectable)], which opens a debug interface using egui where

Jakob Hellermann 517 Dec 31, 2022
Crossterm plugin for the bevy game engine

What is bevy_crossterm? bevy_crossterm is a Bevy plugin that uses crossterm as a renderer. It provides custom components and events which allow users

null 79 Nov 2, 2022
Concise Reference Book for the Bevy Game Engine

Unofficial Bevy Cheat Book Click here to read the book! Concise reference to programming in the Bevy game engine. Covers useful syntax, features, prog

null 947 Jan 8, 2023