Skip to content

Commit e3e2584

Browse files
committed
[feature] Use uuids instead of global counter for protocol entries
1 parent 47df2c8 commit e3e2584

File tree

6 files changed

+17
-23
lines changed

6 files changed

+17
-23
lines changed

internal/app/controller/engine.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@ import (
1010
"sort"
1111
"strconv"
1212
"strings"
13-
"sync"
1413
"time"
1514
)
1615

1716
type GameControllerState struct {
18-
Division config.Division `json:"division" yaml:"division"`
19-
AutoContinue bool `json:"autoContinue" yaml:"autoContinue"`
20-
GameEventBehavior map[GameEventType]GameEventBehavior `json:"gameEventBehavior" yaml:"gameEventBehavior"`
21-
GameEventProposals []*GameEventProposal `json:"gameEventProposals" yaml:"gameEventProposals"`
22-
AutoRefsConnected []string `json:"autoRefsConnected" yaml:"autoRefsConnected"`
23-
TeamConnected map[Team]bool `json:"teamConnected" yaml:"teamConnected"`
24-
TeamConnectionVerified map[Team]bool `json:"teamConnectionVerified" yaml:"teamConnectionVerified"`
25-
MatchState *State `json:"matchState" yaml:"matchState"`
26-
ProtocolEntryIdCounter int `json:"protocolEntryIdCounter" yaml:"protocolEntryIdCounter"`
27-
ProtocolEntryIdCounterMutex sync.Mutex `json:"protocolEntryIdCounterMutex" yaml:"protocolEntryIdCounterMutex"`
17+
Division config.Division `json:"division" yaml:"division"`
18+
AutoContinue bool `json:"autoContinue" yaml:"autoContinue"`
19+
GameEventBehavior map[GameEventType]GameEventBehavior `json:"gameEventBehavior" yaml:"gameEventBehavior"`
20+
GameEventProposals []*GameEventProposal `json:"gameEventProposals" yaml:"gameEventProposals"`
21+
AutoRefsConnected []string `json:"autoRefsConnected" yaml:"autoRefsConnected"`
22+
TeamConnected map[Team]bool `json:"teamConnected" yaml:"teamConnected"`
23+
TeamConnectionVerified map[Team]bool `json:"teamConnectionVerified" yaml:"teamConnectionVerified"`
24+
MatchState *State `json:"matchState" yaml:"matchState"`
2825
}
2926

3027
func NewGameControllerState() (s *GameControllerState) {
@@ -490,7 +487,7 @@ func (e *Engine) processEvent(event Event) error {
490487
return errors.New("unknown event")
491488
}
492489

493-
func (e *Engine) processRevertProtocolEntry(id int) error {
490+
func (e *Engine) processRevertProtocolEntry(id string) error {
494491
err := e.PersistentState.RevertProtocolEntry(id)
495492
if err != nil {
496493
return err

internal/app/controller/engineHistory.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (s *PersistentState) Prune() {
4343
}
4444

4545
// GetProtocolEntry returns the protocol entry with given id
46-
func (s *PersistentState) GetProtocolEntry(id int) *ProtocolEntry {
46+
func (s *PersistentState) GetProtocolEntry(id string) *ProtocolEntry {
4747
for i := len(s.Protocol) - 1; i > 0; i-- {
4848
if s.Protocol[i].Id == id {
4949
return s.Protocol[i]
@@ -53,7 +53,7 @@ func (s *PersistentState) GetProtocolEntry(id int) *ProtocolEntry {
5353
}
5454

5555
// GetProtocolEntry returns the protocol entry with given id
56-
func (s *PersistentState) RevertProtocolEntry(id int) error {
56+
func (s *PersistentState) RevertProtocolEntry(id string) error {
5757
for i := len(s.Protocol) - 1; i > 0; i-- {
5858
entry := s.Protocol[i]
5959
if entry.Id == id {

internal/app/controller/engine_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ func processTransitionFile(t *testing.T, fileName string) {
142142
// override these, as we do not want to test them
143143
expectedState.MatchState.PrevCommands = e.State.PrevCommands
144144
expectedState.MatchState.PrevCommandsFor = e.State.PrevCommandsFor
145-
expectedState.ProtocolEntryIdCounter = e.GcState.ProtocolEntryIdCounter
146145

147146
// check if the engine state is equal to the expected state
148147
if diff := deep.Equal(*e.GcState, expectedState); diff != nil {

internal/app/controller/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ type Event struct {
168168
Stage *EventStage `json:"stage" yaml:"stage"`
169169
Trigger *EventTrigger `json:"trigger" yaml:"trigger"`
170170
GameEvent *GameEvent `json:"gameEvent" yaml:"gameEvent"`
171-
RevertProtocolEntry *int `json:"revertProtocolEntry,omitempty" yaml:"revertProtocolEntry"`
171+
RevertProtocolEntry *string `json:"revertProtocolEntry,omitempty" yaml:"revertProtocolEntry"`
172172
}
173173

174174
func (e Event) String() string {

internal/app/controller/protocol.go

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

33
import (
44
"fmt"
5+
"github.com/odeke-em/go-uuid"
56
"log"
67
"time"
78
)
@@ -30,16 +31,13 @@ const (
3031
UiProtocolHint UiProtocolType = "hint"
3132
)
3233

33-
func (e *Engine) newGlobalProtocolEntryId() int {
34-
defer e.GcState.ProtocolEntryIdCounterMutex.Unlock()
35-
e.GcState.ProtocolEntryIdCounterMutex.Lock()
36-
e.GcState.ProtocolEntryIdCounter++
37-
return e.GcState.ProtocolEntryIdCounter
34+
func (e *Engine) newGlobalProtocolEntryId() string {
35+
return uuid.New()
3836
}
3937

4038
// ProtocolEntry represents a single protocol entry as should be displayed in the UI table
4139
type ProtocolEntry struct {
42-
Id int `json:"id"`
40+
Id string `json:"id"`
4341
Timestamp int64 `json:"timestamp"`
4442
StageTime time.Duration `json:"stageTime"`
4543
Type UiProtocolType `json:"type"`

src/components/events/EventTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
},
8787
revertProtocolEntry(id) {
8888
this.$socket.sendObj({
89-
'revertProtocolEntry': Number(id)
89+
'revertProtocolEntry': id
9090
})
9191
},
9292
iconForType(type) {

0 commit comments

Comments
 (0)