@@ -28,8 +28,10 @@ struct ContributorSelection {
28
28
idx : usize ,
29
29
}
30
30
31
- #[ derive( Component ) ]
32
- struct SelectTimer ;
31
+ struct SelectTimerState {
32
+ timer : Timer ,
33
+ has_triggered : bool ,
34
+ }
33
35
34
36
#[ derive( Component ) ]
35
37
struct ContributorDisplay ;
@@ -122,7 +124,10 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
122
124
commands. spawn_bundle ( OrthographicCameraBundle :: new_2d ( ) ) ;
123
125
commands. spawn_bundle ( UiCameraBundle :: default ( ) ) ;
124
126
125
- commands. spawn_bundle ( ( SelectTimer , Timer :: from_seconds ( SHOWCASE_TIMER_SECS , true ) ) ) ;
127
+ commands. insert_resource ( SelectTimerState {
128
+ timer : Timer :: from_seconds ( SHOWCASE_TIMER_SECS , true ) ,
129
+ has_triggered : false ,
130
+ } ) ;
126
131
127
132
commands
128
133
. spawn ( )
@@ -161,21 +166,19 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
161
166
fn select_system (
162
167
mut contributor_selection : ResMut < ContributorSelection > ,
163
168
mut text_query : Query < & mut Text , With < ContributorDisplay > > ,
164
- mut timer_query : Query < & mut Timer , With < SelectTimer > > ,
165
169
mut query : Query < ( & Contributor , & mut Sprite , & mut Transform ) > ,
170
+ mut timer_state : ResMut < SelectTimerState > ,
166
171
time : Res < Time > ,
167
- mut has_first_tick_occurred : Local < bool > ,
168
172
) {
169
- let mut timer = timer_query. single_mut ( ) ;
170
- if !timer. tick ( time. delta ( ) ) . just_finished ( ) {
173
+ if !timer_state. timer . tick ( time. delta ( ) ) . just_finished ( ) {
171
174
return ;
172
175
}
173
- if !* has_first_tick_occurred {
176
+ if !timer_state . has_triggered {
174
177
let mut text = text_query. single_mut ( ) ;
175
178
text. sections [ 0 ] . value . clear ( ) ;
176
179
text. sections [ 0 ] . value . push_str ( "Contributor: " ) ;
177
180
178
- * has_first_tick_occurred = true ;
181
+ timer_state . has_triggered = true ;
179
182
}
180
183
181
184
{
0 commit comments