|
|
|
|
@ -20,14 +20,16 @@ fileprivate enum Const: String { |
|
|
|
|
case confirmationSound = "PVP_Stab_Oneshot_Bleep_Em.wav" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
typealias TimerID = String |
|
|
|
|
|
|
|
|
|
class Conductor: ObservableObject { |
|
|
|
|
|
|
|
|
|
static let maestro: Conductor = Conductor() |
|
|
|
|
|
|
|
|
|
@Published var soundPlayer: SoundPlayer? = nil |
|
|
|
|
|
|
|
|
|
var delaySoundPlayer: DelaySoundPlayer? = nil |
|
|
|
|
|
|
|
|
|
var delayedSoundPlayers: [TimerID : DelaySoundPlayer] = [:] |
|
|
|
|
|
|
|
|
|
@UserDefault(PreferenceKey.countdowns.rawValue, defaultValue: [:]) static var savedCountdowns: [String : DateInterval] |
|
|
|
|
@UserDefault(PreferenceKey.stopwatches.rawValue, defaultValue: [:]) static var savedStopwatches: [String : Date] |
|
|
|
|
|
|
|
|
|
@ -138,9 +140,9 @@ class Conductor: ObservableObject { |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func cancelCountdown(id: String) { |
|
|
|
|
func cancelCountdown(id: TimerID) { |
|
|
|
|
CountdownScheduler.master.cancelCurrentNotifications(countdownId: id) |
|
|
|
|
self.stopSoundIfPossible() |
|
|
|
|
self.cancelSoundPlayer(id: id) |
|
|
|
|
self.cancelledCountdowns.append(id) |
|
|
|
|
self._endCountdown(countdownId: id, cancel: true) |
|
|
|
|
} |
|
|
|
|
@ -163,7 +165,9 @@ class Conductor: ObservableObject { |
|
|
|
|
let soundFile = try SoundFile(fullName: countdown.soundName) |
|
|
|
|
|
|
|
|
|
let soundPlayer = DelaySoundPlayer(soundFile: soundFile) |
|
|
|
|
self.delaySoundPlayer = soundPlayer |
|
|
|
|
|
|
|
|
|
self.delayedSoundPlayers[countdown.stringId] = soundPlayer |
|
|
|
|
|
|
|
|
|
try soundPlayer.start(in: countdown.duration, |
|
|
|
|
repeatCount: Int(countdown.repeatCount)) |
|
|
|
|
|
|
|
|
|
@ -221,7 +225,7 @@ class Conductor: ObservableObject { |
|
|
|
|
fileprivate func _cleanupCountdowns() { |
|
|
|
|
let now = Date() |
|
|
|
|
for (key, value) in self.currentCountdowns { |
|
|
|
|
if value.end < now { |
|
|
|
|
if value.end < now || self.cancelledCountdowns.contains(key) { |
|
|
|
|
self._endCountdown(countdownId: key, cancel: false) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -268,7 +272,14 @@ class Conductor: ObservableObject { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func stopSoundIfPossible() { |
|
|
|
|
func cancelSoundPlayer(id: TimerID) { |
|
|
|
|
if let soundPlayer = self.delayedSoundPlayers[id] { |
|
|
|
|
soundPlayer.stop() |
|
|
|
|
self.delayedSoundPlayers.removeValue(forKey: id) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func stopMainPlayersIfPossible() { |
|
|
|
|
self.soundPlayer?.stop() |
|
|
|
|
self.soundPlayer = nil |
|
|
|
|
} |
|
|
|
|
|