Skip to content

Commit

Permalink
[feature] Add canPlaceBall flag to each team
Browse files Browse the repository at this point in the history
  • Loading branch information
g3force committed Aug 26, 2018
1 parent f5a2c06 commit 07d9a5b
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 69 deletions.
4 changes: 3 additions & 1 deletion internal/app/controller/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,12 @@ func (e *Engine) processModify(m *EventModifyValue) error {
} else {
return err
}
} else if m.CanPlaceBall != nil {
teamState.CanPlaceBall = *m.CanPlaceBall
} else {
return errors.Errorf("Unknown modify: %v", m)
}
log.Printf("Processed modification %v", m)
log.Printf("Processed %v", m)
return nil
}

Expand Down
4 changes: 4 additions & 0 deletions internal/app/controller/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type EventModifyValue struct {
BotCollisions *int `json:"botCollisions"`
BallPlacementFailures *int `json:"ballPlacementFailures"`
BotSpeedInfringements *int `json:"botSpeedInfringements"`
CanPlaceBall *bool `json:"canPlaceBall"`
Division *Division `json:"division"`
}

Expand Down Expand Up @@ -145,6 +146,9 @@ func (m EventModifyValue) String() string {
if m.BotSpeedInfringements != nil {
return fmt.Sprintf("%v BotSpeedInfringements=%v", str, *m.BotSpeedInfringements)
}
if m.CanPlaceBall != nil {
return fmt.Sprintf("%v CanPlaceBall=%v", str, *m.CanPlaceBall)
}
if m.Division != nil {
return fmt.Sprintf("%v Division=%v", str, *m.Division)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/app/controller/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func initTeamInfo(t *refproto.Referee_TeamInfo) {
t.BotCollisions = new(uint32)
t.BallPlacementFailures = new(uint32)
t.BotSpeedInfringements = new(uint32)
t.CanPlaceBall = new(bool)
}

// Publish the state and command
Expand Down Expand Up @@ -160,6 +161,7 @@ func updateTeam(team *refproto.Referee_TeamInfo, state *TeamInfo) {
*team.BotCollisions = uint32(state.BotCollisions)
*team.BallPlacementFailures = uint32(state.BallPlacementFailures)
*team.BotSpeedInfringements = uint32(state.BotSpeedInfringements)
*team.CanPlaceBall = state.CanPlaceBall
}

func mapTimes(durations []time.Duration) []uint32 {
Expand Down
1 change: 1 addition & 0 deletions internal/app/controller/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ type TeamInfo struct {
BotCollisions int `json:"botCollisions"`
BallPlacementFailures int `json:"ballPlacementFailures"`
BotSpeedInfringements int `json:"botSpeedInfringements"`
CanPlaceBall bool `json:"canPlaceBall"`
}

// State of the game
Expand Down
145 changes: 78 additions & 67 deletions pkg/refproto/ssl_referee.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/refproto/ssl_referee.proto
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ message Referee {
optional uint32 ball_placement_failures = 10;
// The total number of infringements where robots were too fast during game stoppage
optional uint32 bot_speed_infringements = 11;
// Indicate if the team is able and allowed to place the ball
optional bool can_place_ball = 12;
}

// Information about the two teams.
Expand Down
49 changes: 49 additions & 0 deletions src/components/team/TeamBallPlacement.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div>
<label>{{ballPlacementState}}</label>
<a class="btn-edit" v-on:click="edit()">
<font-awesome-icon icon="toggle-on" v-if="canPlaceBall"/>
<font-awesome-icon icon="toggle-off" v-if="!canPlaceBall"/>
</a>
</div>
</template>

<script>
export default {
name: "TeamBallPlacement",
props: {
teamColor: String
},
methods: {
edit: function (v) {
this.$socket.sendObj({
'modify': {
'forTeam': this.teamColor,
'canPlaceBall': !this.canPlaceBall
}
})
}
},
computed: {
teamState: function () {
return this.$store.state.refBoxState.teamState[this.teamColor]
},
canPlaceBall() {
return this.teamState.canPlaceBall;
},
ballPlacementState() {
if (this.canPlaceBall) {
return 'Ball Placement enabled'
}
return 'Ball Placement disabled';
}
}
}
</script>

<style scoped>
.btn-edit {
margin-left: 0.3em;
margin-right: 0.3em;
}
</style>
6 changes: 6 additions & 0 deletions src/components/team/TeamOverview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<TeamCounters
:team-color="teamColor"/>
</div>
<div>
<TeamBallPlacement
:team-color="teamColor"/>
</div>
</div>
</div>
</template>
Expand All @@ -54,10 +58,12 @@
import TeamYellowCards from "./TeamYellowCards";
import TeamRedCards from "./TeamRedCards";
import TeamCounters from "./TeamCounters";
import TeamBallPlacement from "./TeamBallPlacement";
export default {
name: "TeamOverview",
components: {
TeamBallPlacement,
TeamCounters,
TeamRedCards,
TeamYellowCards,
Expand Down
Loading

0 comments on commit 07d9a5b

Please sign in to comment.