bevy_state_stack

Crates.iobevy_state_stack
lib.rsbevy_state_stack
version0.2.1
sourcesrc
created_at2022-09-06 15:01:13.871085
updated_at2022-09-15 13:10:41.562035
descriptionAn improved state stack for bevy.
homepage
repositoryhttps://gitlab.com/martintrumann/bevy_state_stack
max_upload_size
id659573
size13,384
Martin Trumann (martintrumann)

documentation

README

Bevy state stack

This crate allows you to use a state stack that is not confined to a single stage.

Bevy version

bevy version bevy_state_stack version
0.8 0.1, 0.2

Usage

You're better off importing the entire library.

use bevy_state_stack::*;

Add the state enum into the app.

app.add_state_stack(AppState::Menu)

Add different systems to the app.

app.add_system_on_enter(AppState::Menu, setup_menu)
	.add_system_on_exit(AppState::Menu, despawn::<Menu>)
	.add_system_on_enter(AppState::Map, setup_map)
	.add_system_on_update(AppState::Map, pause)
	.add_system_on_update(AppState::Encounter, pause)
	.add_system_set_on_update(
		AppState::Menu,
		SystemSet::new()
			.with_system(resume)
			.with_system(start_game),
	)

You can set, push, or pop the state on top of the stack by inserting the Stack resource.

fn start_game(mut c: Commands) {
	c.insert_resource(Stack::Set(AppState::Map))
}

fn pause(mut c: Commands) {
	c.insert_resource(Stack::Push(AppState::Menu))
}

fn resume(mut c: Commands) {
	c.insert_resource(Stack::<AppState>::Pop);
}
Commit count: 10

cargo fmt