Apply all world side effects using list

This commit is contained in:
2021-04-09 00:47:41 +02:00
parent feec924d5d
commit c42c5069ea
16 changed files with 106 additions and 82 deletions
+11 -8
View File
@@ -6,20 +6,23 @@ module Dodge.Config.Update
import Dodge.Data
import Dodge.Config.Data
import Sound
import Preload.Data
import Data.Aeson (encodeFile)
import Control.Monad (when)
updateDodgeConfig :: World -> IO ()
updateDodgeConfig w = case _menuLayers w of
(ConfigSaveScreen : _) -> do
putStrLn "Saving config to data/dodge.config.json"
encodeFile "data/dodge.config.json" cfig
_ -> when (_configNeedsUpdate w) (setVolume cfig)
where
cfig = _config w
saveConfig :: Configuration -> PreloadData SoundOrigin -> IO (PreloadData SoundOrigin)
saveConfig cfig d = do
putStrLn "Saving config to data/dodge.config.json"
encodeFile "data/dodge.config.json" cfig
return d
setVolume :: Configuration -> IO ()
setVolume cfig = do
setSoundVolume ( _volume_master cfig * _volume_sound cfig)
setMusicVolume ( _volume_master cfig * _volume_music cfig)
setVol :: Configuration -> PreloadData SoundOrigin -> IO (PreloadData SoundOrigin)
setVol cfig d = do
setVolume cfig
return d