Add looping sound, add sound to terminals

This commit is contained in:
2022-03-16 09:23:17 +00:00
parent 5623747b01
commit 5aeb04ba05
24 changed files with 156 additions and 133 deletions
+9 -6
View File
@@ -57,8 +57,8 @@ playSoundAndUpdate sData oldSounds newSounds
mergeSound :: Sound -> Sound -> Sound
mergeSound oldS newS
| _soundChunkID newS == _soundChunkID oldS && _soundStatus newS == ToContinueStart
= newOldChannel & soundStatus .~ _soundStatus oldS
| _soundChunkID newS == _soundChunkID oldS && _playStatus (_soundStatus newS) == ToContinueStart
= newOldChannel & soundStatus . playStatus .~ _playStatus (_soundStatus oldS)
| otherwise = newOldChannel
where
newOldChannel = newS & soundChannel .~ _soundChannel oldS
@@ -74,10 +74,10 @@ updateSound sd s = initialisePlaying sd s
>>= cleanupHalted
initialisePlaying :: IM.IntMap Mix.Chunk -> Sound -> MaybeT IO Sound
initialisePlaying sd s = case _soundStatus s of
initialisePlaying sd s = case _playStatus $ _soundStatus s of
ToStart -> tryPlay sd s
ToContinueStart -> tryPlay sd s
JustStartedPlaying -> return $ s & soundStatus .~ Playing
JustStartedPlaying -> return $ s & soundStatus . playStatus .~ Playing
_ -> return s
tryPlay :: IM.IntMap Mix.Chunk -> Sound -> MaybeT IO Sound
@@ -85,10 +85,13 @@ tryPlay sd s = do
i <- tryGetChannel s
_ <- liftIO $ do
Mix.halt i
Mix.playOn i Mix.Once (sd IM.! _getSoundID (_soundChunkID s))
Mix.playOn i timesToPlay (sd IM.! _getSoundID (_soundChunkID s))
return $ s
& soundChannel ?~ i
& soundStatus .~ JustStartedPlaying
& soundStatus . playStatus .~ JustStartedPlaying
where
timesToPlay | _isLooping (_soundStatus s) = Mix.Forever
| otherwise = Mix.Once
tryGetChannel :: Sound -> MaybeT IO Mix.Channel
tryGetChannel s = case _soundChannel s of