Skip to content

Commit 3af538f

Browse files
committed
Add timestamp to fouls to make invalid goal detection work
1 parent 4d684de commit 3af538f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

internal/app/state/teaminfo.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package state
22

33
import (
44
"google.golang.org/protobuf/types/known/durationpb"
5+
"google.golang.org/protobuf/types/known/timestamppb"
56
"time"
67
)
78

@@ -59,15 +60,17 @@ func (x *TeamInfo) AddRedCard(causedByGameEvent *GameEvent) {
5960
}
6061

6162
// AddFoul adds a new foul to the team
62-
func (x *TeamInfo) AddFoul(causedByGameEvent *GameEvent) {
63+
func (x *TeamInfo) AddFoul(causedByGameEvent *GameEvent, ts time.Time) {
6364
id := uint32(0)
64-
numCards := len(x.Fouls)
65-
if numCards > 0 {
66-
id = *x.Fouls[numCards-1].Id + 1
65+
numFouls := len(x.Fouls)
66+
if numFouls > 0 {
67+
id = *x.Fouls[numFouls-1].Id + 1
6768
}
69+
timestamp := timestamppb.New(ts)
6870
x.Fouls = append(x.Fouls, &Foul{
6971
Id: &id,
7072
CausedByGameEvent: causedByGameEvent,
73+
Timestamp: timestamp,
7174
})
7275
return
7376
}

internal/app/statemachine/change_gameevent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (s *StateMachine) processChangeAddGameEvent(newState *state.State, change *
3838
for _, team := range state.BothTeams() {
3939
if byTeam == state.Team_UNKNOWN || byTeam == team {
4040
log.Printf("Team %v got a foul for %v", byTeam, gameEvent)
41-
newState.TeamInfo(team).AddFoul(gameEvent)
41+
newState.TeamInfo(team).AddFoul(gameEvent, s.timeProvider())
4242
numFouls := len(newState.TeamInfo(team).Fouls)
4343
if numFouls%3 == 0 {
4444
var causedGameEvents []*state.GameEvent

0 commit comments

Comments
 (0)