Expand description
pyri_state
is a bevy_state
alternative offering flexible change detection & scheduling.
NOTE: This crate is incompatible with the bevy/bevy_state
feature, so make sure it’s
disabled.
§Overview
- The current state is a
Resource
orComponent
that implementsState
. - The next state is stored in a
NextStateBuffer
resource by default. - A state flush is triggered by the
TriggerStateFlush
resource and handled in theStateFlush
schedule. - State flush hooks are organized into
ResolveStateSystems
system sets. - Tools are provided for state setup, access, pattern-matching, debugging, and more.
§Getting started
Import the prelude to bring traits and common types into scope:
use pyri_state::prelude::*;
Define your own State
type using the
derive macro:
#[derive(State, Clone, PartialEq, Eq, Default)]
struct Level(pub usize);
Add StatePlugin
and initialize your state type:
app.add_plugins(StatePlugin).init_state::<Level>();
Add update systems with StatePattern::on_update
:
app.add_systems(Update, (
Level::ANY.on_update(update_level_timer),
Level(10).on_update(update_boss_health_bar),
state!(Level(4..=6)).on_update(spawn_enemy_waves),
));
Add flush hooks with other StatePattern
methods:
app.add_systems(StateFlush, (
// Short-hand for `on_exit` followed by `on_enter`.
Level::ANY.on_edge(despawn_old_level, spawn_new_level),
Level(10).on_enter(play_boss_music),
state!(Level(4 | 7 | 10)).on_enter(save_checkpoint),
Level::with(|x| x.0 < 4).on_enter(spawn_tutorial_popup),
));
Modules§
- access
- System parameters to access current and next states.
- debug
- State debugging tools.
- extra
- Extra tools behind feature flags.
- next_
state NextState
trait, extension traits and types.- pattern
- State pattern-matching tools.
- prelude
- Re-exported traits and common types.
- schedule
- State flush scheduling types and functions.
- setup
- State setup and configuration tools.
- state
State
trait and extension traits.
Macros§
- add_
to_ split_ state - A macro for extending
SplitState
newtypes. - state
- A macro for building pattern-matching
FnStatePattern
andFnStateTransPattern
instances.