Move towards incorporating sound into ai
This commit is contained in:
+9
-6
@@ -13,7 +13,7 @@ module Sound (
|
||||
playSoundQueue
|
||||
, playPositionalSoundQueue
|
||||
-- * Complex Playback
|
||||
, playAndUpdate
|
||||
, playSoundAndUpdate
|
||||
-- * Volume Control
|
||||
, setSoundVolume
|
||||
, setMusicVolume
|
||||
@@ -49,8 +49,8 @@ In the update:
|
||||
3. apply 'Just' sound position effects, set value to 'Nothing'
|
||||
4. remove sounds that have stopped playing from the map.
|
||||
-}
|
||||
playAndUpdate :: Ord a => SoundData a -> M.Map a Sound -> IO (M.Map a Sound)
|
||||
playAndUpdate sData newSounds
|
||||
playSoundAndUpdate :: Ord a => SoundData a -> M.Map a Sound -> IO (M.Map a Sound)
|
||||
playSoundAndUpdate sData newSounds
|
||||
= updateSounds (_loadedChunks sData) (M.unionWith mergeSound (_playingSounds sData) newSounds)
|
||||
|
||||
mergeSound :: Sound -> Sound -> Sound
|
||||
@@ -74,6 +74,7 @@ updateSound sd s =
|
||||
initialisePlaying :: IM.IntMap Mix.Chunk -> Sound -> MaybeT IO Sound
|
||||
initialisePlaying sd s = case _soundStatus s of
|
||||
ToStart -> tryPlay sd s
|
||||
JustStartedPlaying -> return $ s & soundStatus .~ Playing
|
||||
_ -> return s
|
||||
|
||||
tryPlay :: IM.IntMap Mix.Chunk -> Sound -> MaybeT IO Sound
|
||||
@@ -84,7 +85,7 @@ tryPlay sd s = do
|
||||
Mix.playOn i Mix.Once (sd IM.! _soundChunkID s)
|
||||
return $ s
|
||||
& soundChannel ?~ i
|
||||
& soundStatus .~ Playing
|
||||
& soundStatus .~ JustStartedPlaying
|
||||
|
||||
--repetitions :: Sound -> Mix.Times
|
||||
--repetitions s = case _soundTime s of
|
||||
@@ -96,6 +97,8 @@ tryGetChannel s = case _soundChannel s of
|
||||
Just i -> return i
|
||||
Nothing -> MaybeT $ Mix.getAvailable Mix.DefaultGroup
|
||||
|
||||
|
||||
|
||||
decrementTimer :: Sound -> IO Sound
|
||||
decrementTimer s = case _soundTime s of
|
||||
Just t
|
||||
@@ -106,10 +109,10 @@ decrementTimer s = case _soundTime s of
|
||||
Nothing -> return s
|
||||
|
||||
applyPosition :: Sound -> IO Sound
|
||||
applyPosition s = case _soundPos s of
|
||||
applyPosition s = case _soundAngDist s of
|
||||
Nothing -> return s
|
||||
Just (a,d) -> Mix.effectPosition (fromJust $ _soundChannel s) a d
|
||||
>> return (s & soundPos .~ Nothing)
|
||||
>> return (s & soundAngDist .~ Nothing)
|
||||
|
||||
fadeOutMaybe
|
||||
:: Maybe Mix.Channel
|
||||
|
||||
Reference in New Issue
Block a user