mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Refactor match sounds such that they only need to be listed in one place.
This commit is contained in:
@@ -303,7 +303,7 @@ func (arena *Arena) AbortMatch() error {
|
||||
}
|
||||
|
||||
if arena.MatchState != WarmupPeriod {
|
||||
arena.playSound("match-abort")
|
||||
arena.playSound("abort")
|
||||
}
|
||||
arena.MatchState = PostMatch
|
||||
arena.matchAborted = true
|
||||
@@ -440,7 +440,7 @@ func (arena *Arena) Update() {
|
||||
case TimeoutActive:
|
||||
if matchTimeSec >= float64(game.MatchTiming.TimeoutDurationSec) {
|
||||
arena.MatchState = PostTimeout
|
||||
arena.playSound("match-end")
|
||||
arena.playSound("end")
|
||||
go func() {
|
||||
// Leave the timer on the screen briefly at the end of the timeout period.
|
||||
time.Sleep(time.Second * matchEndScoreDwellSec)
|
||||
@@ -727,6 +727,10 @@ func (arena *Arena) handleEstop(station string, state bool) {
|
||||
|
||||
func (arena *Arena) handleSounds(matchTimeSec float64) {
|
||||
for _, sound := range game.MatchSounds {
|
||||
if sound.MatchTimeSec < 0 {
|
||||
// Skip sounds with negative timestamps; they are meant to only be triggered explicitly.
|
||||
continue
|
||||
}
|
||||
if _, ok := arena.soundsPlayed[sound]; !ok {
|
||||
if matchTimeSec > sound.MatchTimeSec {
|
||||
arena.playSound(sound.Name)
|
||||
|
||||
@@ -6,15 +6,18 @@
|
||||
package game
|
||||
|
||||
type MatchSound struct {
|
||||
Name string
|
||||
MatchTimeSec float64
|
||||
Name string
|
||||
FileExtension string
|
||||
MatchTimeSec float64
|
||||
}
|
||||
|
||||
// List of sounds and how many seconds into the match they are played.
|
||||
// List of sounds and how many seconds into the match they are played. A negative time indicates that the sound can only
|
||||
// be triggered explicitly.
|
||||
var MatchSounds = []*MatchSound{
|
||||
{"match-start", 0},
|
||||
{"match-resume", 15},
|
||||
{"match-warning1", 120},
|
||||
{"match-warning2", 130},
|
||||
{"match-end", 150},
|
||||
{"start", "wav", 0},
|
||||
{"resume", "wav", 15},
|
||||
{"warning1", "wav", 120},
|
||||
{"warning2", "wav", 130},
|
||||
{"end", "wav", 150},
|
||||
{"abort", "mp3", -1},
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -157,7 +157,7 @@ var handlePlaySound = function(sound) {
|
||||
v.pause();
|
||||
v.currentTime = 0;
|
||||
});
|
||||
$("#" + sound)[0].play();
|
||||
$("#sound-" + sound)[0].play();
|
||||
};
|
||||
|
||||
// Handles a websocket message to update the alliance selection screen.
|
||||
|
||||
@@ -192,16 +192,10 @@
|
||||
<h1>{{"{{Subtitle}}"}}</h1>
|
||||
</div>
|
||||
</script>
|
||||
<audio id="match-warmup" src="/static/audio/match_warmup.wav" preload="auto"></audio>
|
||||
<audio id="match-start" src="/static/audio/match_start.wav" preload="auto"></audio>
|
||||
<audio id="match-end" src="/static/audio/match_end.wav" preload="auto"></audio>
|
||||
<audio id="match-abort" src="/static/audio/match_abort.mp3" preload="auto"></audio>
|
||||
<audio id="match-resume" src="/static/audio/match_resume.wav" preload="auto"></audio>
|
||||
<audio id="match-force" src="/static/audio/match_force.wav" preload="auto"></audio>
|
||||
<audio id="match-levitate" src="/static/audio/match_levitate.wav" preload="auto"></audio>
|
||||
<audio id="match-boost" src="/static/audio/match_boost.wav" preload="auto"></audio>
|
||||
<audio id="match-warning1" src="/static/audio/match_warning1.wav" preload="auto"></audio>
|
||||
<audio id="match-warning2" src="/static/audio/match_warning2.wav" preload="auto"></audio>
|
||||
{{range $sound := .MatchSounds}}
|
||||
<audio id="sound-{{$sound.Name}}" src="/static/audio/{{$sound.Name}}.{{$sound.FileExtension}}" preload="auto">
|
||||
</audio>
|
||||
{{end}}
|
||||
<script src="/static/js/lib/jquery.min.js"></script>
|
||||
<script src="/static/js/lib/jquery.json-2.4.min.js"></script>
|
||||
<script src="/static/js/lib/jquery.websocket-0.0.1.js"></script>
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"github.com/Team254/cheesy-arena/game"
|
||||
"github.com/Team254/cheesy-arena/model"
|
||||
"github.com/Team254/cheesy-arena/websocket"
|
||||
"net/http"
|
||||
@@ -29,7 +30,8 @@ func (web *Web) audienceDisplayHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
data := struct {
|
||||
*model.EventSettings
|
||||
}{web.arena.EventSettings}
|
||||
MatchSounds []*game.MatchSound
|
||||
}{web.arena.EventSettings, game.MatchSounds}
|
||||
err = template.ExecuteTemplate(w, "audience_display.html", data)
|
||||
if err != nil {
|
||||
handleWebErr(w, err)
|
||||
|
||||
@@ -64,7 +64,7 @@ func TestAudienceDisplayWebsocket(t *testing.T) {
|
||||
}
|
||||
sound, ok := messages["playSound"]
|
||||
if assert.True(t, ok) {
|
||||
assert.Equal(t, "match-start", sound)
|
||||
assert.Equal(t, "start", sound)
|
||||
}
|
||||
_, ok = messages["matchTime"]
|
||||
assert.True(t, ok)
|
||||
|
||||
Reference in New Issue
Block a user