Add functionality to trigger a timeout and show the countdown on the audience display (fixes #51).

This commit is contained in:
Patrick Fairbank
2018-09-18 23:58:33 -07:00
parent 27f0134ff7
commit d8c4b92f57
18 changed files with 314 additions and 114 deletions

View File

@@ -6,10 +6,8 @@
package web
import (
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/websocket"
"log"
"net/http"
)
@@ -59,15 +57,8 @@ func (web *Web) allianceStationDisplayWebsocketHandler(w http.ResponseWriter, r
}
defer ws.Close()
// Inform the client what the match period timing parameters are configured to.
err = ws.Write("matchTiming", game.MatchTiming)
if err != nil {
log.Println(err)
return
}
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
ws.HandleNotifiers(web.arena.AllianceStationDisplayModeNotifier, web.arena.ArenaStatusNotifier,
web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier, web.arena.RealtimeScoreNotifier,
web.arena.DisplayConfigurationNotifier, web.arena.ReloadDisplaysNotifier)
ws.HandleNotifiers(web.arena.MatchTimingNotifier, web.arena.AllianceStationDisplayModeNotifier,
web.arena.ArenaStatusNotifier, web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier,
web.arena.RealtimeScoreNotifier, web.arena.DisplayConfigurationNotifier, web.arena.ReloadDisplaysNotifier)
}

View File

@@ -6,10 +6,8 @@
package web
import (
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/websocket"
"log"
"net/http"
)
@@ -59,15 +57,8 @@ func (web *Web) announcerDisplayWebsocketHandler(w http.ResponseWriter, r *http.
}
defer ws.Close()
// Inform the client what the match period timing parameters are configured to.
err = ws.Write("matchTiming", game.MatchTiming)
if err != nil {
log.Println(err)
return
}
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
ws.HandleNotifiers(web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier, web.arena.RealtimeScoreNotifier,
web.arena.ScorePostedNotifier, web.arena.AudienceDisplayModeNotifier, web.arena.DisplayConfigurationNotifier,
web.arena.ReloadDisplaysNotifier)
ws.HandleNotifiers(web.arena.MatchTimingNotifier, web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier,
web.arena.RealtimeScoreNotifier, web.arena.ScorePostedNotifier, web.arena.AudienceDisplayModeNotifier,
web.arena.DisplayConfigurationNotifier, web.arena.ReloadDisplaysNotifier)
}

View File

@@ -6,10 +6,8 @@
package web
import (
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/websocket"
"log"
"net/http"
)
@@ -59,16 +57,9 @@ func (web *Web) audienceDisplayWebsocketHandler(w http.ResponseWriter, r *http.R
}
defer ws.Close()
// Inform the client what the match period timing parameters are configured to.
err = ws.Write("matchTiming", game.MatchTiming)
if err != nil {
log.Println(err)
return
}
// Subscribe the websocket to the notifiers whose messages will be passed on to the client.
ws.HandleNotifiers(web.arena.AudienceDisplayModeNotifier, web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier,
web.arena.RealtimeScoreNotifier, web.arena.PlaySoundNotifier, web.arena.ScorePostedNotifier,
web.arena.AllianceSelectionNotifier, web.arena.LowerThirdNotifier, web.arena.DisplayConfigurationNotifier,
web.arena.ReloadDisplaysNotifier)
ws.HandleNotifiers(web.arena.MatchTimingNotifier, web.arena.AudienceDisplayModeNotifier,
web.arena.MatchLoadNotifier, web.arena.MatchTimeNotifier, web.arena.RealtimeScoreNotifier,
web.arena.PlaySoundNotifier, web.arena.ScorePostedNotifier, web.arena.AllianceSelectionNotifier,
web.arena.LowerThirdNotifier, web.arena.DisplayConfigurationNotifier, web.arena.ReloadDisplaysNotifier)
}

View File

@@ -7,7 +7,6 @@ package web
import (
"fmt"
"github.com/Team254/cheesy-arena/game"
"github.com/Team254/cheesy-arena/model"
"github.com/Team254/cheesy-arena/tournament"
"github.com/Team254/cheesy-arena/websocket"
@@ -167,16 +166,9 @@ func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request
}
defer ws.Close()
// Inform the client what the match period timing parameters are configured to.
err = ws.Write("matchTiming", game.MatchTiming)
if err != nil {
log.Println(err)
return
}
// Subscribe the websocket to the notifiers whose messages will be passed on to the client, in a separate goroutine.
go ws.HandleNotifiers(web.arena.ArenaStatusNotifier, web.arena.MatchTimeNotifier, web.arena.RealtimeScoreNotifier,
web.arena.ScoringStatusNotifier, web.arena.AudienceDisplayModeNotifier,
go ws.HandleNotifiers(web.arena.MatchTimingNotifier, web.arena.ArenaStatusNotifier, web.arena.MatchTimeNotifier,
web.arena.RealtimeScoreNotifier, web.arena.ScoringStatusNotifier, web.arena.AudienceDisplayModeNotifier,
web.arena.AllianceStationDisplayModeNotifier)
// Loop, waiting for commands and responding to them, until the client closes the connection.
@@ -298,6 +290,17 @@ func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request
web.arena.AllianceStationDisplayMode = screen
web.arena.AllianceStationDisplayModeNotifier.Notify()
continue
case "startTimeout":
durationSec, ok := data.(float64)
if !ok {
ws.WriteError(fmt.Sprintf("Failed to parse '%s' message.", messageType))
continue
}
err = web.arena.StartTimeout(int(durationSec))
if err != nil {
ws.WriteError(err.Error())
continue
}
default:
ws.WriteError(fmt.Sprintf("Invalid message type '%s'.", messageType))
continue

View File

@@ -132,7 +132,8 @@ func (web *Web) scoringPanelWebsocketHandler(w http.ResponseWriter, r *http.Requ
}
}
case "\r":
if (web.arena.MatchState != field.PreMatch || web.arena.CurrentMatch.Type == "test") &&
if (web.arena.MatchState != field.PreMatch && web.arena.MatchState != field.TimeoutActive &&
web.arena.MatchState != field.PostTimeout || web.arena.CurrentMatch.Type == "test") &&
!(*score).AutoCommitted {
(*score).AutoCommitted = true
scoreChanged = true

View File

@@ -76,7 +76,8 @@ func (web *Web) ledPlcWebsocketHandler(w http.ResponseWriter, r *http.Request) {
switch messageType {
case "setLedMode":
if web.arena.MatchState != field.PreMatch {
if web.arena.MatchState != field.PreMatch && web.arena.MatchState != field.TimeoutActive &&
web.arena.MatchState != field.PostTimeout {
ws.WriteError("Arena must be in pre-match state")
continue
}