@@ -26,44 +26,44 @@ func processEvent(event *Event) error {
26
26
func processCommand (c * EventCommand ) error {
27
27
switch c .Type {
28
28
case CommandHalt :
29
- refBox .State .GameState = GameStateHalted
30
- refBox .State .GameStateFor = nil
29
+ RefBox .State .GameState = GameStateHalted
30
+ RefBox .State .GameStateFor = nil
31
31
case CommandStop :
32
- refBox .State .GameState = GameStateStopped
33
- refBox .State .GameStateFor = nil
32
+ RefBox .State .GameState = GameStateStopped
33
+ RefBox .State .GameStateFor = nil
34
34
case CommandForceStart , CommandNormalStart , CommandDirect , CommandIndirect :
35
- refBox .State .GameState = GameStateRunning
36
- refBox .State .GameStateFor = nil
35
+ RefBox .State .GameState = GameStateRunning
36
+ RefBox .State .GameStateFor = nil
37
37
case CommandKickoff :
38
38
if c .ForTeam == nil {
39
39
return errors .New ("Team required for kickoff" )
40
40
}
41
- refBox .State .GameState = GameStatePreKickoff
42
- refBox .State .GameStateFor = c .ForTeam
41
+ RefBox .State .GameState = GameStatePreKickoff
42
+ RefBox .State .GameStateFor = c .ForTeam
43
43
case CommandPenalty :
44
44
if c .ForTeam == nil {
45
45
return errors .New ("Team required for penalty" )
46
46
}
47
- refBox .State .GameState = GameStatePrePenalty
48
- refBox .State .GameStateFor = c .ForTeam
47
+ RefBox .State .GameState = GameStatePrePenalty
48
+ RefBox .State .GameStateFor = c .ForTeam
49
49
case CommandBallPlacement :
50
50
if c .ForTeam == nil {
51
51
return errors .New ("Team required for ball placement" )
52
52
}
53
- refBox .State .GameState = GameStateBallPlacement
54
- refBox .State .GameStateFor = c .ForTeam
53
+ RefBox .State .GameState = GameStateBallPlacement
54
+ RefBox .State .GameStateFor = c .ForTeam
55
55
case CommandGoal :
56
56
if c .ForTeam == nil {
57
57
return errors .New ("Team required for goal" )
58
58
}
59
- refBox .State .TeamState [* c .ForTeam ].Goals ++
59
+ RefBox .State .TeamState [* c .ForTeam ].Goals ++
60
60
case CommandTimeout :
61
61
if c .ForTeam == nil {
62
62
return errors .New ("Team required for timeout" )
63
63
}
64
- refBox .State .TeamState [* c .ForTeam ].TimeoutsLeft --
65
- refBox .State .GameState = GameStateTimeout
66
- refBox .State .GameStateFor = c .ForTeam
64
+ RefBox .State .TeamState [* c .ForTeam ].TimeoutsLeft --
65
+ RefBox .State .GameState = GameStateTimeout
66
+ RefBox .State .GameStateFor = c .ForTeam
67
67
default :
68
68
return errors .Errorf ("Unknown command: %v" , c )
69
69
}
@@ -76,7 +76,7 @@ func processModify(m *EventModifyValue) error {
76
76
if m .ForTeam .Unknown () {
77
77
return errors .Errorf ("Unknown team: %v" , m .ForTeam )
78
78
}
79
- teamState := refBox .State .TeamState [m .ForTeam ]
79
+ teamState := RefBox .State .TeamState [m .ForTeam ]
80
80
if m .Goals != nil {
81
81
teamState .Goals = * m .Goals
82
82
} else if m .Goalie != nil {
@@ -91,7 +91,7 @@ func processModify(m *EventModifyValue) error {
91
91
teamState .Name = * m .TeamName
92
92
} else if m .OnPositiveHalf != nil {
93
93
teamState .OnPositiveHalf = * m .OnPositiveHalf
94
- refBox .State .TeamState [m .ForTeam .Opposite ()].OnPositiveHalf = ! * m .OnPositiveHalf
94
+ RefBox .State .TeamState [m .ForTeam .Opposite ()].OnPositiveHalf = ! * m .OnPositiveHalf
95
95
} else if m .YellowCardTime != nil {
96
96
cardId := m .YellowCardTime .CardID
97
97
if cardId < 0 || cardId >= len (teamState .YellowCardTimes ) {
@@ -114,11 +114,11 @@ func processModify(m *EventModifyValue) error {
114
114
}
115
115
116
116
func processStage (s * EventStage ) error {
117
- if refBox .State .GameState != GameStateHalted && refBox .State .GameState != GameStateStopped {
117
+ if RefBox .State .GameState != GameStateHalted && RefBox .State .GameState != GameStateStopped {
118
118
return errors .New ("The game state must be halted or stopped to change the stage" )
119
119
}
120
120
121
- index , err := refBox .State .Stage .index ()
121
+ index , err := RefBox .State .Stage .index ()
122
122
if err != nil {
123
123
return err
124
124
}
@@ -127,28 +127,28 @@ func processStage(s *EventStage) error {
127
127
if nextIndex >= len (Stages ) {
128
128
return errors .New ("No next stage" )
129
129
}
130
- refBox .State .Stage = Stages [nextIndex ]
130
+ RefBox .State .Stage = Stages [nextIndex ]
131
131
} else if s .StageOperation == StagePrevious {
132
132
nextIndex := index - 1
133
133
if nextIndex < 0 {
134
134
return errors .New ("No previous stage" )
135
135
}
136
- refBox .State .Stage = Stages [nextIndex ]
136
+ RefBox .State .Stage = Stages [nextIndex ]
137
137
} else {
138
138
return errors .Errorf ("Unknown stage operation: %v" , s .StageOperation )
139
139
}
140
140
141
- refBox .State .StageTimeLeft = refBox .StageTimes [refBox .State .Stage ]
142
- refBox .State .StageTimeElapsed = 0
141
+ RefBox .State .StageTimeLeft = RefBox .StageTimes [RefBox .State .Stage ]
142
+ RefBox .State .StageTimeElapsed = 0
143
143
144
- if refBox .State .Stage == StageFirstHalf {
145
- refBox .MatchTimeStart = time .Now ()
144
+ if RefBox .State .Stage == StageFirstHalf {
145
+ RefBox .MatchTimeStart = time .Now ()
146
146
}
147
- if refBox .State .Stage == StageOvertimeFirstHalfPre {
148
- refBox .State .TeamState [TeamYellow ].TimeoutsLeft = refBox .Config .Overtime .Timeouts
149
- refBox .State .TeamState [TeamYellow ].TimeoutTimeLeft = refBox .Config .Overtime .TimeoutDuration
150
- refBox .State .TeamState [TeamBlue ].TimeoutsLeft = refBox .Config .Overtime .Timeouts
151
- refBox .State .TeamState [TeamBlue ].TimeoutTimeLeft = refBox .Config .Overtime .TimeoutDuration
147
+ if RefBox .State .Stage == StageOvertimeFirstHalfPre {
148
+ RefBox .State .TeamState [TeamYellow ].TimeoutsLeft = RefBox .Config .Overtime .Timeouts
149
+ RefBox .State .TeamState [TeamYellow ].TimeoutTimeLeft = RefBox .Config .Overtime .TimeoutDuration
150
+ RefBox .State .TeamState [TeamBlue ].TimeoutsLeft = RefBox .Config .Overtime .Timeouts
151
+ RefBox .State .TeamState [TeamBlue ].TimeoutTimeLeft = RefBox .Config .Overtime .TimeoutDuration
152
152
}
153
153
154
154
log .Printf ("Processed stage %v" , s .StageOperation )
@@ -163,7 +163,7 @@ func processCard(card *EventCard) error {
163
163
if card .Type != CardTypeYellow && card .Type != CardTypeRed {
164
164
return errors .Errorf ("Unknown card type: %v" , card .Type )
165
165
}
166
- teamState := refBox .State .TeamState [card .ForTeam ]
166
+ teamState := RefBox .State .TeamState [card .ForTeam ]
167
167
if card .Operation == CardOperationAdd {
168
168
return addCard (card , teamState )
169
169
} else if card .Operation == CardOperationRevoke {
@@ -190,7 +190,7 @@ func addCard(card *EventCard, teamState *TeamInfo) error {
190
190
if card .Type == CardTypeYellow {
191
191
log .Printf ("Add yellow card for team %v" , card .ForTeam )
192
192
teamState .YellowCards ++
193
- teamState .YellowCardTimes = append (teamState .YellowCardTimes , refBox .Config .Global .YellowCardDuration )
193
+ teamState .YellowCardTimes = append (teamState .YellowCardTimes , RefBox .Config .Global .YellowCardDuration )
194
194
} else if card .Type == CardTypeRed {
195
195
log .Printf ("Add red card for team %v" , card .ForTeam )
196
196
teamState .RedCards ++
@@ -200,14 +200,14 @@ func addCard(card *EventCard, teamState *TeamInfo) error {
200
200
201
201
func processTrigger (t * EventTrigger ) error {
202
202
if t .Type == TriggerResetMatch {
203
- refBox .State = NewState (refBox .Config )
204
- refBox .MatchTimeStart = time .Unix (0 , 0 )
203
+ RefBox .State = NewState (RefBox .Config )
204
+ RefBox .MatchTimeStart = time .Unix (0 , 0 )
205
205
} else if t .Type == TriggerSwitchColor {
206
- yellow := refBox .State .TeamState [TeamYellow ]
207
- refBox .State .TeamState [TeamYellow ] = refBox .State .TeamState [TeamBlue ]
208
- refBox .State .TeamState [TeamBlue ] = yellow
206
+ yellow := RefBox .State .TeamState [TeamYellow ]
207
+ RefBox .State .TeamState [TeamYellow ] = RefBox .State .TeamState [TeamBlue ]
208
+ RefBox .State .TeamState [TeamBlue ] = yellow
209
209
} else if t .Type == TriggerUndo {
210
- refBox .UndoLastAction ()
210
+ RefBox .UndoLastAction ()
211
211
} else {
212
212
return errors .Errorf ("Unknown trigger: %v" , t .Type )
213
213
}
0 commit comments