game states cleanup

This commit is contained in:
2026-09-19 10:53:36 +02:00
parent 9df830bf18
commit d42f5af75f
7 changed files with 74 additions and 20 deletions
+14 -3
View File
@@ -2,11 +2,15 @@ use bevy::prelude::*;
use crate::{camera::MainCamera, game_state::GameState, player::Player};
#[derive(Component)]
pub struct Debug;
#[derive(Component)]
pub struct DebugCamera;
fn spawn_debug_camera(mut commands: Commands) {
commands.spawn((
Debug,
DebugCamera,
Camera2d,
Camera {
@@ -63,6 +67,7 @@ fn spawn_debug_frame(mut commands: Commands) {
};
commands.spawn((
Debug,
FramePart(side),
Sprite::from_color(Color::srgb(1.0, 0.0, 0.0), size),
Visibility::Hidden,
@@ -99,18 +104,24 @@ fn draw_view_frame(
*visibility = visible;
}
}
fn cleanup_debug(mut commands: Commands, entities: Query<Entity, With<Debug>>) {
for entity in entities {
commands.entity(entity).despawn();
}
}
pub struct DebugPlugin;
impl Plugin for DebugPlugin {
fn build(&self, app: &mut App) {
app.add_systems(
Startup,
OnEnter(GameState::InGame),
(
spawn_debug_camera,
setup_debug_camera.after(spawn_debug_camera),
spawn_debug_frame,
)
.run_if(in_state(GameState::InGame)),
),
)
.add_systems(
Update,