From 4ecbfaa3700aa0dffa2a5ff1e92e4b630320db96 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Sun, 27 Jul 2025 14:42:50 -0500 Subject: [PATCH] Implement (most of) the timer countdown The timer-wrapper thing was marked as a Component rather than a Resource, which I have fixed. The update function is about as straight forward as can be: 1. tick the timer 2. read the value out, format it for display, 3. check if the timer is expired, change states if so. --- src/preparation_widget.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/preparation_widget.rs b/src/preparation_widget.rs index a29a321..8103408 100644 --- a/src/preparation_widget.rs +++ b/src/preparation_widget.rs @@ -11,7 +11,8 @@ pub fn preparation_widget_plugin(app: &mut App) { .add_systems( Update, (animate_get_ready_widget).run_if(in_state(GameState::GetReady)), - ); + ) + .insert_resource(ReadySetGoTimer(Timer::from_seconds(3.0, TimerMode::Once))); } /// Marker component for things on the get-ready indicator @@ -19,7 +20,7 @@ pub fn preparation_widget_plugin(app: &mut App) { struct OnReadySetGo; /// Newtype wrapper for `Timer`. Used to count down during the "get ready" phase. -#[derive(Component)] +#[derive(Deref, DerefMut, Resource)] struct ReadySetGoTimer(Timer); /// Marker for the counter text segment @@ -71,6 +72,23 @@ fn despawn_get_ready(mut commands: Commands, to_despawn: Query>, + time: Res