Skip to content

Commit 07d9a5b

Browse files
committed
[feature] Add canPlaceBall flag to each team
1 parent f5a2c06 commit 07d9a5b

File tree

10 files changed

+150
-69
lines changed

10 files changed

+150
-69
lines changed

internal/app/controller/engine.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,12 @@ func (e *Engine) processModify(m *EventModifyValue) error {
291291
} else {
292292
return err
293293
}
294+
} else if m.CanPlaceBall != nil {
295+
teamState.CanPlaceBall = *m.CanPlaceBall
294296
} else {
295297
return errors.Errorf("Unknown modify: %v", m)
296298
}
297-
log.Printf("Processed modification %v", m)
299+
log.Printf("Processed %v", m)
298300
return nil
299301
}
300302

internal/app/controller/events.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ type EventModifyValue struct {
104104
BotCollisions *int `json:"botCollisions"`
105105
BallPlacementFailures *int `json:"ballPlacementFailures"`
106106
BotSpeedInfringements *int `json:"botSpeedInfringements"`
107+
CanPlaceBall *bool `json:"canPlaceBall"`
107108
Division *Division `json:"division"`
108109
}
109110

@@ -145,6 +146,9 @@ func (m EventModifyValue) String() string {
145146
if m.BotSpeedInfringements != nil {
146147
return fmt.Sprintf("%v BotSpeedInfringements=%v", str, *m.BotSpeedInfringements)
147148
}
149+
if m.CanPlaceBall != nil {
150+
return fmt.Sprintf("%v CanPlaceBall=%v", str, *m.CanPlaceBall)
151+
}
148152
if m.Division != nil {
149153
return fmt.Sprintf("%v Division=%v", str, *m.Division)
150154
}

internal/app/controller/publisher.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func initTeamInfo(t *refproto.Referee_TeamInfo) {
6565
t.BotCollisions = new(uint32)
6666
t.BallPlacementFailures = new(uint32)
6767
t.BotSpeedInfringements = new(uint32)
68+
t.CanPlaceBall = new(bool)
6869
}
6970

7071
// Publish the state and command
@@ -160,6 +161,7 @@ func updateTeam(team *refproto.Referee_TeamInfo, state *TeamInfo) {
160161
*team.BotCollisions = uint32(state.BotCollisions)
161162
*team.BallPlacementFailures = uint32(state.BallPlacementFailures)
162163
*team.BotSpeedInfringements = uint32(state.BotSpeedInfringements)
164+
*team.CanPlaceBall = state.CanPlaceBall
163165
}
164166

165167
func mapTimes(durations []time.Duration) []uint32 {

internal/app/controller/state.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ type TeamInfo struct {
214214
BotCollisions int `json:"botCollisions"`
215215
BallPlacementFailures int `json:"ballPlacementFailures"`
216216
BotSpeedInfringements int `json:"botSpeedInfringements"`
217+
CanPlaceBall bool `json:"canPlaceBall"`
217218
}
218219

219220
// State of the game

pkg/refproto/ssl_referee.pb.go

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

pkg/refproto/ssl_referee.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ message Referee {
144144
optional uint32 ball_placement_failures = 10;
145145
// The total number of infringements where robots were too fast during game stoppage
146146
optional uint32 bot_speed_infringements = 11;
147+
// Indicate if the team is able and allowed to place the ball
148+
optional bool can_place_ball = 12;
147149
}
148150

149151
// Information about the two teams.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<template>
2+
<div>
3+
<label>{{ballPlacementState}}</label>
4+
<a class="btn-edit" v-on:click="edit()">
5+
<font-awesome-icon icon="toggle-on" v-if="canPlaceBall"/>
6+
<font-awesome-icon icon="toggle-off" v-if="!canPlaceBall"/>
7+
</a>
8+
</div>
9+
</template>
10+
11+
<script>
12+
export default {
13+
name: "TeamBallPlacement",
14+
props: {
15+
teamColor: String
16+
},
17+
methods: {
18+
edit: function (v) {
19+
this.$socket.sendObj({
20+
'modify': {
21+
'forTeam': this.teamColor,
22+
'canPlaceBall': !this.canPlaceBall
23+
}
24+
})
25+
}
26+
},
27+
computed: {
28+
teamState: function () {
29+
return this.$store.state.refBoxState.teamState[this.teamColor]
30+
},
31+
canPlaceBall() {
32+
return this.teamState.canPlaceBall;
33+
},
34+
ballPlacementState() {
35+
if (this.canPlaceBall) {
36+
return 'Ball Placement enabled'
37+
}
38+
return 'Ball Placement disabled';
39+
}
40+
}
41+
}
42+
</script>
43+
44+
<style scoped>
45+
.btn-edit {
46+
margin-left: 0.3em;
47+
margin-right: 0.3em;
48+
}
49+
</style>

src/components/team/TeamOverview.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
<TeamCounters
4141
:team-color="teamColor"/>
4242
</div>
43+
<div>
44+
<TeamBallPlacement
45+
:team-color="teamColor"/>
46+
</div>
4347
</div>
4448
</div>
4549
</template>
@@ -54,10 +58,12 @@
5458
import TeamYellowCards from "./TeamYellowCards";
5559
import TeamRedCards from "./TeamRedCards";
5660
import TeamCounters from "./TeamCounters";
61+
import TeamBallPlacement from "./TeamBallPlacement";
5762
5863
export default {
5964
name: "TeamOverview",
6065
components: {
66+
TeamBallPlacement,
6167
TeamCounters,
6268
TeamRedCards,
6369
TeamYellowCards,

0 commit comments

Comments
 (0)