mirror of
https://github.com/storytold/storyteller-bevy.git
synced 2026-10-17 00:13:17 +00:00
Debug toggling (#9)
#8 introduced some additional debug information to the view, which was already rendering some information and visualizations which were not necessary relevant to the end-user experience. This PR adds an input action (bound to Ctrl + `) to toggle the display of those visualizations, and disables them by default.
This commit is contained in:
+38
-16
@@ -3,13 +3,19 @@ use bevy::{
|
||||
prelude::*,
|
||||
};
|
||||
|
||||
use crate::debug::DebugMode;
|
||||
|
||||
pub(super) struct FpsCounterPlugin;
|
||||
|
||||
impl Plugin for FpsCounterPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_plugins(FrameTimeDiagnosticsPlugin)
|
||||
.add_systems(Startup, layout)
|
||||
.add_systems(Update, update);
|
||||
.add_systems(Update, update)
|
||||
.add_systems(
|
||||
Update,
|
||||
update_visibility.run_if(resource_exists_and_changed::<DebugMode>()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,24 +23,28 @@ impl Plugin for FpsCounterPlugin {
|
||||
struct FramerateCounter;
|
||||
|
||||
fn layout(mut cmd: Commands) {
|
||||
let mut text_bundle = TextBundle::from_section(
|
||||
"0 fps",
|
||||
TextStyle {
|
||||
color: Color::GREEN,
|
||||
font_size: 14.,
|
||||
..default()
|
||||
},
|
||||
)
|
||||
.with_text_alignment(TextAlignment::Right)
|
||||
.with_style(Style {
|
||||
position_type: PositionType::Absolute,
|
||||
right: Val::Px(16.),
|
||||
bottom: Val::Px(16.),
|
||||
..default()
|
||||
});
|
||||
|
||||
text_bundle.visibility = Visibility::Hidden;
|
||||
|
||||
cmd.spawn((
|
||||
FramerateCounter,
|
||||
Name::new("Framerate Counter"),
|
||||
TextBundle::from_section(
|
||||
"0 fps",
|
||||
TextStyle {
|
||||
color: Color::GREEN,
|
||||
font_size: 14.,
|
||||
..default()
|
||||
},
|
||||
)
|
||||
.with_text_alignment(TextAlignment::Right)
|
||||
.with_style(Style {
|
||||
position_type: PositionType::Absolute,
|
||||
right: Val::Px(16.),
|
||||
bottom: Val::Px(16.),
|
||||
..default()
|
||||
}),
|
||||
text_bundle,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -53,3 +63,15 @@ fn update(
|
||||
counter.single_mut().sections[0].value = format!("{fps:.2} fps");
|
||||
}
|
||||
}
|
||||
|
||||
fn update_visibility(
|
||||
r_debug: Res<DebugMode>,
|
||||
mut q_visibility: Query<&mut Visibility, With<FramerateCounter>>,
|
||||
) {
|
||||
for mut visibility in q_visibility.iter_mut() {
|
||||
*visibility = match **r_debug {
|
||||
true => Visibility::Inherited,
|
||||
false => Visibility::Hidden,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user