Skip to content

Commit f26c911

Browse files
committed
[feature] Add autoContinue option, continue automatically if enabled
1 parent fbf26c2 commit f26c911

File tree

9 files changed

+109
-255
lines changed

9 files changed

+109
-255
lines changed

internal/app/controller/controller.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,6 @@ func (c *GameController) ProcessAutoRefRequests(request refproto.AutoRefToContro
7070
event := Event{GameEvent: &GameEvent{Type: gameEventType, Details: details}}
7171
c.OnNewEvent(event)
7272
}
73-
if request.State != nil {
74-
if *request.State == refproto.AutoRefToControllerRequest_READY_TO_CONTINUE {
75-
c.Engine.Continue()
76-
}
77-
}
7873

7974
return nil
8075
}

internal/app/controller/engine.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,14 +332,23 @@ func (e *Engine) processModify(m *EventModifyValue) error {
332332
if m.Division != nil {
333333
if *m.Division == DivA || *m.Division == DivB {
334334
e.State.Division = *m.Division
335-
log.Printf("Processed modification %v", m)
336-
return nil
337335
} else {
338-
return errors.Errorf("Invalid divsion: %v", *m.Division)
336+
return errors.Errorf("Invalid division: %v", *m.Division)
339337
}
338+
} else if m.AutoContinue != nil {
339+
e.State.AutoContinue = *m.AutoContinue
340+
if e.State.AutoContinue {
341+
e.Continue()
342+
}
343+
} else if err := e.processTeamModify(m); err != nil {
344+
return err
340345
}
341346

342-
// process team-dependent modifies
347+
log.Printf("Processed %v", m)
348+
return nil
349+
}
350+
351+
func (e *Engine) processTeamModify(m *EventModifyValue) error {
343352
if m.ForTeam.Unknown() {
344353
return errors.Errorf("Unknown team: %v", m.ForTeam)
345354
}
@@ -390,7 +399,6 @@ func (e *Engine) processModify(m *EventModifyValue) error {
390399
} else {
391400
return errors.Errorf("Unknown modify: %v", m)
392401
}
393-
log.Printf("Processed %v", m)
394402
return nil
395403
}
396404

@@ -593,6 +601,8 @@ func (e *Engine) processGameEvent(event *GameEvent) error {
593601
} else if e.State.GameState() != GameStateStopped {
594602
e.SendCommand(CommandStop, "")
595603
}
604+
} else if e.State.AutoContinue && event.IsContinueGame() {
605+
e.Continue()
596606
}
597607

598608
log.Printf("Processed game event %v", event)

internal/app/controller/events.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,16 @@ type EventModifyValue struct {
105105
BallPlacementFailures *int `json:"ballPlacementFailures"`
106106
CanPlaceBall *bool `json:"canPlaceBall"`
107107
Division *Division `json:"division"`
108+
AutoContinue *bool `json:"autoContinue"`
108109
}
109110

110111
func (m EventModifyValue) String() string {
111-
str := fmt.Sprintf("modify for %v:", m.ForTeam)
112+
str := "modify"
113+
if m.ForTeam != TeamUnknown {
114+
str += fmt.Sprintf(" for team %v:", m.ForTeam)
115+
} else {
116+
str += ":"
117+
}
112118
if m.Goals != nil {
113119
return fmt.Sprintf("%v Goals=%v", str, *m.Goals)
114120
}
@@ -148,6 +154,9 @@ func (m EventModifyValue) String() string {
148154
if m.Division != nil {
149155
return fmt.Sprintf("%v Division=%v", str, *m.Division)
150156
}
157+
if m.AutoContinue != nil {
158+
return fmt.Sprintf("%v AutoContinue=%v", str, *m.AutoContinue)
159+
}
151160
return fmt.Sprintf("%v undefined", str)
152161
}
153162

internal/app/controller/gameEvent.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ func (e GameEvent) IsContinued() bool {
144144
return false
145145
}
146146

147+
// IsContinueGame checks if the game event should trigger continuing the game based on the current primary event
148+
func (e GameEvent) IsContinueGame() bool {
149+
switch e.Type {
150+
case GameEventPlacementSucceeded,
151+
GameEventPrepared:
152+
return true
153+
}
154+
return false
155+
}
156+
147157
func (e GameEvent) ToProto() *refproto.GameEvent {
148158
protoEvent := new(refproto.GameEvent)
149159
switch e.Type {

internal/app/controller/state.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ type State struct {
256256
TeamState map[Team]*TeamInfo `json:"teamState"`
257257
Division Division `json:"division"`
258258
PlacementPos *Location `json:"placementPos"`
259+
AutoContinue bool `json:"autoContinue"`
259260
}
260261

261262
// NewState creates a new state, initialized for the start of a new game
@@ -278,6 +279,7 @@ func NewState() (s *State) {
278279
s.TeamState[TeamBlue].OnPositiveHalf = !s.TeamState[TeamYellow].OnPositiveHalf
279280

280281
s.Division = DivA
282+
s.AutoContinue = true
281283

282284
return
283285
}

0 commit comments

Comments
 (0)