Skip to content

Commit 4228485

Browse files
committed
[feature] Add online state for teams and autoRefs to UI
1 parent df0ac38 commit 4228485

File tree

7 files changed

+82
-18
lines changed

7 files changed

+82
-18
lines changed

internal/app/controller/controller.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,32 @@ func (c *GameController) publishApi() {
184184
defer c.historyPreserver.Close()
185185
for {
186186
c.timer.WaitTillNextFullSecond()
187+
c.updateOnlineStates()
187188
c.Engine.Tick(c.timer.Delta())
188189
c.historyPreserver.Save(c.Engine.History)
189190
c.publish()
190191
}
191192
}
192193

194+
func (c *GameController) updateOnlineStates() {
195+
for _, team := range []Team{TeamYellow, TeamBlue} {
196+
c.Engine.State.TeamState[team].Connected = c.teamConnected(team)
197+
}
198+
var autoRefs []string
199+
for _, autoRef := range c.AutoRefServer.Clients {
200+
autoRefs = append(autoRefs, autoRef.Id)
201+
}
202+
c.Engine.State.AutoRefsConnected = autoRefs
203+
}
204+
205+
func (c *GameController) teamConnected(team Team) bool {
206+
teamName := c.Engine.State.TeamState[team].Name
207+
if _, ok := c.TeamServer.Clients[teamName]; ok {
208+
return true
209+
}
210+
return false
211+
}
212+
193213
func (c *GameController) publishNetwork() {
194214
for {
195215
c.timer.WaitTillNextFull(100 * time.Millisecond)

internal/app/controller/state.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,24 +244,26 @@ type TeamInfo struct {
244244
BallPlacementFailures int `json:"ballPlacementFailures"`
245245
CanPlaceBall bool `json:"canPlaceBall"`
246246
MaxAllowedBots int `json:"maxAllowedBots"`
247+
Connected bool `json:"connected"`
247248
}
248249

249250
// State of the game
250251
type State struct {
251-
Stage Stage `json:"stage"`
252-
Command RefCommand `json:"command"`
253-
CommandFor Team `json:"commandForTeam"`
254-
GameEvents []*GameEvent `json:"gameEvents"`
255-
StageTimeElapsed time.Duration `json:"stageTimeElapsed"`
256-
StageTimeLeft time.Duration `json:"stageTimeLeft"`
257-
MatchTimeStart time.Time `json:"matchTimeStart"`
258-
MatchDuration time.Duration `json:"matchDuration"`
259-
TeamState map[Team]*TeamInfo `json:"teamState"`
260-
Division Division `json:"division"`
261-
PlacementPos *Location `json:"placementPos"`
262-
AutoContinue bool `json:"autoContinue"`
263-
NextCommand RefCommand `json:"nextCommand"`
264-
NextCommandFor Team `json:"nextCommandFor"`
252+
Stage Stage `json:"stage"`
253+
Command RefCommand `json:"command"`
254+
CommandFor Team `json:"commandForTeam"`
255+
GameEvents []*GameEvent `json:"gameEvents"`
256+
StageTimeElapsed time.Duration `json:"stageTimeElapsed"`
257+
StageTimeLeft time.Duration `json:"stageTimeLeft"`
258+
MatchTimeStart time.Time `json:"matchTimeStart"`
259+
MatchDuration time.Duration `json:"matchDuration"`
260+
TeamState map[Team]*TeamInfo `json:"teamState"`
261+
Division Division `json:"division"`
262+
PlacementPos *Location `json:"placementPos"`
263+
AutoContinue bool `json:"autoContinue"`
264+
NextCommand RefCommand `json:"nextCommand"`
265+
NextCommandFor Team `json:"nextCommandFor"`
266+
AutoRefsConnected []string `json:"autoRefsConnected"`
265267
}
266268

267269
// NewState creates a new state, initialized for the start of a new game

src/App.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
</div>
77
<div id="main-elements">
88
<div class="team-container">
9-
<h2>Yellow Team</h2>
109
<TeamOverview class="team-views" team-color="Yellow"/>
1110
<ControlTeam class="team-views" team-color="Yellow"/>
1211
</div>
@@ -25,7 +24,6 @@
2524
</div>
2625
</div>
2726
<div class="team-container">
28-
<h2>Blue Team</h2>
2927
<TeamOverview class="team-views" team-color="Blue"/>
3028
<ControlTeam class="team-views" team-color="Blue"/>
3129
</div>

src/components/events/Events.vue

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<div>
33
<EventTable :current-page="currentPage" :per-page="perPage" :events="events"/>
44
<div class="event-controls-container">
5+
<span class="auto-refs-connected" v-b-tooltip.hover :title="autoRefs"><b>{{autoRefsConnected}}</b> autoRefs connected. </span>
6+
57
<b-pagination size="sm"
68
:total-rows="events.length"
79
v-model="currentPage"
@@ -40,7 +42,25 @@
4042
},
4143
state() {
4244
return this.$store.state.refBoxState
43-
}
45+
},
46+
autoRefsConnected() {
47+
if (this.state.autoRefsConnected != null) {
48+
return this.state.autoRefsConnected.length;
49+
}
50+
return 0;
51+
},
52+
autoRefs() {
53+
if (this.autoRefsConnected) {
54+
let autoRefs = 'Connected AutoRefs: ';
55+
for (let i = 0; i < this.state.autoRefsConnected.length; i++) {
56+
autoRefs += this.state.autoRefsConnected[i];
57+
if (i !== (this.state.autoRefsConnected.length - 1)) {
58+
autoRefs += ', '
59+
}
60+
}
61+
return autoRefs;
62+
}
63+
},
4464
},
4565
}
4666
</script>
@@ -56,4 +76,9 @@
5676
margin-bottom: 1rem;
5777
margin-left: 1rem;
5878
}
79+
80+
.auto-refs-connected {
81+
margin-top: 0.2rem;
82+
margin-right: 1rem;
83+
}
5984
</style>

src/components/team/TeamOverview.vue

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<template>
22
<div>
3+
<h2>{{teamColor}} Team
4+
<span v-b-tooltip.hover
5+
title="Team connected"
6+
v-if="team.connected">
7+
<font-awesome-icon
8+
class="fa-xs"
9+
icon="signal"/>
10+
</span>
11+
</h2>
312
<div class="content">
413
<div>
514
<TeamName

src/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import 'bootstrap/dist/css/bootstrap.css'
1111
import 'bootstrap-vue/dist/bootstrap-vue.css'
1212
// Use fontawesome to load some icons
1313
import {library} from '@fortawesome/fontawesome-svg-core'
14-
import {faCaretSquareDown, faCaretSquareUp, faEdit, faToggleOff, faToggleOn} from '@fortawesome/free-solid-svg-icons'
14+
import {
15+
faCaretSquareDown,
16+
faCaretSquareUp,
17+
faEdit,
18+
faSignal,
19+
faToggleOff,
20+
faToggleOn
21+
} from '@fortawesome/free-solid-svg-icons'
1522
import {FontAwesomeIcon} from '@fortawesome/vue-fontawesome'
1623
// Connect to the backend with a single websocket that communicates with JSON format and is attached to the store
1724
import VueNativeSock from 'vue-native-websocket'
@@ -27,6 +34,7 @@ library.add(faCaretSquareDown);
2734
library.add(faCaretSquareUp);
2835
library.add(faToggleOn);
2936
library.add(faToggleOff);
37+
library.add(faSignal);
3038
Vue.component('font-awesome-icon', FontAwesomeIcon);
3139

3240
let wsAddress;

src/store.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class TeamState {
1717
ballPlacementFailures = 0;
1818
canPlaceBall = true;
1919
maxAllowedBots = 0;
20+
connected = false;
2021
}
2122

2223
export class RefBoxState {
@@ -32,6 +33,7 @@ export class RefBoxState {
3233
autoContinue = true;
3334
nextCommand = '';
3435
nextCommandFor = '';
36+
autoRefsConnected = [];
3537
}
3638

3739
export default new Vuex.Store({

0 commit comments

Comments
 (0)