Skip to content

Commit 1a5c8ce

Browse files
committed
[feature] Add new counters for each team for certain rules from 2018
1 parent 4837fef commit 1a5c8ce

File tree

9 files changed

+138
-33
lines changed

9 files changed

+138
-33
lines changed

internal/app/controller/engine.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ func (e *Engine) processModify(m *EventModifyValue) (*EventCommand, error) {
177177
} else if m.OnPositiveHalf != nil {
178178
teamState.OnPositiveHalf = *m.OnPositiveHalf
179179
e.State.TeamState[m.ForTeam.Opposite()].OnPositiveHalf = !*m.OnPositiveHalf
180+
} else if m.BotCollisions != nil {
181+
teamState.BotCollisions = *m.BotCollisions
182+
} else if m.BallPlacementFailures != nil {
183+
teamState.BallPlacementFailures = *m.BallPlacementFailures
184+
} else if m.BotSpeedInfringements != nil {
185+
teamState.BotSpeedInfringements = *m.BotSpeedInfringements
180186
} else if m.YellowCardTime != nil {
181187
cardId := m.YellowCardTime.CardID
182188
if cardId < 0 || cardId >= len(teamState.YellowCardTimes) {

internal/app/controller/events.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,18 @@ type EventModifyCardTime struct {
116116
type EventModifyValue struct {
117117
ForTeam Team `json:"forTeam"`
118118

119-
Goals *int `json:"goals"`
120-
Goalie *int `json:"goalie"`
121-
YellowCards *int `json:"yellowCards"`
122-
YellowCardTime *EventModifyCardTime `json:"yellowCardTime"`
123-
RedCards *int `json:"redCards"`
124-
TimeoutsLeft *int `json:"timeoutsLeft"`
125-
TimeoutTimeLeft *string `json:"timeoutTimeLeft"`
126-
OnPositiveHalf *bool `json:"onPositiveHalf"`
127-
TeamName *string `json:"teamName"`
119+
Goals *int `json:"goals"`
120+
Goalie *int `json:"goalie"`
121+
YellowCards *int `json:"yellowCards"`
122+
YellowCardTime *EventModifyCardTime `json:"yellowCardTime"`
123+
RedCards *int `json:"redCards"`
124+
TimeoutsLeft *int `json:"timeoutsLeft"`
125+
TimeoutTimeLeft *string `json:"timeoutTimeLeft"`
126+
OnPositiveHalf *bool `json:"onPositiveHalf"`
127+
TeamName *string `json:"teamName"`
128+
BotCollisions *int `json:"botCollisions"`
129+
BallPlacementFailures *int `json:"ballPlacementFailures"`
130+
BotSpeedInfringements *int `json:"botSpeedInfringements"`
128131
}
129132

130133
func (m EventModifyValue) String() string {
@@ -156,6 +159,15 @@ func (m EventModifyValue) String() string {
156159
if m.TeamName != nil {
157160
return fmt.Sprintf("%v TeamName=%v", str, *m.TeamName)
158161
}
162+
if m.BotCollisions != nil {
163+
return fmt.Sprintf("%v BotCollisions=%v", str, *m.BotCollisions)
164+
}
165+
if m.BallPlacementFailures != nil {
166+
return fmt.Sprintf("%v BallPlacementFailures=%v", str, *m.BallPlacementFailures)
167+
}
168+
if m.BotSpeedInfringements != nil {
169+
return fmt.Sprintf("%v BotSpeedInfringements=%v", str, *m.BotSpeedInfringements)
170+
}
159171
return fmt.Sprintf("%v undefined", str)
160172
}
161173

internal/app/controller/state.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,18 @@ const (
147147

148148
// TeamInfo about a team
149149
type TeamInfo struct {
150-
Name string `json:"name"`
151-
Goals int `json:"goals"`
152-
Goalie int `json:"goalie"`
153-
YellowCards int `json:"yellowCards"`
154-
YellowCardTimes []time.Duration `json:"yellowCardTimes"`
155-
RedCards int `json:"redCards"`
156-
TimeoutsLeft int `json:"timeoutsLeft"`
157-
TimeoutTimeLeft time.Duration `json:"timeoutTimeLeft"`
158-
OnPositiveHalf bool `json:"onPositiveHalf"`
150+
Name string `json:"name"`
151+
Goals int `json:"goals"`
152+
Goalie int `json:"goalie"`
153+
YellowCards int `json:"yellowCards"`
154+
YellowCardTimes []time.Duration `json:"yellowCardTimes"`
155+
RedCards int `json:"redCards"`
156+
TimeoutsLeft int `json:"timeoutsLeft"`
157+
TimeoutTimeLeft time.Duration `json:"timeoutTimeLeft"`
158+
OnPositiveHalf bool `json:"onPositiveHalf"`
159+
BotCollisions int `json:"botCollisions"`
160+
BallPlacementFailures int `json:"ballPlacementFailures"`
161+
BotSpeedInfringements int `json:"botSpeedInfringements"`
159162
}
160163

161164
// State of the game
@@ -201,6 +204,9 @@ func newTeamInfo() (t TeamInfo) {
201204
t.TimeoutsLeft = 0
202205
t.TimeoutTimeLeft = 0
203206
t.OnPositiveHalf = true
207+
t.BotCollisions = 0
208+
t.BallPlacementFailures = 0
209+
t.BotSpeedInfringements = 0
204210
return
205211
}
206212

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<template>
2+
<div>
3+
<div>
4+
<EditableLabelNumber
5+
:label="'Bot collisions: '"
6+
:value="teamState.botCollisions"
7+
:callback="updateBotCollisions"
8+
:min="0"
9+
:max="99"/>
10+
</div>
11+
<div>
12+
<EditableLabelNumber
13+
:label="'Ball-placement failures: '"
14+
:value="teamState.ballPlacementFailures"
15+
:callback="updateBallPlacementFailures"
16+
:min="0"
17+
:max="99"/>
18+
</div>
19+
<div>
20+
<EditableLabelNumber
21+
:label="'Bot-speed infringements: '"
22+
:value="teamState.botSpeedInfringements"
23+
:callback="updateBotSpeedInfringements"
24+
:min="0"
25+
:max="99"/>
26+
</div>
27+
</div>
28+
</template>
29+
30+
<script>
31+
import EditableLabelNumber from "../common/EditableLabelNumber";
32+
33+
export default {
34+
name: "TeamCounters",
35+
components: {EditableLabelNumber},
36+
props: {
37+
teamColor: String
38+
},
39+
computed: {
40+
teamState: function () {
41+
return this.$store.state.refBoxState.teamState[this.teamColor]
42+
}
43+
},
44+
methods: {
45+
updateBotCollisions: function (v) {
46+
this.$socket.sendObj({
47+
'modify': {
48+
'forTeam': this.teamColor,
49+
'botCollisions': Number(v)
50+
}
51+
})
52+
},
53+
updateBallPlacementFailures: function (v) {
54+
this.$socket.sendObj({
55+
'modify': {
56+
'forTeam': this.teamColor,
57+
'ballPlacementFailures': Number(v)
58+
}
59+
})
60+
},
61+
updateBotSpeedInfringements: function (v) {
62+
this.$socket.sendObj({
63+
'modify': {
64+
'forTeam': this.teamColor,
65+
'botSpeedInfringements': Number(v)
66+
}
67+
})
68+
}
69+
}
70+
}
71+
</script>
72+
73+
<style scoped>
74+
75+
</style>

ui/src/components/team/TeamHalf.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,4 @@
2020
</script>
2121

2222
<style scoped>
23-
button {
24-
margin: 0.5em;
25-
}
2623
</style>

ui/src/components/team/TeamOverview.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
:yellow-cards="team.yellowCards"
3838
:yellow-card-times="team.yellowCardTimes"/>
3939
</div>
40+
<div>
41+
<TeamCounters
42+
:team-color="teamColor"/>
43+
</div>
4044
</div>
4145
</div>
4246
</template>
@@ -50,13 +54,20 @@
5054
import TeamName from "./TeamName";
5155
import TeamYellowCards from "./TeamYellowCards";
5256
import TeamRedCards from "./TeamRedCards";
57+
import TeamCounters from "./TeamCounters";
5358
5459
export default {
5560
name: "TeamOverview",
5661
components: {
62+
TeamCounters,
5763
TeamRedCards,
5864
TeamYellowCards,
59-
TeamName, TeamHalf, EditableLabelText, TeamGoalie, TeamTimeouts, TeamScore
65+
TeamName,
66+
TeamHalf,
67+
EditableLabelText,
68+
TeamGoalie,
69+
TeamTimeouts,
70+
TeamScore
6071
},
6172
props: {
6273
teamColor: String

ui/src/components/team/TeamScore.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<template>
22
<EditableLabelNumber
33
:label="'Goals: '"
4-
:title="'Number of goals'"
54
:value="score"
65
:callback="updateGoals"
76
:min="0"

ui/src/components/team/TeamYellowCards.vue

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<span>
2+
<div>
33
<EditableLabelNumber
44
label="Yellow cards: "
55
:value="yellowCards"
@@ -28,7 +28,7 @@
2828
:value="cardTime"
2929
:callback="(v) => updateCardTime(v, cardId)"/>
3030
</b-collapse>
31-
</span>
31+
</div>
3232
</template>
3333

3434
<script>
@@ -65,8 +65,4 @@
6565
</script>
6666

6767
<style scoped>
68-
.editable-label {
69-
margin-left: 0.15em;
70-
margin-right: 0.15em;
71-
}
7268
</style>

ui/src/main.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ Vue.use(BootstrapVue);
1818
export class TeamState {
1919
name = 'someone';
2020
goals = 0;
21-
goalie = 1;
22-
yellowCards = 3;
23-
yellowCardTimes = [50, 60];
21+
goalie = 0;
22+
yellowCards = 0;
23+
yellowCardTimes = [];
2424
redCards = 0;
2525
timeoutsLeft = 4;
26-
timeoutTimeLeft = 60;
26+
timeoutTimeLeft = 300;
2727
onPositiveHalf = true;
28+
botCollisions = 0;
29+
ballPlacementFailures = 0;
30+
botSpeedInfringements = 0;
2831
}
2932

3033
export class RefBoxState {

0 commit comments

Comments
 (0)