Skip to content

Commit 1eb18fd

Browse files
committed
Add globally unique id to GameEvent and connect it with proposal group
1 parent 4b64278 commit 1eb18fd

File tree

6 files changed

+35
-5
lines changed

6 files changed

+35
-5
lines changed

frontend/src/helpers/ChangeDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function changeDetails(change: Change): ChangeDetails {
129129
const details = changeDetails.acceptProposalGroupChange;
130130
return {
131131
typeName: "Proposals accepted",
132-
title: `Proposal ${details.groupId!} accepted by ${details.acceptedBy}`,
132+
title: `Proposal accepted by ${details.acceptedBy}: '${details.groupId!}'`,
133133
icon: "check_circle_outline",
134134
}
135135
}

frontend/src/proto/ssl_gc_game_event.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { Vector2 } from "./ssl_gc_geometry";
1111
* An autoRef should ideally set all fields, except if there are good reasons to not do so.
1212
*/
1313
export interface GameEvent {
14+
/** A globally unique id of the game event. */
15+
id?: string;
16+
/** The type of the game event. */
1417
type?: GameEvent_Type;
1518
/**
1619
* The origins of this game event.
@@ -856,6 +859,7 @@ export interface GameEvent_PenaltyKickFailed {
856859
export const GameEvent = {
857860
fromJSON(object: any): GameEvent {
858861
return {
862+
id: isSet(object.id) ? String(object.id) : "",
859863
type: isSet(object.type) ? gameEvent_TypeFromJSON(object.type) : GameEvent_Type.UNKNOWN_GAME_EVENT_TYPE,
860864
origin: Array.isArray(object?.origin) ? object.origin.map((e: any) => String(e)) : [],
861865
createdTimestamp: isSet(object.createdTimestamp) ? Number(object.createdTimestamp) : 0,
@@ -1033,6 +1037,7 @@ export const GameEvent = {
10331037

10341038
toJSON(message: GameEvent): unknown {
10351039
const obj: any = {};
1040+
message.id !== undefined && (obj.id = message.id);
10361041
message.type !== undefined && (obj.type = gameEvent_TypeToJSON(message.type));
10371042
if (message.origin) {
10381043
obj.origin = message.origin.map((e) => e);

internal/app/engine/engine.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/statemachine"
88
"github.com/RoboCup-SSL/ssl-game-controller/internal/app/store"
99
"github.com/RoboCup-SSL/ssl-game-controller/pkg/timer"
10+
"github.com/google/uuid"
1011
"github.com/pkg/errors"
1112
"google.golang.org/protobuf/proto"
1213
"google.golang.org/protobuf/types/known/durationpb"
@@ -151,6 +152,13 @@ func (e *Engine) processGameEvent(gameEvent *state.GameEvent) *state.GameEvent {
151152
gameEvent.CreatedTimestamp = new(uint64)
152153
*gameEvent.CreatedTimestamp = uint64(e.timeProvider().UnixMicro())
153154

155+
// Set unique id
156+
if gameEvent.Id != nil {
157+
log.Printf("Ignore existing id in enqueued game event: %v", gameEvent)
158+
}
159+
gameEvent.Id = new(string)
160+
*gameEvent.Id = uuid.NewString()
161+
154162
// convert aimless kick if necessary
155163
if e.currentState.Division.Div() == config.DivA && *gameEvent.Type == state.GameEvent_AIMLESS_KICK {
156164
return convertAimlessKick(gameEvent)

internal/app/state/ssl_gc_game_event.pb.go

Lines changed: 13 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/app/statemachine/change_acceptproposal.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func (s *StateMachine) processChangeAcceptProposals(newState *state.State, chang
1414
return
1515
}
1616

17-
majorityEvent := s.createMergedGameEvent(group.Proposals, change.AcceptedBy)
17+
majorityEvent := s.createMergedGameEvent(group, change.AcceptedBy)
1818
changes = append(changes, &Change{
1919
Change: &Change_AddGameEventChange{
2020
AddGameEventChange: &Change_AddGameEvent{
@@ -37,10 +37,12 @@ func findGroupById(groups []*state.ProposalGroup, id string) *state.ProposalGrou
3737
return nil
3838
}
3939

40-
func (s *StateMachine) createMergedGameEvent(proposals []*state.Proposal, acceptedBy *string) *state.GameEvent {
40+
func (s *StateMachine) createMergedGameEvent(group *state.ProposalGroup, acceptedBy *string) *state.GameEvent {
41+
proposals := group.Proposals
4142
event := new(state.GameEvent)
4243
proto.Merge(event, proposals[0].GameEvent)
4344
event.Origin = []string{}
45+
event.Id = group.Id
4446
byTeam := map[state.Team]int{}
4547
origins := map[string]struct{}{}
4648
for _, e := range proposals {

proto/ssl_gc_game_event.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import "ssl_gc_geometry.proto";
1313
// An autoRef should ideally set all fields, except if there are good reasons to not do so.
1414
message GameEvent {
1515

16+
// A globally unique id of the game event.
17+
optional string id = 50;
18+
19+
// The type of the game event.
1620
optional Type type = 40;
1721

1822
// The origins of this game event.

0 commit comments

Comments
 (0)