@@ -15,13 +15,14 @@ use bevy::prelude::*;
1515use serde:: { Deserialize , Serialize } ;
1616use serde_with:: { DurationMilliSeconds , serde_as} ;
1717use std:: time:: Duration ;
18+ // use tracing::info;
1819
1920use bifrost:: communication:: { GameControllerMessage , GameState } ;
2021use nidhogg:: types:: color;
2122
2223use std:: time:: Instant ;
2324
24- const GOAL_DELAY : u64 = 15 ;
25+ const GOAL_DELAY : u64 = 17 ;
2526
2627#[ serde_as]
2728#[ derive( Resource , Serialize , Deserialize , Debug , Clone ) ]
@@ -66,7 +67,10 @@ pub enum PrimaryState {
6667 /// State at the start of the match where the robots stand up
6768 Initial ,
6869 /// State in which robots walk to their legal positions
69- Ready { referee_in_standby : bool } ,
70+ Ready {
71+ referee_in_standby : bool ,
72+ whistle_in_playing : bool ,
73+ } ,
7074 /// State in which the robots wait for a kick-off or penalty
7175 Set ,
7276 /// State in which the robots are playing soccer, with a bool to keep state after a whistle
@@ -154,6 +158,7 @@ pub fn update_primary_state(
154158}
155159
156160#[ must_use]
161+ #[ allow( clippy:: too_many_arguments) ]
157162pub fn next_primary_state (
158163 primary_state : & PrimaryState ,
159164 game_controller_message : Option < & GameControllerMessage > ,
@@ -197,10 +202,7 @@ pub fn next_primary_state(
197202 ..
198203 }
199204 ) {
200- primary_state = PS :: Ready {
201- referee_in_standby : false ,
202- whistle_in_playing : false ,
203- } ;
205+ primary_state = PS :: Set ;
204206 }
205207 }
206208
@@ -225,6 +227,15 @@ pub fn next_primary_state(
225227 ) || recognized_ready_pose;
226228
227229 let previous_primary_state = primary_state;
230+
231+ // if matches!(primary_state, PS::Playing { .. }) && whistle.detected() {
232+ // primary_state = PS::Ready {
233+ // referee_in_standby: false,
234+ // whistle_in_playing: true,
235+ // };
236+ // whistle_timer.whistle_timer = Some(Instant::now());
237+ // }
238+
228239 primary_state = match game_controller_message {
229240 Some ( message) => match message. state {
230241 GameState :: Initial => PS :: Initial ,
@@ -258,6 +269,14 @@ pub fn next_primary_state(
258269 )
259270 {
260271 whistle_timer. whistle_timer = Some ( Instant :: now ( ) ) ;
272+ // info!("starting whistle");
273+ }
274+
275+ // if we change from whistle_in_playing:true turn off timer
276+ if previous_primary_state != primary_state && matches ! ( previous_primary_state, PS :: Ready { .. } )
277+ {
278+ whistle_timer. whistle_timer = None ;
279+ // info!("stopped whiste (switched state)")
261280 }
262281
263282 // check if a timer was set
@@ -266,6 +285,10 @@ pub fn next_primary_state(
266285 // either it was a false positive, or it was okay and should also be reset
267286 if start_time. elapsed ( ) . as_secs ( ) > GOAL_DELAY {
268287 whistle_timer. whistle_timer = None ;
288+ // info!(
289+ // "stopped whistle (GOAL DELAY). {:?}",
290+ // start_time.elapsed().as_secs()
291+ // );
269292 // if it still has whistle_in_playing:true after the GOAL_DELAY, change to false
270293 if matches ! (
271294 primary_state,
@@ -283,7 +306,7 @@ pub fn next_primary_state(
283306 }
284307
285308 if previous_primary_state != primary_state {
286- println ! ( "primary state is set to: {:?}" , primary_state ) ;
309+ // println!("primary state is set to: {primary_state :?}");
287310 }
288311
289312 if penalty_state. is_penalized ( ) {
0 commit comments