debug cam issue fixed
This commit is contained in:
+86
-80
@@ -13,6 +13,7 @@ use crate::{
|
||||
player::{FallStarted, MoveSettings, Player, Velocity, spawn_player},
|
||||
score::Depth,
|
||||
},
|
||||
screen::DisplayImage,
|
||||
states::GameState,
|
||||
world::{Chunk, RunSeed},
|
||||
};
|
||||
@@ -33,6 +34,7 @@ fn spawn_debug_camera(mut commands: Commands) {
|
||||
Camera2d,
|
||||
Camera {
|
||||
is_active: false,
|
||||
order: 2,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
@@ -45,13 +47,17 @@ fn setup_debug_camera(mut camera: Single<&mut Projection, With<DebugCamera>>) {
|
||||
}
|
||||
|
||||
fn toggle_debug_camera(
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||
mut display_image: Single<&mut Visibility, With<DisplayImage>>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::Tab) {
|
||||
main_camera.is_active = !main_camera.is_active;
|
||||
debug_camera.is_active = !debug_camera.is_active;
|
||||
|
||||
if debug_camera.is_active {
|
||||
**display_image = Visibility::Hidden;
|
||||
} else {
|
||||
**display_image = Visibility::Visible;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,83 +215,6 @@ fn update_view_debug_text(mut text: Single<&mut Text, With<ViewDebugText>>) {
|
||||
text.0 = format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}");
|
||||
}
|
||||
|
||||
fn debug_panel(
|
||||
mut contexts: EguiContexts,
|
||||
store: Res<DiagnosticsStore>,
|
||||
mut run_seed: ResMut<RunSeed>,
|
||||
player: Single<(Entity, &Transform, &Velocity), With<Player>>,
|
||||
chunk: Query<Entity, With<Chunk>>,
|
||||
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||
mut commands: Commands,
|
||||
mut fall_started: ResMut<FallStarted>,
|
||||
mut depth: ResMut<Depth>,
|
||||
) {
|
||||
egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| {
|
||||
// Fps
|
||||
let fps = store
|
||||
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||
.and_then(|diagnostic| diagnostic.smoothed());
|
||||
|
||||
match fps {
|
||||
Some(fps) => ui.label(format!("FPS: {fps:.0}")),
|
||||
None => ui.label("FPS: -"),
|
||||
};
|
||||
|
||||
// Frame time in ms
|
||||
match store
|
||||
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
|
||||
.and_then(|d| d.smoothed())
|
||||
{
|
||||
Some(ms) => ui.label(format!("Frame: {ms:.2} ms")),
|
||||
None => ui.label("Frame : - ms"),
|
||||
};
|
||||
|
||||
// Run seed
|
||||
ui.label(format!("Seed: {}", run_seed.0));
|
||||
|
||||
let (player_entity, transform, velocity) = *player;
|
||||
ui.label(format!(
|
||||
"Position: ({:.0}, {:.0})",
|
||||
transform.translation.x, transform.translation.y
|
||||
));
|
||||
ui.label(format!(
|
||||
"Velocity: ({:.0},{:.0})",
|
||||
velocity.0.x, velocity.0.y
|
||||
));
|
||||
|
||||
// Resolution
|
||||
ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}"));
|
||||
|
||||
ui.separator();
|
||||
|
||||
let state = if debug_camera.is_active { "ON" } else { "OFF" };
|
||||
if ui.button(format!("Debug camera: {state}")).clicked() {
|
||||
main_camera.is_active = !main_camera.is_active;
|
||||
debug_camera.is_active = !debug_camera.is_active;
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
let restart = ui.button("Restart (same seed)").clicked();
|
||||
let new_map = ui.button("Restart (new map)").clicked();
|
||||
if restart || new_map {
|
||||
for entity in chunk.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
if new_map {
|
||||
run_seed.0 = rand::random::<u64>();
|
||||
}
|
||||
fall_started.0 = false;
|
||||
depth.0 = 0.0;
|
||||
|
||||
commands.entity(player_entity).despawn();
|
||||
|
||||
spawn_player(commands);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Real time tuning movement & inertia sliders
|
||||
fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettings>) {
|
||||
egui::Window::new("Movement / Inertia ").show(
|
||||
@@ -333,6 +262,84 @@ fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettin
|
||||
);
|
||||
}
|
||||
|
||||
fn debug_panel(
|
||||
mut contexts: EguiContexts,
|
||||
store: Res<DiagnosticsStore>,
|
||||
mut run_seed: ResMut<RunSeed>,
|
||||
player: Single<(Entity, &Transform, &Velocity), With<Player>>,
|
||||
chunk: Query<Entity, With<Chunk>>,
|
||||
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||
mut commands: Commands,
|
||||
mut fall_started: ResMut<FallStarted>,
|
||||
mut depth: ResMut<Depth>,
|
||||
mut display_image: Single<&mut Visibility, With<DisplayImage>>,
|
||||
) {
|
||||
egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| {
|
||||
// Fps
|
||||
let fps = store
|
||||
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||
.and_then(|diagnostic| diagnostic.smoothed());
|
||||
|
||||
match fps {
|
||||
Some(fps) => ui.label(format!("FPS: {fps:.0}")),
|
||||
None => ui.label("FPS: -"),
|
||||
};
|
||||
|
||||
// Frame time in ms
|
||||
match store
|
||||
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
|
||||
.and_then(|d| d.smoothed())
|
||||
{
|
||||
Some(ms) => ui.label(format!("Frame: {ms:.2} ms")),
|
||||
None => ui.label("Frame : - ms"),
|
||||
};
|
||||
|
||||
// Run seed
|
||||
ui.label(format!("Seed: {}", run_seed.0));
|
||||
|
||||
let (player_entity, transform, velocity) = *player;
|
||||
ui.label(format!(
|
||||
"Position: ({:.0}, {:.0})",
|
||||
transform.translation.x, transform.translation.y
|
||||
));
|
||||
ui.label(format!(
|
||||
"Velocity: ({:.0},{:.0})",
|
||||
velocity.0.x, velocity.0.y
|
||||
));
|
||||
|
||||
// Resolution
|
||||
ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}"));
|
||||
|
||||
ui.separator();
|
||||
|
||||
let state = if debug_camera.is_active { "ON" } else { "OFF" };
|
||||
if ui.button(format!("Debug camera: {state}")).clicked() {
|
||||
toggle_debug_camera(main_camera, debug_camera, display_image);
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
let restart = ui.button("Restart (same seed)").clicked();
|
||||
let new_map = ui.button("Restart (new map)").clicked();
|
||||
if restart || new_map {
|
||||
for entity in chunk.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
if new_map {
|
||||
run_seed.0 = rand::random::<u64>();
|
||||
}
|
||||
fall_started.0 = false;
|
||||
depth.0 = 0.0;
|
||||
|
||||
commands.entity(player_entity).despawn();
|
||||
|
||||
spawn_player(commands);
|
||||
}
|
||||
// TODO: Add colidbox On/Off button
|
||||
});
|
||||
}
|
||||
|
||||
pub struct DebugPlugin;
|
||||
|
||||
impl Plugin for DebugPlugin {
|
||||
@@ -351,7 +358,6 @@ impl Plugin for DebugPlugin {
|
||||
(
|
||||
draw_view_frame,
|
||||
follow_player_debug,
|
||||
toggle_debug_camera,
|
||||
// update_seed_debug_text,
|
||||
// update_fps_debug_text,
|
||||
// update_view_debug_text,
|
||||
|
||||
@@ -49,6 +49,7 @@ fn spawn_virtual_screen(mut commands: Commands, mut images: ResMut<Assets<Image>
|
||||
DisplayImage,
|
||||
Sprite::from_image(game_image),
|
||||
Transform::default(),
|
||||
Visibility::Visible,
|
||||
RenderLayers::layer(1),
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user