Linting, haddocking
This commit is contained in:
+16
-10
@@ -9,6 +9,8 @@ module Dodge.Config.Data (
|
||||
, volume_music
|
||||
, wall_textured
|
||||
, shadow_resolution
|
||||
, windowX
|
||||
, windowY
|
||||
) where
|
||||
|
||||
import Data.Aeson
|
||||
@@ -20,11 +22,13 @@ import System.Directory
|
||||
import Control.Lens
|
||||
|
||||
data Configuration = Configuration
|
||||
{ _volume_master :: Float
|
||||
, _volume_sound :: Float
|
||||
, _volume_music :: Float
|
||||
, _wall_textured :: Bool
|
||||
, _shadow_resolution :: Int -- ^ Higher values divide the screen size, i.e. make the resolution worse
|
||||
{ _volume_master :: Float
|
||||
, _volume_sound :: Float
|
||||
, _volume_music :: Float
|
||||
, _wall_textured :: Bool
|
||||
, _shadow_resolution :: Int -- ^ Higher values divide screen size, i.e. make the resolution worse
|
||||
, _windowX :: Float
|
||||
, _windowY :: Float
|
||||
}
|
||||
deriving (Generic, Show)
|
||||
|
||||
@@ -36,10 +40,12 @@ instance ToJSON Configuration where
|
||||
instance FromJSON Configuration
|
||||
|
||||
defaultConfig = Configuration
|
||||
{ _volume_master = 1
|
||||
, _volume_sound = 1
|
||||
, _volume_music = 1
|
||||
, _wall_textured = False
|
||||
, _shadow_resolution = 1
|
||||
{ _volume_master = 1
|
||||
, _volume_sound = 1
|
||||
, _volume_music = 1
|
||||
, _wall_textured = False
|
||||
, _shadow_resolution = 1
|
||||
, _windowX = 800
|
||||
, _windowY = 600
|
||||
}
|
||||
|
||||
|
||||
@@ -7,22 +7,39 @@ 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
|
||||
|
||||
setVolume :: Configuration -> IO ()
|
||||
setVolume cfig = do
|
||||
setSoundVolume ( _volume_master cfig * _volume_sound cfig)
|
||||
setMusicVolume ( _volume_master cfig * _volume_music cfig)
|
||||
|
||||
{- |
|
||||
Apply the volume settings from the world configuration to the running game.
|
||||
-}
|
||||
setVol :: Configuration -> PreloadData SoundOrigin -> IO (PreloadData SoundOrigin)
|
||||
setVol cfig d = do
|
||||
setVolume cfig
|
||||
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)
|
||||
where
|
||||
x = round $ _windowX cfig
|
||||
y = round $ _windowY cfig
|
||||
divRes = _shadow_resolution cfig
|
||||
|
||||
Reference in New Issue
Block a user