Skip to content

Commit 46b73fe

Browse files
committed
[feature] Store first kickoff team and update next command during pre's
1 parent a3ebe86 commit 46b73fe

File tree

4 files changed

+126
-16
lines changed

4 files changed

+126
-16
lines changed

internal/app/controller/engine.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
type GameControllerState struct {
1717
Division config.Division `json:"division" yaml:"division"`
1818
AutoContinue bool `json:"autoContinue" yaml:"autoContinue"`
19+
FirstKickoffTeam Team `json:"firstKickoffTeam" yaml:"firstKickoffTeam"`
1920
GameEventBehavior map[GameEventType]GameEventBehavior `json:"gameEventBehavior" yaml:"gameEventBehavior"`
2021
GameEventProposals []*GameEventProposal `json:"gameEventProposals" yaml:"gameEventProposals"`
2122
AutoRefsConnected []string `json:"autoRefsConnected" yaml:"autoRefsConnected"`
@@ -29,6 +30,7 @@ func NewGameControllerState() (s *GameControllerState) {
2930

3031
s.Division = config.DivA
3132
s.AutoContinue = true
33+
s.FirstKickoffTeam = TeamYellow
3234

3335
s.GameEventBehavior = map[GameEventType]GameEventBehavior{}
3436
for _, event := range AllGameEvents() {
@@ -113,6 +115,8 @@ func (e *Engine) ResetGame() {
113115
e.State.TeamState[team].TimeoutsLeft = e.config.Normal.Timeouts
114116
e.State.TeamState[team].MaxAllowedBots = e.config.MaxBots[e.GcState.Division]
115117
}
118+
119+
e.updateNextCommandForStage()
116120
}
117121

118122
// Update updates times and triggers events if needed
@@ -535,6 +539,9 @@ func (e *Engine) processModify(m *EventModifyValue) error {
535539
}
536540
} else if m.AutoContinue != nil {
537541
e.GcState.AutoContinue = *m.AutoContinue
542+
} else if m.FirstKickoffTeam != nil {
543+
e.GcState.FirstKickoffTeam = Team(*m.FirstKickoffTeam)
544+
e.updateNextCommandForStage()
538545
} else if m.GameEventBehavior != nil {
539546
e.GcState.GameEventBehavior[m.GameEventBehavior.GameEventType] = m.GameEventBehavior.GameEventBehavior
540547
} else if m.RemoveGameEvent != nil {
@@ -670,6 +677,20 @@ func (e *Engine) updateStage(stage Stage) {
670677
}
671678

672679
e.State.Stage = stage
680+
681+
e.updateNextCommandForStage()
682+
}
683+
684+
func (e *Engine) updateNextCommandForStage() {
685+
switch e.State.Stage {
686+
case StagePreGame, StageOvertimeFirstHalfPre:
687+
e.State.NextCommand = CommandKickoff
688+
e.State.NextCommandFor = e.GcState.FirstKickoffTeam
689+
690+
case StageSecondHalfPre, StageOvertimeSecondHalfPre:
691+
e.State.NextCommand = CommandKickoff
692+
e.State.NextCommandFor = e.GcState.FirstKickoffTeam.Opposite()
693+
}
673694
}
674695

675696
func (e *Engine) updatePreStages() {

internal/app/controller/events.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ type EventModifyValue struct {
117117
CanPlaceBall *bool `json:"canPlaceBall,omitempty" yaml:"canPlaceBall"`
118118
Division *config.Division `json:"division,omitempty" yaml:"division"`
119119
AutoContinue *bool `json:"autoContinue,omitempty" yaml:"autoContinue"`
120+
FirstKickoffTeam *string `json:"firstKickoffTeam,omitempty" yaml:"firstKickoffTeam"`
120121
GameEventBehavior *EventModifyGameEventBehavior `json:"gameEventBehavior,omitempty" yaml:"gameEventBehavior"`
121122
BotSubstitutionIntend *bool `json:"botSubstitutionIntend,omitempty" yaml:"botSubstitutionIntend"`
122123
RemoveGameEvent *int `json:"removeGameEvent,omitempty" yaml:"removeGameEvent"`

src/components/common/DualSwitch.vue

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<template>
2+
<div class="switch btn-group-toggle btn-group">
3+
<label v-b-tooltip.hover
4+
:title="leftTitle"
5+
:class="{btn:true, 'btn-active': (selectedValue === leftValue), 'btn-passive': (selectedValue !== leftValue)}"
6+
@click="callback(leftValue)"
7+
:disabled="disabled">
8+
{{leftLabel}}
9+
</label>
10+
<label v-b-tooltip.hover
11+
:title="rightTitle"
12+
:class="{btn:true, 'btn-active': (selectedValue === rightValue), 'btn-passive': (selectedValue !== rightValue)}"
13+
@click="callback(rightValue)"
14+
:disabled="disabled">
15+
{{rightLabel}}
16+
</label>
17+
</div>
18+
</template>
19+
20+
<script>
21+
export default {
22+
name: "DualSwitch",
23+
props: {
24+
leftTitle: String,
25+
leftLabel: String,
26+
leftValue: String,
27+
rightTitle: String,
28+
rightLabel: String,
29+
rightValue: String,
30+
callback: {
31+
type: Function,
32+
default: function () {
33+
}
34+
},
35+
selectedValue: {
36+
type: String,
37+
default: ''
38+
},
39+
disabled: {
40+
type: Boolean,
41+
default: false
42+
},
43+
}
44+
}
45+
</script>
46+
47+
<style scoped>
48+
49+
button, .switch {
50+
margin: 0.5em;
51+
}
52+
53+
.btn-active {
54+
background-color: green;
55+
border-color: green;
56+
color: white;
57+
}
58+
59+
.btn-passive {
60+
background-color: red;
61+
border-color: red;
62+
color: white;
63+
}
64+
65+
</style>

src/components/settings/MatchSettings.vue

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
<template>
22
<div>
3+
<p>
4+
<label>First kickoff team: </label>
5+
<DualSwitch
6+
left-label="Yellow"
7+
left-value="Yellow"
8+
right-label="Blue"
9+
right-value="Blue"
10+
:callback="switchFirstKickoffTeam"
11+
:selected-value="firstKickoffTeam"
12+
/>
13+
</p>
14+
315
<b-button v-b-tooltip.hover title="Switch the colors of the teams, keep everything else"
416
v-on:click="switchColor"
517
:disabled="forbidMatchControls">
@@ -12,17 +24,15 @@
1224
Switch sides
1325
</b-button>
1426

15-
<div class="divisions btn-group-toggle btn-group">
16-
<label :class="{btn:true, 'btn-secondary': true, active: isDivA, disabled: forbidMatchControls}"
17-
@click="switchDivision('DivA')"
18-
:disabled="forbidMatchControls">
19-
Div A
20-
</label>
21-
<label :class="{btn:true, 'btn-secondary': true, active: !isDivA, disabled: forbidMatchControls}"
22-
@click="switchDivision('DivB')">
23-
Div B
24-
</label>
25-
</div>
27+
<DualSwitch
28+
left-label="Div A"
29+
left-value="DivA"
30+
right-label="Div B"
31+
right-value="DivB"
32+
:callback="switchDivision"
33+
:selected-value="division"
34+
:disabled="forbidMatchControls"
35+
/>
2636

2737
<b-button v-b-tooltip.hover title="Start a new match by resetting everything"
2838
v-on:click="showMsgBoxConfirmResetGame">
@@ -32,11 +42,16 @@
3242
</template>
3343

3444
<script>
45+
import TeamSelection from "../common/TeamSelection";
46+
import DualSwitch from "../common/DualSwitch";
3547
export default {
3648
name: "MatchSettings",
49+
components: {DualSwitch, TeamSelection},
3750
data() {
3851
return {
39-
selected: 'DivA',
52+
kickoffTeamSelectionModel: {
53+
team: null,
54+
}
4055
}
4156
},
4257
methods: {
@@ -55,9 +70,14 @@
5570
'trigger': {'triggerType': 'switchSides'}
5671
})
5772
},
58-
switchDivision(division) {
73+
switchDivision(div) {
5974
this.$socket.sendObj({
60-
'modify': {'division': division}
75+
'modify': {'division': div}
76+
})
77+
},
78+
switchFirstKickoffTeam(team) {
79+
this.$socket.sendObj({
80+
'modify': {'firstKickoffTeam': team}
6181
})
6282
},
6383
showMsgBoxConfirmResetGame() {
@@ -86,8 +106,11 @@
86106
state() {
87107
return this.$store.state.refBoxState
88108
},
89-
isDivA() {
90-
return this.$store.state.gcState.division === 'DivA';
109+
firstKickoffTeam() {
110+
return this.$store.state.gcState.firstKickoffTeam;
111+
},
112+
division() {
113+
return this.$store.state.gcState.division;
91114
},
92115
halted() {
93116
return this.state.command === 'halt';

0 commit comments

Comments
 (0)