You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
use bevy::color::palettes::css::{BLACK, RED, WHITE};
|
|
|
|
use super::*;
|
|
|
|
/// Debugging systems, resources, events, etc.
|
|
pub struct DebuggingPlugin;
|
|
|
|
impl Plugin for DebuggingPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.init_state::<DebuggingState>()
|
|
.add_systems(Startup, init_debug_ui)
|
|
.add_systems(Update, (
|
|
toggle_state_visibility::<DebuggingState>.run_if(state_changed::<DebuggingState>),
|
|
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<NextState<DebuggingState>>,
|
|
curr: Res<State<DebuggingState>>,
|
|
) {
|
|
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()
|
|
}
|
|
));
|
|
}
|