Skip to content

Commit

Permalink
Add sound when match result is shown (closes #120).
Browse files Browse the repository at this point in the history
  • Loading branch information
patfair committed Apr 30, 2022
1 parent d4d4292 commit 8962b48
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
19 changes: 19 additions & 0 deletions field/arena.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,25 @@ func (arena *Arena) StartTimeout(durationSec int) error {
return nil
}

// Updates the audience display screen.
func (arena *Arena) SetAudienceDisplayMode(mode string) {
if arena.AudienceDisplayMode != mode {
arena.AudienceDisplayMode = mode
arena.AudienceDisplayModeNotifier.Notify()
if mode == "score" {
arena.playSound("match_result")
}
}
}

// Updates the alliance station display screen.
func (arena *Arena) SetAllianceStationDisplayMode(mode string) {
if arena.AllianceStationDisplayMode != mode {
arena.AllianceStationDisplayMode = mode
arena.AllianceStationDisplayModeNotifier.Notify()
}
}

// Returns the fractional number of seconds since the start of the match.
func (arena *Arena) MatchTimeSec() float64 {
if arena.MatchState == PreMatch || arena.MatchState == StartMatch || arena.MatchState == PostMatch {
Expand Down
6 changes: 6 additions & 0 deletions game/match_sounds.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,11 @@ func UpdateMatchSounds() {
-1,
false,
},
{
"match_result",
"wav",
-1,
false,
},
}
}
Binary file added static/audio/match_result.wav
Binary file not shown.
10 changes: 4 additions & 6 deletions web/match_play.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,20 @@ func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request
}
continue // Skip sending the status update, as the client is about to terminate and reload.
case "setAudienceDisplay":
screen, ok := data.(string)
mode, ok := data.(string)
if !ok {
ws.WriteError(fmt.Sprintf("Failed to parse '%s' message.", messageType))
continue
}
web.arena.AudienceDisplayMode = screen
web.arena.AudienceDisplayModeNotifier.Notify()
web.arena.SetAudienceDisplayMode(mode)
continue
case "setAllianceStationDisplay":
screen, ok := data.(string)
mode, ok := data.(string)
if !ok {
ws.WriteError(fmt.Sprintf("Failed to parse '%s' message.", messageType))
continue
}
web.arena.AllianceStationDisplayMode = screen
web.arena.AllianceStationDisplayModeNotifier.Notify()
web.arena.SetAllianceStationDisplayMode(mode)
continue
case "startTimeout":
durationSec, ok := data.(float64)
Expand Down

0 comments on commit 8962b48

Please sign in to comment.