49 lines
1 KiB
Rust
49 lines
1 KiB
Rust
use bevy::prelude::*;
|
|
|
|
use crate::{Brick, GameState, WORLD_SIZE};
|
|
|
|
pub struct DebugPlugin;
|
|
|
|
impl Plugin for DebugPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
if !cfg!(feature = "debug") {
|
|
return;
|
|
}
|
|
|
|
app.add_systems(
|
|
Update,
|
|
(
|
|
draw_world_bounds,
|
|
log_state_transitions.run_if(state_changed::<GameState>),
|
|
cheat_codes,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
fn draw_world_bounds(mut gizmos: Gizmos) {
|
|
gizmos.rect_2d(
|
|
Isometry2d::from_translation(WORLD_SIZE / 2.),
|
|
WORLD_SIZE,
|
|
LinearRgba::RED,
|
|
);
|
|
}
|
|
|
|
fn log_state_transitions(state: Res<State<GameState>>) {
|
|
info!({ ?state }, "State changed");
|
|
}
|
|
|
|
fn cheat_codes(
|
|
mut commands: Commands,
|
|
input: Res<ButtonInput<KeyCode>>,
|
|
bricks: Query<Entity, With<Brick>>,
|
|
) {
|
|
if input.pressed(KeyCode::Digit1) {
|
|
let mut iter = bricks.iter();
|
|
_ = iter.next();
|
|
|
|
for entity in iter {
|
|
commands.entity(entity).despawn();
|
|
}
|
|
}
|
|
}
|