debug systems toggle

This commit is contained in:
nquidox 2026-04-18 20:51:09 +03:00
parent eb4e1a1e6c
commit a10cc0712b
4 changed files with 105 additions and 20 deletions

View file

@ -5,3 +5,17 @@ pub struct LinearStateMarker;
#[derive(Component, Copy, Clone)]
pub struct LinearRestartMarker;
#[derive(Resource)]
pub struct LinearDebugConfig {
pub toggle_track: bool,
pub toggle_grid: bool,
pub toggle_laser: bool,
}
#[derive(Component, Copy, Clone)]
pub enum DebugToggle{
Track,
Grid,
Laser,
}

View file

@ -3,8 +3,8 @@ pub mod plugin;
mod components;
pub use components::*;
mod systems;
pub use systems::*;
mod systems_debug;
pub use systems_debug::*;
mod components_track;
pub use components_track::*;

View file

@ -1,9 +1,13 @@
use crate::{HEIGHT, WIDTH, states, FACTOR};
use crate::{FACTOR, HEIGHT, WIDTH, states};
use bevy::prelude::*;
use states::linear::*;
use std::f32::consts::FRAC_PI_2;
pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos, config: ResMut<LinearDebugConfig>) {
if !config.toggle_track {
return;
};
let mut current_pos = track.start_point;
let mut current_dir = track.start_direction.normalize();
@ -53,23 +57,51 @@ pub fn draw_track_gizmos(track: Res<Track>, mut gizmos: Gizmos) {
gizmos.circle_2d(current_pos, 5.0, Color::WHITE);
}
pub fn draw_grid(mut gizmos: Gizmos) {
let half_x = WIDTH as f32 / 2.0 * FACTOR as f32;
let half_y = HEIGHT as f32 / 2.0 * FACTOR as f32;
pub fn draw_grid(mut gizmos: Gizmos, config: ResMut<LinearDebugConfig>) {
if !config.toggle_grid {
return;
};
const FF: f32 = FACTOR as f32;
const HALF_X: f32 = WIDTH as f32 / 2.0;
const HALF_Y: f32 = HEIGHT as f32 / 2.0;
const STEP_X: f32 = HALF_X * FF;
const STEP_Y: f32 = HALF_Y * FF;
for i in 0..WIDTH {
gizmos.line_2d(
Vec2::new((i as f32 - 8.0) * FACTOR as f32, half_y),
Vec2::new((i as f32 - 8.0) * FACTOR as f32, -half_y),
Vec2::new((i as f32 - HALF_X) * FF, STEP_Y),
Vec2::new((i as f32 - HALF_X) * FF, -STEP_Y),
DARK_GREEN,
);
}
for i in 0..HEIGHT {
gizmos.line_2d(
Vec2::new(-half_x, (i as f32 - 4.0) * FACTOR as f32),
Vec2::new(half_x, (i as f32 - 4.0) * FACTOR as f32),
Vec2::new(-STEP_X, (i as f32 - HALF_Y) * FF),
Vec2::new(STEP_X, (i as f32 - HALF_Y) * FF),
DARK_GREEN,
)
}
}
// pub fn draw_cannon_laser(mut gizmos: Gizmos, config: ResMut<LinearDebugConfig>){
// if !config.toggle_laser {
// return;
// };
// }
pub fn toggle_debug_systems(
buttons: Query<(&Interaction, &DebugToggle), Changed<Interaction>>,
mut config: ResMut<LinearDebugConfig>,
) {
for (interaction, toggle_type) in &buttons {
if matches!(interaction, Interaction::Pressed) {
match toggle_type {
DebugToggle::Track => config.toggle_track = !config.toggle_track,
DebugToggle::Grid => config.toggle_grid = !config.toggle_grid,
DebugToggle::Laser => config.toggle_laser = !config.toggle_laser,
}
}
}
}

View file

@ -1,11 +1,12 @@
use crate::states::AppState;
use crate::states::AppState::LinearPlayState;
use crate::states::linear::plugin::LinearUpdateSet;
use crate::states::linear::{LinearRestartMarker, LinearStateMarker};
use crate::states::linear::{DebugToggle, LinearRestartMarker, LinearStateMarker};
use crate::ui::button_click::ButtonClickMessage;
use crate::ui::click::handle_click_system;
use crate::ui::{ButtonStyle, spawn_button};
use crate::ui::{ButtonStyle, spawn_button, spawn_background};
use bevy::prelude::*;
use crate::{FACTOR, HEIGHT, WIDTH};
pub struct LinearUIPlugin;
@ -44,25 +45,63 @@ fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
))
.id();
let restart_button_style = ButtonStyle {
let button_style = ButtonStyle {
font: asset_server.load("fonts/QR Ames Beta.otf"),
font_size: 24.0,
font_size: 16.0,
text_color: Color::WHITE,
normal_bg: Color::linear_rgba(0.15, 0.15, 0.15, 1.0),
hovered_bg: Color::linear_rgb(0.25, 0.25, 0.25),
pressed_bg: Color::linear_rgb(0.3, 0.3, 0.3),
width: Val::Px(200.0),
height: Val::Px(50.0),
width: Val::Px(100.0),
height: Val::Px(25.0),
margin: UiRect::all(Val::Px(10.0)),
};
let bg_image: Handle<Image> = asset_server.load("sprites/bg/linear_bg.png");
commands.spawn((
Sprite{
image: bg_image,
custom_size: Some(Vec2::new((WIDTH*FACTOR) as f32, (HEIGHT*FACTOR) as f32)),
..default()
},
Transform::from_xyz(0.0, 0.0, -10.0),
LinearStateMarker,
));
// spawn_background(&mut commands, bg_image, LinearStateMarker);
spawn_button(
&mut commands,
root,
"Restart",
&restart_button_style,
&button_style,
LinearRestartMarker,
);
spawn_button(
&mut commands,
root,
"Track",
&button_style,
DebugToggle::Track,
);
spawn_button(
&mut commands,
root,
"Grid",
&button_style,
DebugToggle::Grid,
);
spawn_button(
&mut commands,
root,
"Laser",
&button_style,
DebugToggle::Laser,
);
}
pub fn restart_game_button_system(