use super::*; /// Debugging systems, resources, events, etc. pub struct DebuggingPlugin; impl Plugin for DebuggingPlugin { fn build(&self, app: &mut App) { app.init_state::() .add_systems(Startup, init_debug_ui) .add_systems(Update, ( toggle_state_visibility::.run_if(state_changed::), toggle_debug_state.run_if(on_keyboard_press(KeyCode::F12)) )); } } /// Tracks if the debugger is on or off for other games systems to hook into /// /// The Debugging state may add it's own global debugging information, but is mostly a shell #[derive(States, Component, Default, Debug, Clone, Hash, Eq, PartialEq)] pub enum DebuggingState { #[default] Off, On, } /// Toggles the debug state from off -> on // off -> on when triggered fn toggle_debug_state( mut next: ResMut>, curr: Res>, ) { use DebuggingState::*; next.set(match curr.get() { On => Off, Off => On, }); debug!("Toggling debug state: {:?} -> {:?}", curr, next); } /// Create the Debugging UI fn init_debug_ui( mut commands: Commands ) { commands.spawn(( DebuggingState::On, Text(" Debug: ON ".into()), TextColor(WHITE.into()), BackgroundColor(RED.into()), BorderRadius::MAX, Node { align_self: AlignSelf::Center, justify_self: JustifySelf::End, ..default() } )); }