Commit realtime scores and autopost to final score buffer.

This commit is contained in:
Patrick Fairbank
2014-08-03 20:59:07 -07:00
parent 747c007fe4
commit 4892247a1e
2 changed files with 20 additions and 2 deletions

View File

@@ -293,8 +293,7 @@ func MatchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
continue
}
case "commitResults":
// TODO(pat): Deal with scoring here. For now, use an empty match result set for a 0-0 tie.
err = CommitMatchScore(mainArena.currentMatch, &MatchResult{MatchId: mainArena.currentMatch.Id})
err = CommitCurrentMatchScore()
if err != nil {
websocket.WriteError(err.Error())
continue
@@ -355,7 +354,13 @@ func MatchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
}
}
// Saves the given match and result to the database, supplanting any previous result for the match.
func CommitMatchScore(match *Match, matchResult *MatchResult) error {
// Store the result in the buffer to be shown in the audience display.
mainArena.savedMatch = match
mainArena.savedMatchResult = matchResult
mainArena.scorePostedNotifier.Notify(nil)
if match.Type == "test" {
// Do nothing since this is a test match and doesn't exist in the database.
return nil
@@ -437,6 +442,15 @@ func CommitMatchScore(match *Match, matchResult *MatchResult) error {
return nil
}
// Saves the realtime result as the final score for the match currently loaded into the arena.
func CommitCurrentMatchScore() error {
// TODO(patrick): Set the red/yellow cards.
matchResult := MatchResult{MatchId: mainArena.currentMatch.Id,
RedScore: mainArena.redRealtimeScore.CurrentScore, BlueScore: mainArena.blueRealtimeScore.CurrentScore,
RedFouls: mainArena.redRealtimeScore.Fouls, BlueFouls: mainArena.blueRealtimeScore.Fouls}
return CommitMatchScore(mainArena.currentMatch, &matchResult)
}
func (list MatchPlayList) Len() int {
return len(list)
}

View File

@@ -248,8 +248,12 @@ func TestMatchPlayWebsocketCommands(t *testing.T) {
readWebsocketType(t, ws, "status")
readWebsocketType(t, ws, "setAudienceDisplay")
assert.Equal(t, POST_MATCH, mainArena.MatchState)
mainArena.redRealtimeScore.CurrentScore.AutoHighHot = 29
mainArena.blueRealtimeScore.CurrentScore.AutoHighHot = 37
ws.Write("commitResults", nil)
readWebsocketType(t, ws, "reload")
assert.Equal(t, 29, mainArena.savedMatchResult.RedScore.AutoHighHot)
assert.Equal(t, 37, mainArena.savedMatchResult.BlueScore.AutoHighHot)
assert.Equal(t, PRE_MATCH, mainArena.MatchState)
ws.Write("discardResults", nil)
readWebsocketType(t, ws, "reload")