Skip to content

Commit 83c51a8

Browse files
committed
[feature] Add goalkeeper or bot subst. intend change to ui protocol
1 parent 9fd453b commit 83c51a8

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

internal/app/controller/teamConnection.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ func (c *GameController) ProcessTeamRequests(teamName string, request refproto.T
6060
}
6161

6262
if x, ok := request.GetRequest().(*refproto.TeamToControllerRequest_SubstituteBot); ok {
63-
log.Printf("Team %v updated bot substituation intend to %v", team, x.SubstituteBot)
64-
c.Engine.State.TeamState[team].BotSubstitutionIntend = x.SubstituteBot
63+
if c.Engine.State.TeamState[team].BotSubstitutionIntend != x.SubstituteBot {
64+
log.Printf("Team %v updated bot substituation intend to %v", team, x.SubstituteBot)
65+
c.Engine.State.TeamState[team].BotSubstitutionIntend = x.SubstituteBot
66+
c.Engine.LogTeamBotSubstitutionChange(team, x.SubstituteBot)
67+
}
68+
return nil
6569
}
6670

6771
if c.Engine.State.GameState() != GameStateStopped {
@@ -73,6 +77,7 @@ func (c *GameController) ProcessTeamRequests(teamName string, request refproto.T
7377
return errors.Errorf("Goalkeeper id is invalid: %v", x.DesiredKeeper)
7478
}
7579
log.Printf("Changing keeper for team %v to %v", team, x.DesiredKeeper)
80+
c.Engine.LogTeamGoalkeeperChange(team, c.Engine.State.TeamState[team].Goalkeeper, int(x.DesiredKeeper))
7681
c.Engine.State.TeamState[team].Goalkeeper = int(x.DesiredKeeper)
7782
}
7883

internal/app/controller/uiProtocol.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const (
2323
UiProtocolGameEventIgnored UiProtocolType = "ignoredGameEvent"
2424
// UiProtocolModify represents a manual modification on the state
2525
UiProtocolModify UiProtocolType = "modify"
26+
// UiProtocolTeamAction represents an action from a team
27+
UiProtocolTeamAction UiProtocolType = "teamAction"
2628
)
2729

2830
// UiProtocolEntry represents a single protocol entry as should be displayed in the UI table
@@ -125,3 +127,31 @@ func (e *Engine) LogModify(m EventModifyValue) {
125127
}
126128
e.UiProtocol = append(e.UiProtocol, entry)
127129
}
130+
131+
// LogTeamGoalkeeperChange adds a goalkeeper change from a team to the protocol
132+
func (e *Engine) LogTeamGoalkeeperChange(forTeam Team, oldGoalkeeperId int, newGoalkeeperId int) {
133+
description := fmt.Sprintf("%v -> %v", oldGoalkeeperId, newGoalkeeperId)
134+
entry := UiProtocolEntry{
135+
Timestamp: e.TimeProvider().UnixNano(),
136+
StageTime: e.State.StageTimeElapsed,
137+
Type: UiProtocolTeamAction,
138+
Name: "Goalkeeper",
139+
Team: forTeam,
140+
Description: description,
141+
}
142+
e.UiProtocol = append(e.UiProtocol, entry)
143+
}
144+
145+
// LogTeamBotSubstitutionChange adds a bot substitution intend change from a team to the protocol
146+
func (e *Engine) LogTeamBotSubstitutionChange(forTeam Team, substituteBot bool) {
147+
description := fmt.Sprintf("%v", substituteBot)
148+
entry := UiProtocolEntry{
149+
Timestamp: e.TimeProvider().UnixNano(),
150+
StageTime: e.State.StageTimeElapsed,
151+
Type: UiProtocolTeamAction,
152+
Name: "BotSubstitutionIntend",
153+
Team: forTeam,
154+
Description: description,
155+
}
156+
e.UiProtocol = append(e.UiProtocol, entry)
157+
}

0 commit comments

Comments
 (0)