Pause and resume sounds when pausing game
This commit is contained in:
+1
-1
@@ -190,7 +190,7 @@ gameOverMenu u =
|
||||
--charToScode = Scancode . fromIntegral . (\x -> x - 61) . fromEnum
|
||||
|
||||
unpause :: Universe -> Universe
|
||||
unpause = over uvWorld resumeSound . set uvScreenLayers []
|
||||
unpause = resumeSound . set uvScreenLayers []
|
||||
|
||||
-- note that this won't update after it is first loaded
|
||||
displayConfig :: Universe -> ScreenLayer
|
||||
|
||||
+12
-6
@@ -27,23 +27,29 @@ import Control.Lens
|
||||
import Data.Int (Int16)
|
||||
import qualified Data.Map as M
|
||||
import Data.Maybe
|
||||
import Dodge.Data.World
|
||||
import Dodge.Data.Universe
|
||||
import Dodge.SoundLogic.LoadSound
|
||||
import Geometry.Data
|
||||
import Geometry.Vector
|
||||
import Sound.Data
|
||||
import SDL.Mixer as Mix
|
||||
|
||||
-- | Placeholder...
|
||||
haltSound :: World -> World
|
||||
haltSound w = w
|
||||
haltSound = id
|
||||
|
||||
-- | Placeholder...
|
||||
pauseSound :: World -> World
|
||||
pauseSound w = w
|
||||
pauseSound :: Universe -> Universe
|
||||
pauseSound = uvIOEffects %~ \f u -> do
|
||||
Mix.pause (-1)
|
||||
f u
|
||||
|
||||
-- | Placeholder...
|
||||
resumeSound :: World -> World
|
||||
resumeSound w = w
|
||||
resumeSound :: Universe -> Universe
|
||||
resumeSound = uvIOEffects %~ \f u -> do
|
||||
Mix.resume (-1)
|
||||
f u
|
||||
|
||||
|
||||
soundWithStatusVolume ::
|
||||
-- | Volume factor, 0 - 1
|
||||
|
||||
@@ -13,9 +13,15 @@ loadSound (i,s) = do
|
||||
chnk <- Mix.load $ "./data/sound/" ++ s
|
||||
return (i,chnk)
|
||||
|
||||
-- current thinking is to use group 0 for game sounds, group 1 for menu sounds
|
||||
loadSounds :: IO (IM.IntMap Mix.Chunk)
|
||||
loadSounds = do
|
||||
Mix.openAudio Mix.defaultAudio 128
|
||||
Mix.setChannels 32
|
||||
x <- Mix.groupSpan 0 0 29
|
||||
putStrLn $ show x <> " channels assigned to group 0"
|
||||
y <- Mix.groupSpan 1 30 31
|
||||
putStrLn $ show y <> " channels assigned to group 1"
|
||||
fmap IM.fromList $ mapM loadSound $ zip [0..] soundPathList
|
||||
|
||||
loadMusic :: IO (IM.IntMap Mix.Music)
|
||||
|
||||
@@ -500,6 +500,7 @@ updateEnterRegex w = case w ^? hud . hudElement . subInventory of
|
||||
|
||||
pauseGame :: Universe -> Universe
|
||||
pauseGame u = u & uvScreenLayers .~ [pauseMenu u]
|
||||
& pauseSound
|
||||
|
||||
spaceAction :: World -> World
|
||||
spaceAction w = case w ^. hud . hudElement of
|
||||
|
||||
+6
-7
@@ -1,12 +1,11 @@
|
||||
module Preload
|
||||
( cleanUpPreload
|
||||
)
|
||||
where
|
||||
module Preload (
|
||||
cleanUpPreload,
|
||||
) where
|
||||
|
||||
import Data.Preload
|
||||
import Preload.Render
|
||||
import Sound.Data
|
||||
|
||||
import qualified SDL.Mixer as Mix
|
||||
import Sound.Data
|
||||
|
||||
cleanUpPreload :: PreloadData -> IO ()
|
||||
cleanUpPreload pd = do
|
||||
@@ -14,4 +13,4 @@ cleanUpPreload pd = do
|
||||
cleanUpSoundPreload $ _soundData pd
|
||||
|
||||
cleanUpSoundPreload :: SoundData -> IO ()
|
||||
cleanUpSoundPreload _ = Mix.closeAudio
|
||||
cleanUpSoundPreload _ = Mix.closeAudio >> putStrLn "Audio closed"
|
||||
|
||||
+2
-2
@@ -96,7 +96,7 @@ tryPlay sd s = do
|
||||
tryGetChannel :: Sound -> MaybeT IO Mix.Channel
|
||||
tryGetChannel s = case _soundChannel s of
|
||||
Just i -> return i
|
||||
Nothing -> MaybeT $ Mix.getAvailable Mix.DefaultGroup
|
||||
Nothing -> MaybeT $ Mix.getAvailable 0 -- 0 refers to the group for game sounds
|
||||
|
||||
decrementTimer :: Sound -> IO Sound
|
||||
decrementTimer s = case _soundTime s of
|
||||
@@ -135,7 +135,7 @@ playSoundQueue chunkMap = mapM_ $ \n -> runMaybeT $ playIfFree (chunkMap IM.! n)
|
||||
times. Returns 'Just' the channel if succeeds. -}
|
||||
playIfFree :: Mix.Chunk -> Mix.Times -> MaybeT IO Mix.Channel
|
||||
playIfFree c times = do
|
||||
i <- MaybeT $ Mix.getAvailable Mix.DefaultGroup
|
||||
i <- MaybeT $ Mix.getAvailable 0 -- 0 refers to the group for game sounds
|
||||
liftIO $ Mix.playOn i times c
|
||||
|
||||
-----------------------------------------------------------------
|
||||
|
||||
+2
-2
@@ -50,8 +50,8 @@ data Sound = Sound
|
||||
{ _soundTime :: Maybe Int
|
||||
, _soundStatus :: SoundStatus
|
||||
, _soundChannel :: Maybe Mix.Channel
|
||||
, _soundAngDist :: Maybe (Int16, Word8) -- why do BOTH of
|
||||
, _soundPos :: Point2 -- these exist?
|
||||
, _soundAngDist :: Maybe (Int16, Word8)
|
||||
, _soundPos :: Point2
|
||||
, _soundVolume :: Float
|
||||
, _soundVolumeFraction :: Float -- this needs cleaning up/combining
|
||||
, _soundChunkID :: SoundID
|
||||
|
||||
Reference in New Issue
Block a user