@@ -151,6 +151,7 @@ func (e *Engine) processCommand(c *EventCommand) error {
151151 return errors .Errorf ("Unknown command: %v" , c )
152152 }
153153
154+ e .updatePreStages ()
154155 log .Printf ("Processed command %v" , * c )
155156 return nil
156157}
@@ -210,17 +211,25 @@ func (e *Engine) processStage(s *EventStage) error {
210211 if nextIndex >= len (Stages ) {
211212 return errors .New ("No next stage" )
212213 }
213- e .State . Stage = Stages [nextIndex ]
214+ e .updateStage ( Stages [nextIndex ])
214215 } else if s .StageOperation == StagePrevious {
215216 nextIndex := index - 1
216217 if nextIndex < 0 {
217218 return errors .New ("No previous stage" )
218219 }
219- e .State . Stage = Stages [nextIndex ]
220+ e .updateStage ( Stages [nextIndex ])
220221 } else {
221222 return errors .Errorf ("Unknown stage operation: %v" , s .StageOperation )
222223 }
223224
225+ log .Printf ("Processed stage %v" , s .StageOperation )
226+
227+ return nil
228+ }
229+
230+ func (e * Engine ) updateStage (stage Stage ) {
231+ e .State .Stage = stage
232+
224233 e .State .StageTimeLeft = e .StageTimes [e .State .Stage ]
225234 e .State .StageTimeElapsed = 0
226235
@@ -233,10 +242,6 @@ func (e *Engine) processStage(s *EventStage) error {
233242 e .State .TeamState [TeamBlue ].TimeoutsLeft = e .config .Overtime .Timeouts
234243 e .State .TeamState [TeamBlue ].TimeoutTimeLeft = e .config .Overtime .TimeoutDuration
235244 }
236-
237- log .Printf ("Processed stage %v" , s .StageOperation )
238-
239- return nil
240245}
241246
242247func (e * Engine ) processCard (card * EventCard ) error {
@@ -322,6 +327,22 @@ func revokeCard(card *EventCard, teamState *TeamInfo) error {
322327 return nil
323328}
324329
330+ func (e * Engine ) updatePreStages () {
331+ proceedPreStages := e .State .GameState != GameStateHalted
332+ if proceedPreStages {
333+ switch e .State .Stage {
334+ case StagePreGame :
335+ e .updateStage (StageFirstHalf )
336+ case StageSecondHalfPre :
337+ e .updateStage (StageSecondHalf )
338+ case StageOvertimeFirstHalfPre :
339+ e .updateStage (StageOvertimeFirstHalf )
340+ case StageOvertimeSecondHalfPre :
341+ e .updateStage (StageOvertimeSecondHalf )
342+ }
343+ }
344+ }
345+
325346func strToDuration (s string ) (duration time.Duration , err error ) {
326347 duration = 0
327348 err = nil
0 commit comments