From c39993fc01719f3f0fa235863db970a269bdd1f7 Mon Sep 17 00:00:00 2001 From: zefad Date: Sat, 19 Sep 2026 12:50:48 +0200 Subject: [PATCH] debug info texts --- src/debug.rs | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 3 deletions(-) diff --git a/src/debug.rs b/src/debug.rs index 3c6e802..63fcf87 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -1,6 +1,9 @@ -use bevy::prelude::*; +use bevy::{ + diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin}, + prelude::*, +}; -use crate::{camera::MainCamera, game_state::GameState, player::Player}; +use crate::{camera::MainCamera, game_state::GameState, player::Player, world::RunSeed}; #[derive(Component)] pub struct Debug; @@ -105,6 +108,72 @@ fn draw_view_frame( } } +#[derive(Component)] +struct SeedDebugText; + +#[derive(Component)] +struct FpsDebugText; + +// Debug information on screen +fn spawn_debug_texts(mut commands: Commands) { + commands.spawn(( + Debug, + Node { + position_type: PositionType::Absolute, + right: Val::Px(0.0), + top: Val::Px(0.0), + width: Val::Percent(17.0), + height: Val::Percent(10.0), + flex_direction: FlexDirection::Column, + row_gap: Val::Px(5.0), + ..default() + }, + // Black background + BackgroundColor(Color::srgba(0.0, 1.0, 0.0, 0.1)), + // Texts + children![ + // Seed display + ( + Text::new(""), + TextFont { + font_size: FontSize::Px(20.0), + ..default() + }, + TextColor(Color::srgb(1.0, 1.0, 0.0)), + SeedDebugText, + ), + ( + Text::new(""), + TextFont { + font_size: FontSize::Px(20.0), + ..default() + }, + TextColor(Color::srgb(1.0, 1.0, 0.0)), + FpsDebugText, + ) + ], + )); +} + +// Update depth score texts +fn update_seed_debug_text( + run_seed: Res, + mut run_seed_debug_text: Single<&mut Text, With>, +) { + run_seed_debug_text.0 = format!("Seed: {}", run_seed.0); +} + +fn update_fps_debug_text( + store: Res, + mut fps_debug_text: Single<&mut Text, With>, +) { + if let Some(fps) = store.get(&FrameTimeDiagnosticsPlugin::FPS) { + if let Some(value) = fps.smoothed() { + fps_debug_text.0 = format!("FPS: {:.0}", value); + } + } +} + fn cleanup_debug(mut commands: Commands, entities: Query>) { for entity in entities { commands.entity(entity).despawn(); @@ -121,13 +190,21 @@ impl Plugin for DebugPlugin { spawn_debug_camera, setup_debug_camera.after(spawn_debug_camera), spawn_debug_frame, + spawn_debug_texts, ), ) .add_systems( Update, - (draw_view_frame, follow_player_debug, toggle_debug_camera) + ( + draw_view_frame, + follow_player_debug, + toggle_debug_camera, + update_seed_debug_text, + update_fps_debug_text, + ) .run_if(in_state(GameState::InGame)), ) + .add_plugins(FrameTimeDiagnosticsPlugin::default()) .add_systems(OnExit(GameState::InGame), cleanup_debug); } }