refactor: Combine two UiStatusText components into one enum

This commit is contained in:
demenik
2025-11-26 20:08:55 +01:00
parent 3b7bfb17e1
commit b63b2d060d
2 changed files with 14 additions and 17 deletions

View File

@@ -1,3 +1,5 @@
use std::thread::current;
use crate::features::savegame::messages::SavegameDumpMessage;
use crate::prelude::*;
@@ -34,13 +36,13 @@ fn setup(mut commands: Commands) {
BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)),
children![
(
UiPhaseText,
UiStatusText::Phase,
Text::new("..."),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
),
(
UiTimerText,
UiStatusText::Timer,
Text::new("--:--"),
TextFont::from_font_size(16.0),
TextColor(Color::WHITE)
@@ -59,22 +61,17 @@ fn setup(mut commands: Commands) {
));
}
fn update_status(
phase_res: Res<CurrentPhase>,
mut phase_query: Query<&mut Text, (With<UiPhaseText>, Without<UiTimerText>)>,
mut timer_query: Query<&mut Text, (With<UiTimerText>, Without<UiPhaseText>)>,
) {
fn update_status(phase_res: Res<CurrentPhase>, mut text_query: Query<(&mut Text, &UiStatusText)>) {
if !phase_res.is_changed() {
return;
}
let current_phase = &phase_res.0;
if let Ok(mut phase_text) = phase_query.single_mut() {
phase_text.0 = current_phase.display_name().to_string();
}
if let Ok(mut timer_text) = timer_query.single_mut() {
timer_text.0 = current_phase.format_duration();
for (mut text, status_type) in text_query.iter_mut() {
text.0 = match status_type {
UiStatusText::Phase => current_phase.display_name().into(),
UiStatusText::Timer => current_phase.format_duration(),
};
}
}

View File

@@ -4,10 +4,10 @@ use crate::prelude::*;
pub struct UiStatusRootContainer;
#[derive(Component)]
pub struct UiPhaseText;
#[derive(Component)]
pub struct UiTimerText;
pub enum UiStatusText {
Phase,
Timer,
}
#[derive(Component)]
pub enum UiStatusButton {