bevy-undo2

This crate makes it easy to use the undo-operation on bevy.

License: MIT/Apache

Crate

Examples

examples/simple.rs

```rust

use bevy::prelude::; use bevy_undo2::prelude::;

[derive(Event, Clone)]

struct GreetEvent(String);

fn main() { App::new() .addplugins(DefaultPlugins) .addplugins(UndoPlugin) .addsystems(Startup, setup) .addsystems(Update, (keyboardinputsystem, readundoeventsystem)) .addundo_event::() .run(); }

fn setup( mut commands: Commands, mut scheduler: UndoScheduler, asset: Res ) { commands.spawn(Camera2dBundle::default()); commands.spawn(Text2dBundle{ text: Text::fromsection("Please Press [R]", TextStyle{ font: asset.load("fonts/FiraSans-Bold.ttf"), fontsize: 31., ..default() }), ..default() }); scheduler.register(GreetEvent("Undo!".to_string())); }

fn keyboardinputsystem( mut requester: UndoRequester, key: Res>, ) { if key.pressed(KeyCode::R) { requester.undo(); } }

fn readundoeventsystem( mut er: EventReader, mut text: Query<&mut Text> ) { for GreetEvent(message) in er.iter() { text.singlemut().sections[0].value = message.clone(); } } ```

examples/callback.rs

```rust use bevy::prelude::; use bevy_undo2::prelude::;

fn main() { App::new() .addplugins(DefaultPlugins) .addplugins(UndoPlugin) .addsystems(Startup, setup) .addsystems(Update, keyboardinputsystem) .run(); }

fn setup( mut commands: Commands, mut scheduler: UndoCallbackScheduler, asset: Res, ) { commands.spawn(Camera2dBundle::default()); let text = commands .spawn(Text2dBundle { text: Text::fromsection("Please Press [R]: Delete text", TextStyle { font: asset.load("fonts/FiraSans-Bold.ttf"), fontsize: 31., ..default() }), ..default() }) .id();

scheduler.register(move |cmd| {
    cmd.entity(text).despawn();
});

}

fn keyboardinputsystem( mut requester: UndoRequester, key: Res>, ) { if key.pressed(KeyCode::R) { requester.undo(); } } ```

Compatible Bevy versions

| this crate | bevy | |------------|--------| | 0.0.1 | 0.11.0 |