Add (persistent) volume control

This commit is contained in:
jgk
2021-04-08 11:06:02 +02:00
parent f1214c0584
commit ea0dfbe1df
8 changed files with 76 additions and 54 deletions
+10 -7
View File
@@ -1,10 +1,10 @@
{-|
IO actions that apply config side effects and save it to disk.
IO actions that apply config side effects and save configuration settings to disk.
-}
module Dodge.Config.Update
where
import Dodge.Data
import Dodge.LoadConfig
import Dodge.Config.Data
import Sound
import Data.Aeson (encodeFile)
@@ -12,11 +12,14 @@ import Control.Monad (when)
updateDodgeConfig :: World -> IO ()
updateDodgeConfig w = case _menuLayers w of
(ConfigSaveScreen _: _) -> do
putStrLn "Saving config"
(ConfigSaveScreen : _) -> do
putStrLn "Saving config to data/dodge.config.json"
encodeFile "data/dodge.config.json" cfig
_ -> when (_configNeedsUpdate w) $ do
setSoundVolume ( _volume_master cfig * _volume_sound cfig)
setMusicVolume ( _volume_master cfig * _volume_music cfig)
_ -> when (_configNeedsUpdate w) (setVolume cfig)
where
cfig = _config w
setVolume :: Configuration -> IO ()
setVolume cfig = do
setSoundVolume ( _volume_master cfig * _volume_sound cfig)
setMusicVolume ( _volume_master cfig * _volume_music cfig)