Files
loop/src/Dodge/Config/Update.hs
T
2021-05-17 22:39:18 +02:00

45 lines
1.3 KiB
Haskell

{-|
IO actions that apply config side effects and save configuration settings to disk.
-}
module Dodge.Config.Update
where
import Dodge.Data.SoundOrigin
import Dodge.Config.Data
import Sound
import Preload.Data
import Preload.Update
import Data.Aeson (encodeFile)
--import Control.Monad (when)
{- |
Write the current world configuration to disk as a json file.
-}
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
{- |
Apply the volume settings from the world configuration to the running game.
-}
setVol :: Configuration -> PreloadData SoundOrigin -> IO (PreloadData SoundOrigin)
setVol cfig d = do
setSoundVolume ( _volume_master cfig * _volume_sound cfig)
setMusicVolume ( _volume_master cfig * _volume_music cfig)
return d
{- |
Apply /all/ of the values in the world configuration to the running game.
-}
applyWorldConfig
:: Configuration
-> PreloadData SoundOrigin
-> IO (PreloadData SoundOrigin)
applyWorldConfig cfig pdata = do
setVol cfig pdata >>= resizeSpareFBO (x `div` divRes) (y `div` divRes) x y
where
x = round $ _windowX cfig
y = round $ _windowY cfig
divRes = _shadow_resolution cfig