mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -04:00
Added match sound playback to audience display.
This commit is contained in:
8
arena.go
8
arena.go
@@ -72,6 +72,7 @@ type Arena struct {
|
||||
realtimeScoreNotifier *Notifier
|
||||
scorePostedNotifier *Notifier
|
||||
audienceDisplayNotifier *Notifier
|
||||
playSoundNotifier *Notifier
|
||||
audienceDisplayScreen string
|
||||
lastMatchState int
|
||||
lastMatchTimeSec float64
|
||||
@@ -103,6 +104,7 @@ func (arena *Arena) Setup() {
|
||||
arena.realtimeScoreNotifier = NewNotifier()
|
||||
arena.scorePostedNotifier = NewNotifier()
|
||||
arena.audienceDisplayNotifier = NewNotifier()
|
||||
arena.playSoundNotifier = NewNotifier()
|
||||
|
||||
// Load empty match as current.
|
||||
arena.MatchState = PRE_MATCH
|
||||
@@ -289,6 +291,7 @@ func (arena *Arena) AbortMatch() error {
|
||||
arena.MatchState = POST_MATCH
|
||||
arena.audienceDisplayScreen = "blank"
|
||||
arena.audienceDisplayNotifier.Notify(nil)
|
||||
arena.playSoundNotifier.Notify("match-abort")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -339,6 +342,7 @@ func (arena *Arena) Update() {
|
||||
sendDsPacket = true
|
||||
arena.audienceDisplayScreen = "match"
|
||||
arena.audienceDisplayNotifier.Notify(nil)
|
||||
arena.playSoundNotifier.Notify("match-start")
|
||||
case AUTO_PERIOD:
|
||||
auto = true
|
||||
enabled = true
|
||||
@@ -347,6 +351,7 @@ func (arena *Arena) Update() {
|
||||
auto = false
|
||||
enabled = false
|
||||
sendDsPacket = true
|
||||
arena.playSoundNotifier.Notify("match-end")
|
||||
}
|
||||
case PAUSE_PERIOD:
|
||||
auto = false
|
||||
@@ -356,6 +361,7 @@ func (arena *Arena) Update() {
|
||||
auto = false
|
||||
enabled = true
|
||||
sendDsPacket = true
|
||||
arena.playSoundNotifier.Notify("match-resume")
|
||||
}
|
||||
case TELEOP_PERIOD:
|
||||
auto = false
|
||||
@@ -364,6 +370,7 @@ func (arena *Arena) Update() {
|
||||
arena.matchTiming.TeleopDurationSec-arena.matchTiming.EndgameTimeLeftSec) {
|
||||
arena.MatchState = ENDGAME_PERIOD
|
||||
sendDsPacket = false
|
||||
arena.playSoundNotifier.Notify("match-endgame")
|
||||
}
|
||||
case ENDGAME_PERIOD:
|
||||
auto = false
|
||||
@@ -376,6 +383,7 @@ func (arena *Arena) Update() {
|
||||
sendDsPacket = true
|
||||
arena.audienceDisplayScreen = "blank"
|
||||
arena.audienceDisplayNotifier.Notify(nil)
|
||||
arena.playSoundNotifier.Notify("match-end")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,8 @@ func AudienceDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
||||
defer close(realtimeScoreListener)
|
||||
scorePostedListener := mainArena.scorePostedNotifier.Listen()
|
||||
defer close(scorePostedListener)
|
||||
playSoundListener := mainArena.playSoundNotifier.Listen()
|
||||
defer close(playSoundListener)
|
||||
|
||||
// Send the various notifications immediately upon connection.
|
||||
var data interface{}
|
||||
@@ -161,6 +163,12 @@ func AudienceDisplayWebsocketHandler(w http.ResponseWriter, r *http.Request) {
|
||||
BlueScore *ScoreSummary
|
||||
}{mainArena.savedMatch, mainArena.savedMatch.CapitalizedType(),
|
||||
mainArena.savedMatchResult.RedScoreSummary(), mainArena.savedMatchResult.BlueScoreSummary()}
|
||||
case sound, ok := <-playSoundListener:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
messageType = "playSound"
|
||||
message = sound
|
||||
}
|
||||
err = websocket.Write(messageType, message)
|
||||
if err != nil {
|
||||
|
||||
@@ -60,11 +60,15 @@ func TestAudienceDisplayWebsocket(t *testing.T) {
|
||||
mainArena.AllianceStations["B3"].Bypass = true
|
||||
mainArena.StartMatch()
|
||||
mainArena.Update()
|
||||
messages := readWebsocketMultiple(t, ws, 2)
|
||||
messages := readWebsocketMultiple(t, ws, 3)
|
||||
screen, ok := messages["setAudienceDisplay"]
|
||||
if assert.True(t, ok) {
|
||||
assert.Equal(t, "match", screen)
|
||||
}
|
||||
sound, ok := messages["playSound"]
|
||||
if assert.True(t, ok) {
|
||||
assert.Equal(t, "match-start", sound)
|
||||
}
|
||||
_, ok = messages["matchTime"]
|
||||
assert.True(t, ok)
|
||||
mainArena.realtimeScoreNotifier.Notify(nil)
|
||||
|
||||
BIN
static/audio/match_abort.mp3
Normal file
BIN
static/audio/match_abort.mp3
Normal file
Binary file not shown.
BIN
static/audio/match_end.wav
Normal file
BIN
static/audio/match_end.wav
Normal file
Binary file not shown.
BIN
static/audio/match_endgame.wav
Normal file
BIN
static/audio/match_endgame.wav
Normal file
Binary file not shown.
BIN
static/audio/match_resume.wav
Normal file
BIN
static/audio/match_resume.wav
Normal file
Binary file not shown.
BIN
static/audio/match_start.wav
Normal file
BIN
static/audio/match_start.wav
Normal file
Binary file not shown.
@@ -77,6 +77,15 @@ var handleSetFinalScore = function(data) {
|
||||
$("#finalMatchName").text(data.MatchName + " " + data.Match.DisplayName);
|
||||
};
|
||||
|
||||
var handlePlaySound = function(sound) {
|
||||
$("audio").each(function(k, v) {
|
||||
// Stop and reset any sounds that are still playing.
|
||||
v.pause();
|
||||
v.currentTime = 0;
|
||||
});
|
||||
$("#" + sound)[0].play();
|
||||
};
|
||||
|
||||
var transitionBlankToIntro = function(callback) {
|
||||
$("#centering").transition({queue: false, bottom: "0px"}, 500, "ease", function() {
|
||||
$(".teams").transition({queue: false, width: "75px"}, 100, "linear", function() {
|
||||
@@ -207,7 +216,8 @@ $(function() {
|
||||
matchTiming: function(event) { handleMatchTiming(event.data); },
|
||||
matchTime: function(event) { handleMatchTime(event.data); },
|
||||
realtimeScore: function(event) { handleRealtimeScore(event.data); },
|
||||
setFinalScore: function(event) { handleSetFinalScore(event.data); }
|
||||
setFinalScore: function(event) { handleSetFinalScore(event.data); },
|
||||
playSound: function(event) { handlePlaySound(event.data); }
|
||||
});
|
||||
|
||||
// Map how to transition from one screen to another. Missing links between screens indicate that first we
|
||||
|
||||
@@ -98,6 +98,11 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<audio id="match-start" src="/static/audio/match_start.wav" type="audio/wav" preload="auto" />
|
||||
<audio id="match-end" src="/static/audio/match_end.wav" type="audio/wav" preload="auto" />
|
||||
<audio id="match-abort" src="/static/audio/match_abort.mp3" type="audio/mp3" preload="auto" />
|
||||
<audio id="match-resume" src="/static/audio/match_resume.wav" type="audio/wav" preload="auto" />
|
||||
<audio id="match-endgame" src="/static/audio/match_endgame.wav" type="audio/wav" preload="auto" />
|
||||
<script src="/static/js/lib/handlebars-1.3.0.js"></script>
|
||||
<script src="/static/js/lib/jquery.min.js"></script>
|
||||
<script src="/static/js/lib/jquery.json-2.4.min.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user