diff --git a/tetris/src/debug.rs b/tetris/src/debug.rs index 11a961c..3d6fc4f 100644 --- a/tetris/src/debug.rs +++ b/tetris/src/debug.rs @@ -12,11 +12,16 @@ pub struct DebugPlugin; // - Show current state(s) impl Plugin for DebugPlugin { fn build(&self, app: &mut App) { - app.add_systems(Update, ( - log_transition::.run_if(state_changed::), - log_transition::.run_if(state_changed::), - log_transition::.run_if(state_changed::), - )); + app + .init_state::() + .add_systems(Update, + // Logging state transitions + ( + log_transition::.run_if(state_changed::), + log_transition::.run_if(state_changed::), + log_transition::.run_if(state_changed::), + )) + .add_systems(Update, toggle_debug.run_if(input_just_pressed(KeyCode::F12))); } } @@ -28,6 +33,7 @@ pub enum Debugger { On, } +/// Logs all state transitions for state T fn log_transition( curr: Res>, mut prev: Local>, @@ -38,3 +44,16 @@ fn log_transition( *prev = Some(curr.get().clone()); } + +/// Toggle the debug state when a key is pressed +fn toggle_debug( + curr: Res>, + mut next: ResMut>, +) { + next.set( + match curr.get() { + Debugger::On => Debugger::Off, + Debugger::Off => Debugger::On, + } + ); +}