mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 21:56:50 -04:00
Add warning sound when there is one minute remaining in a timeout (closes #121).
This commit is contained in:
@@ -349,6 +349,8 @@ func (arena *Arena) StartTimeout(durationSec int) error {
|
||||
}
|
||||
|
||||
game.MatchTiming.TimeoutDurationSec = durationSec
|
||||
game.UpdateMatchSounds()
|
||||
arena.soundsPlayed = make(map[*game.MatchSound]struct{})
|
||||
arena.MatchTimingNotifier.Notify()
|
||||
arena.MatchState = TimeoutActive
|
||||
arena.MatchStartTime = time.Now()
|
||||
@@ -458,7 +460,6 @@ func (arena *Arena) Update() {
|
||||
case TimeoutActive:
|
||||
if matchTimeSec >= float64(game.MatchTiming.TimeoutDurationSec) {
|
||||
arena.MatchState = PostTimeout
|
||||
arena.playSound("end")
|
||||
go func() {
|
||||
// Leave the timer on the screen briefly at the end of the timeout period.
|
||||
time.Sleep(time.Second * matchEndScoreDwellSec)
|
||||
@@ -798,7 +799,7 @@ func (arena *Arena) handleEstop(station string, state bool) {
|
||||
}
|
||||
|
||||
func (arena *Arena) handleSounds(matchTimeSec float64) {
|
||||
if arena.MatchState == PreMatch || arena.MatchState == TimeoutActive || arena.MatchState == PostTimeout {
|
||||
if arena.MatchState == PreMatch {
|
||||
// Only apply this logic during a match.
|
||||
return
|
||||
}
|
||||
@@ -808,8 +809,13 @@ func (arena *Arena) handleSounds(matchTimeSec float64) {
|
||||
// Skip sounds with negative timestamps; they are meant to only be triggered explicitly.
|
||||
continue
|
||||
}
|
||||
if sound.Timeout && !(arena.MatchState == TimeoutActive || arena.MatchState == PostTimeout) ||
|
||||
!sound.Timeout && (arena.MatchState == TimeoutActive || arena.MatchState == PostTimeout) {
|
||||
// Skip timeout sounds if this is a regular match, and vice versa.
|
||||
continue
|
||||
}
|
||||
if _, ok := arena.soundsPlayed[sound]; !ok {
|
||||
if matchTimeSec > sound.MatchTimeSec {
|
||||
if matchTimeSec > sound.MatchTimeSec && matchTimeSec-sound.MatchTimeSec < 1 {
|
||||
arena.playSound(sound.Name)
|
||||
arena.soundsPlayed[sound] = struct{}{}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ type MatchSound struct {
|
||||
Name string
|
||||
FileExtension string
|
||||
MatchTimeSec float64
|
||||
Timeout bool
|
||||
}
|
||||
|
||||
// List of sounds and how many seconds into the match they are played. A negative time indicates that the sound can only
|
||||
@@ -17,13 +18,56 @@ var MatchSounds []*MatchSound
|
||||
|
||||
func UpdateMatchSounds() {
|
||||
MatchSounds = []*MatchSound{
|
||||
{"start", "wav", 0},
|
||||
{"end", "wav", float64(MatchTiming.AutoDurationSec)},
|
||||
{"resume", "wav", float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec)},
|
||||
{"warning", "wav", float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec +
|
||||
MatchTiming.TeleopDurationSec - MatchTiming.WarningRemainingDurationSec)},
|
||||
{"end", "wav", float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec +
|
||||
MatchTiming.TeleopDurationSec)},
|
||||
{"abort", "wav", -1},
|
||||
{
|
||||
"start",
|
||||
"wav",
|
||||
0,
|
||||
false,
|
||||
},
|
||||
{
|
||||
"end",
|
||||
"wav",
|
||||
float64(MatchTiming.AutoDurationSec),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"resume",
|
||||
"wav",
|
||||
float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"warning",
|
||||
"wav",
|
||||
float64(
|
||||
MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec + MatchTiming.TeleopDurationSec -
|
||||
MatchTiming.WarningRemainingDurationSec,
|
||||
),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"end",
|
||||
"wav",
|
||||
float64(MatchTiming.AutoDurationSec + MatchTiming.PauseDurationSec + MatchTiming.TeleopDurationSec),
|
||||
false,
|
||||
},
|
||||
{
|
||||
"timeout_warning",
|
||||
"wav",
|
||||
float64(MatchTiming.TimeoutDurationSec - MatchTiming.TimeoutWarningRemainingDurationSec),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"end",
|
||||
"wav",
|
||||
float64(MatchTiming.TimeoutDurationSec),
|
||||
true,
|
||||
},
|
||||
{
|
||||
"abort",
|
||||
"wav",
|
||||
-1,
|
||||
false,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,13 +8,14 @@ package game
|
||||
import "time"
|
||||
|
||||
var MatchTiming = struct {
|
||||
WarmupDurationSec int
|
||||
AutoDurationSec int
|
||||
PauseDurationSec int
|
||||
TeleopDurationSec int
|
||||
WarningRemainingDurationSec int
|
||||
TimeoutDurationSec int
|
||||
}{0, 15, 2, 135, 30, 0}
|
||||
WarmupDurationSec int
|
||||
AutoDurationSec int
|
||||
PauseDurationSec int
|
||||
TeleopDurationSec int
|
||||
WarningRemainingDurationSec int
|
||||
TimeoutDurationSec int
|
||||
TimeoutWarningRemainingDurationSec int
|
||||
}{0, 15, 2, 135, 30, 0, 60}
|
||||
|
||||
func GetDurationToAutoEnd() time.Duration {
|
||||
return time.Duration(MatchTiming.WarmupDurationSec+MatchTiming.AutoDurationSec) * time.Second
|
||||
|
||||
BIN
static/audio/timeout_warning.wav
Normal file
BIN
static/audio/timeout_warning.wav
Normal file
Binary file not shown.
Reference in New Issue
Block a user