debug egui
This commit is contained in:
+65
-3
@@ -1,6 +1,7 @@
|
||||
use bevy::{
|
||||
asset::uuid::timestamp::context,
|
||||
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
||||
math::curve::cores::ChunkedUnevenCoreError,
|
||||
prelude::*,
|
||||
};
|
||||
use bevy_egui::{EguiContexts, EguiPrimaryContextPass, egui};
|
||||
@@ -9,10 +10,11 @@ use crate::{
|
||||
config::{SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
gameplay::{
|
||||
camera::MainCamera,
|
||||
player::{MoveSettings, Player},
|
||||
player::{FallStarted, MoveSettings, Player, Velocity, spawn_player},
|
||||
score::Depth,
|
||||
},
|
||||
states::GameState,
|
||||
world::RunSeed,
|
||||
world::{Chunk, RunSeed},
|
||||
};
|
||||
|
||||
#[derive(Component)]
|
||||
@@ -210,9 +212,14 @@ fn update_view_debug_text(mut text: Single<&mut Text, With<ViewDebugText>>) {
|
||||
fn debug_panel(
|
||||
mut contexts: EguiContexts,
|
||||
store: Res<DiagnosticsStore>,
|
||||
run_seed: Res<RunSeed>,
|
||||
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
|
||||
@@ -225,8 +232,28 @@ fn debug_panel(
|
||||
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}"));
|
||||
|
||||
@@ -237,6 +264,25 @@ fn debug_panel(
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -267,6 +313,22 @@ fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettin
|
||||
if ui.button("Reset").clicked() {
|
||||
*settings = MoveSettings::default();
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
let export_text = format!(
|
||||
"pub const FALL_SPEED: f32 = {:.0};\npub const DIVE_SPEED: f32 = {:.0};\npub const HORIZONTAL_SPEED: f32 = {:.0};\npub const HORIZONTAL_ACCEL: f32 = {:.0};\npub const HORIZONTAL_FRICTION: f32 = {:.0};\npub const VERTICAL_RATE: f32 = {:.0};",
|
||||
settings.fall_speed,
|
||||
settings.dive_speed,
|
||||
settings.horizontal_speed,
|
||||
settings.horizontal_accel,
|
||||
settings.horizontal_friction,
|
||||
settings.vertical_rate,
|
||||
);
|
||||
// ui.monospace(&export_text);
|
||||
if ui.button("Copy -> config.rs").clicked() {
|
||||
ui.ctx().copy_text(export_text);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -18,14 +18,14 @@ pub struct Player;
|
||||
|
||||
// Speed of the player
|
||||
#[derive(Component)]
|
||||
pub struct Velocity(Vec2);
|
||||
pub struct Velocity(pub Vec2);
|
||||
|
||||
// Falling bool
|
||||
#[derive(Resource, Default)]
|
||||
pub struct FallStarted(pub bool);
|
||||
|
||||
// Spawn entity player
|
||||
fn spawn_player(mut commands: Commands) {
|
||||
pub fn spawn_player(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Player,
|
||||
Collider {
|
||||
|
||||
Reference in New Issue
Block a user