From f272195e8b342e98f926a356b28c2da938db006f Mon Sep 17 00:00:00 2001 From: Nicolai Ommer Date: Sun, 6 Aug 2023 20:36:31 +0200 Subject: [PATCH] Combine game event proposals with accepted game events --- .../src/components/match/GameEventItem.vue | 11 ++- .../src/components/match/GameEventList.vue | 20 ------ .../match/GameEventProposalGroupItem.vue | 41 +++++++++-- .../match/GameEventProposalGroupItemList.vue | 25 ------- .../match/GameEventProposalItem.vue | 7 +- frontend/src/components/match/GameEvents.vue | 69 +++++++++++++++++++ frontend/src/views/MatchView.vue | 6 +- internal/app/engine/engine.go | 56 ++++++++------- internal/app/engine/process_proposals.go | 3 + 9 files changed, 148 insertions(+), 90 deletions(-) delete mode 100644 frontend/src/components/match/GameEventList.vue delete mode 100644 frontend/src/components/match/GameEventProposalGroupItemList.vue create mode 100644 frontend/src/components/match/GameEvents.vue diff --git a/frontend/src/components/match/GameEventItem.vue b/frontend/src/components/match/GameEventItem.vue index 5b85dc48..430a9d3e 100644 --- a/frontend/src/components/match/GameEventItem.vue +++ b/frontend/src/components/match/GameEventItem.vue @@ -5,10 +5,10 @@ import {gameEventNames} from "@/helpers/texts"; import type {GameEvent} from "@/proto/ssl_gc_game_event"; import {gameEventForTeam, originIcon} from "@/helpers"; import GameEventDetailsTree from "@/components/match/GameEventDetailsTree.vue"; +import dayjs from "dayjs"; const props = defineProps<{ gameEvent: GameEvent, - caption?: string, }>() const label = computed(() => { @@ -22,6 +22,13 @@ const team = computed(() => { const origins = computed(() => { return props.gameEvent.origin }) + +const time = computed(() => { + if (props.gameEvent.createdTimestamp) { + return dayjs(props.gameEvent.createdTimestamp / 1e3).format("MMM, DD YYYY HH:mm:ss,SSS") + } + return undefined +}) diff --git a/internal/app/engine/engine.go b/internal/app/engine/engine.go index dec495a9..04c4713f 100644 --- a/internal/app/engine/engine.go +++ b/internal/app/engine/engine.go @@ -82,27 +82,6 @@ func NewEngine(gameConfig config.Game, engineConfig config.Engine) (e *Engine) { // Enqueue adds the change to the change queue func (e *Engine) Enqueue(change *statemachine.Change) { - if change.GetAddGameEventChange() != nil { - change.GetAddGameEventChange().GameEvent = e.processGameEvent(change.GetAddGameEventChange().GameEvent) - change = e.handleGameEventBehavior(change) - if change == nil { - return - } - } else if change.GetAddPassiveGameEventChange() != nil { - change.GetAddPassiveGameEventChange().GameEvent = e.processGameEvent(change.GetAddPassiveGameEventChange().GameEvent) - } else if change.GetAddProposalChange() != nil { - log.Println("Ignoring unexpected proposal change: ", change.GetAddProposalChange()) - return - } - - if change.Revertible == nil { - change.Revertible = new(bool) - // Assume that changes from outside are by default revertible, except if the flag is already set - *change.Revertible = true - } - if change.Origin == nil { - change.Origin = proto.String("Unknown") - } e.changeQueue <- change } @@ -146,18 +125,16 @@ func isNonMajorityOrigin(origins []string) bool { func (e *Engine) processGameEvent(gameEvent *state.GameEvent) *state.GameEvent { // Set creation timestamp - if gameEvent.CreatedTimestamp != nil { - log.Printf("Ignore existing created_timestamp in enqueued game event: %v", gameEvent) + if gameEvent.CreatedTimestamp == nil { + gameEvent.CreatedTimestamp = new(uint64) + *gameEvent.CreatedTimestamp = uint64(e.timeProvider().UnixMicro()) } - gameEvent.CreatedTimestamp = new(uint64) - *gameEvent.CreatedTimestamp = uint64(e.timeProvider().UnixMicro()) // Set unique id - if gameEvent.Id != nil { - log.Printf("Ignore existing id in enqueued game event: %v", gameEvent) + if gameEvent.Id == nil { + gameEvent.Id = new(string) + *gameEvent.Id = uuid.NewString() } - gameEvent.Id = new(string) - *gameEvent.Id = uuid.NewString() // convert aimless kick if necessary if e.currentState.Division.Div() == config.DivA && *gameEvent.Type == state.GameEvent_AIMLESS_KICK { @@ -382,6 +359,27 @@ func (e *Engine) processChange(change *statemachine.Change) (newChanges []*state e.mutex.Lock() defer e.mutex.Unlock() + if change.GetAddGameEventChange() != nil { + change.GetAddGameEventChange().GameEvent = e.processGameEvent(change.GetAddGameEventChange().GameEvent) + change = e.handleGameEventBehavior(change) + if change == nil { + return + } + } else if change.GetAddPassiveGameEventChange() != nil { + change.GetAddPassiveGameEventChange().GameEvent = e.processGameEvent(change.GetAddPassiveGameEventChange().GameEvent) + } else if change.GetAddProposalChange() != nil { + change.GetAddProposalChange().Proposal.GameEvent = e.processGameEvent(change.GetAddProposalChange().Proposal.GameEvent) + } + + if change.Revertible == nil { + change.Revertible = new(bool) + // Assume that changes from outside are by default revertible, except if the flag is already set + *change.Revertible = true + } + if change.Origin == nil { + change.Origin = proto.String("Unknown") + } + var entry = e.stateStore.CreateEntry(change, e.timeProvider(), e.currentState) log.Printf("Process change %d: %+v", *entry.Id, change.StringJson()) diff --git a/internal/app/engine/process_proposals.go b/internal/app/engine/process_proposals.go index f1201b75..ceb927a9 100644 --- a/internal/app/engine/process_proposals.go +++ b/internal/app/engine/process_proposals.go @@ -46,6 +46,9 @@ func (e *Engine) uniqueAcceptingOrigins(group *state.ProposalGroup) int { origins := map[string]bool{} for _, p := range group.Proposals { for _, o := range p.GameEvent.Origin { + if _, ok := e.config.AutoRefConfigs[o]; !ok { + continue + } if e.config.AutoRefConfigs[o].GameEventBehavior[p.GameEvent.Type.String()] == AutoRefConfig_BEHAVIOR_ACCEPT { origins[o] = true }