debug info texts
This commit is contained in:
+80
-3
@@ -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<RunSeed>,
|
||||
mut run_seed_debug_text: Single<&mut Text, With<SeedDebugText>>,
|
||||
) {
|
||||
run_seed_debug_text.0 = format!("Seed: {}", run_seed.0);
|
||||
}
|
||||
|
||||
fn update_fps_debug_text(
|
||||
store: Res<DiagnosticsStore>,
|
||||
mut fps_debug_text: Single<&mut Text, With<FpsDebugText>>,
|
||||
) {
|
||||
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<Entity, With<Debug>>) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user