use super::card;
use crate::app::Sim;
use bevy::prelude::*;
#[derive(Component)]
pub struct SideClock;
pub(super) const CLOCK_TOP: f32 = 10.0;
const CLOCK_PX: f32 = 44.0;
pub fn update_side_clock(
sim: Res<Sim>,
blink: crate::app::hud::Blink,
mut clocks: Query<(&mut Text, &mut TextColor), With<SideClock>>,
mut value: Local<String>,
) {
let Some(ticks) = sim.0.remaining_ticks() else {
return;
};
crate::app::hud::clock_into(&mut value, ticks);
let (elapsed, blinking) = blink.read(&sim.0);
let target = crate::app::hud::clock_color(ticks, sim.0.rules().round_length, elapsed, blinking);
for (mut text, mut color) in &mut clocks {
crate::app::menu_ui::set_text(&mut text, &value);
crate::app::menu_ui::set_color(&mut color, target);
}
}
pub(super) const CLOCK_H: f32 = 64.0 + 2.0 * crate::app::menu_ui::FRAME_PX;
pub(super) fn spawn_clock(root: &mut ChildSpawnerCommands) {
let (mut node, edge, fill, shadow) = card(CLOCK_TOP, Some(CLOCK_H));
node.padding.bottom = Val::Px(crate::app::menu_ui::CARD_PAD);
root.spawn((node, edge, fill, shadow, crate::app::menu_ui::Framed))
.with_children(|card| {
card.spawn((
SideClock,
Text::new(""),
crate::app::menu_ui::display_font(CLOCK_PX),
TextColor(crate::app::palette::CLOCK_CALM),
));
});
}