Skip to content

Commit 03279ac

Browse files
committed
[feature] Add reset game event
1 parent 8015b2a commit 03279ac

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

internal/app/controller/engine.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ func (e *Engine) SendCommand(command RefCommand, forTeam Team) {
5050
e.State.Command = command
5151
e.State.CommandFor = forTeam
5252
e.LogCommand()
53+
54+
if command.RunningState() && e.State.GameEvent != GameEventNone {
55+
e.SendGameEvent(GameEventNone, "")
56+
}
5357
}
5458

5559
func (e *Engine) SendGameEvent(gameEvent GameEventType, forTeam Team) {

internal/app/controller/gameEvents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "time"
55
type GameEventType string
66

77
const (
8-
GameEventUnknown GameEventType = "unknown"
8+
GameEventNone GameEventType = "none"
99
GameEventBallLeftFieldTouchLine GameEventType = "ballLeftFieldTouchLine"
1010
GameEventBallLeftFieldGoalLine GameEventType = "ballLeftFieldGoalLine"
1111
)

internal/app/controller/state.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ const (
156156
CommandBallPlacement RefCommand = "ballPlacement"
157157
)
158158

159+
func (c RefCommand) RunningState() bool {
160+
switch c {
161+
case CommandNormalStart, CommandForceStart, CommandDirect, CommandIndirect:
162+
return true
163+
default:
164+
return false
165+
}
166+
}
167+
159168
// GameState of a game
160169
type GameState string
161170

@@ -211,7 +220,7 @@ func NewState() (s *State) {
211220
s = new(State)
212221
s.Stage = StagePreGame
213222
s.Command = CommandHalt
214-
s.GameEvent = GameEventUnknown
223+
s.GameEvent = GameEventNone
215224

216225
s.StageTimeLeft = 0
217226
s.StageTimeElapsed = 0

src/components/GameState.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<template>
22
<div>
3+
<span v-b-tooltip.hover title="Last game event" v-if="state.gameEvent !== 'none'">
4+
{{state.gameEvent}} <span v-if="state.gameEventForTeam !== ''">({{state.gameEventForTeam}})</span>
5+
|
6+
</span>
7+
38
<span v-b-tooltip.hover title="The current stage of the game">
49
{{state.stage}}
510
</span>
@@ -22,10 +27,6 @@
2227
<span v-b-tooltip.hover title="Current command">
2328
{{state.command}} <span v-if="state.commandForTeam !== ''">for {{state.commandForTeam}}</span>
2429
</span>
25-
|
26-
<span v-b-tooltip.hover title="Last game event">
27-
{{state.gameEvent}} <span v-if="state.gameEventForTeam !== ''">for {{state.gameEventForTeam}}</span>
28-
</span>
2930
</div>
3031
</template>
3132

src/components/events/Events.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
:per-page="perPage">
99
</b-pagination>
1010

11-
<b-btn v-b-modal.new-event-modal size="sm" variant="primary">New</b-btn>
11+
<b-btn v-b-modal.new-event-modal size="sm" variant="primary" :disabled="newEventDisabled">New</b-btn>
1212
<b-modal id="new-event-modal"
1313
title="New Game Event"
1414
:lazy="true">
@@ -37,6 +37,12 @@
3737
computed: {
3838
events() {
3939
return this.$store.state.gameEvents;
40+
},
41+
state() {
42+
return this.$store.state.refBoxState
43+
},
44+
newEventDisabled() {
45+
return this.state.command !== 'stop' && this.state.command !== 'halt';
4046
}
4147
},
4248
}

src/store.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class RefBoxState {
2222
stage = 'unknown';
2323
command = 'unknown';
2424
commandForTeam = '';
25-
gameEvent = 'unknown';
25+
gameEvent = 'none';
2626
gameEventForTeam = '';
2727
stageTimeElapsed = 0;
2828
stageTimeLeft = 0;

0 commit comments

Comments
 (0)