Move config options

This commit is contained in:
2022-04-11 09:04:51 +01:00
parent ab2408b480
commit d46d315203
8 changed files with 30 additions and 31 deletions
+10 -10
View File
@@ -9,15 +9,15 @@ data Configuration = Configuration
{ _volume_master :: Float { _volume_master :: Float
, _volume_sound :: Float , _volume_sound :: Float
, _volume_music :: Float , _volume_music :: Float
, _wall_textured :: Bool , _graphics_wall_textured :: Bool
, _cloud_shadows :: Bool , _graphics_cloud_shadows :: Bool
, _resolution_factor :: ResFactor , _graphics_resolution_factor :: ResFactor
, _windowX :: Float , _windowX :: Float
, _windowY :: Float , _windowY :: Float
, _windowPosX :: Int , _windowPosX :: Int
, _windowPosY :: Int , _windowPosY :: Int
, _rotate_to_wall :: Bool , _gameplay_rotate_to_wall :: Bool
, _show_sound :: Bool , _debug_show_sound :: Bool
, _debug_seconds_frame :: Bool , _debug_seconds_frame :: Bool
, _debug_noclip :: Bool , _debug_noclip :: Bool
, _debug_cr_status :: Bool , _debug_cr_status :: Bool
@@ -55,15 +55,15 @@ defaultConfig = Configuration
{ _volume_master = 1 { _volume_master = 1
, _volume_sound = 1 , _volume_sound = 1
, _volume_music = 1 , _volume_music = 1
, _wall_textured = True , _graphics_wall_textured = True
, _cloud_shadows = True , _graphics_cloud_shadows = True
, _resolution_factor = FullRes , _graphics_resolution_factor = FullRes
, _windowX = 800 , _windowX = 800
, _windowY = 600 , _windowY = 600
, _windowPosX = 0 , _windowPosX = 0
, _windowPosY = 0 , _windowPosY = 0
, _rotate_to_wall = True , _gameplay_rotate_to_wall = True
, _show_sound = False , _debug_show_sound = False
, _debug_seconds_frame = True , _debug_seconds_frame = True
, _debug_noclip = False , _debug_noclip = False
, _debug_cr_status = False , _debug_cr_status = False
+4 -5
View File
@@ -12,8 +12,7 @@ import Sound
import Data.Preload import Data.Preload
import Preload.Update import Preload.Update
--import Data.Aeson (encodeFile) import qualified Data.Aeson.Encode.Pretty as AEP
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Lazy as BS import qualified Data.ByteString.Lazy as BS
--import Control.Monad (when) --import Control.Monad (when)
{- | {- |
@@ -22,8 +21,8 @@ Write the current world configuration to disk as a json file.
saveConfig :: Configuration -> (a -> IO a) -> a -> IO a saveConfig :: Configuration -> (a -> IO a) -> a -> IO a
saveConfig cfig f x = do saveConfig cfig f x = do
putStrLn "Saving config to data/dodge.config.json" putStrLn "Saving config to data/dodge.config.json"
BS.writeFile "data/dodge.config.json" $ encodePretty cfig BS.writeFile "data/dodge.config.json"
-- encodeFile "data/dodge.config.json" cfig $ AEP.encodePretty' (AEP.Config (AEP.Spaces 2) compare (AEP.Generic) (False)) cfig
f x f x
{- | {- |
Apply the volume settings from the world configuration to the running game. Apply the volume settings from the world configuration to the running game.
@@ -50,4 +49,4 @@ applyWorldConfig cfig pdata = do
where where
x = round $ _windowX cfig x = round $ _windowX cfig
y = round $ _windowY cfig y = round $ _windowY cfig
divRes = resFactorNum $ _resolution_factor cfig divRes = resFactorNum $ _graphics_resolution_factor cfig
+1 -1
View File
@@ -86,7 +86,7 @@ handleResizeEvent sev u = return . Just $ u
x = fromIntegral x' x = fromIntegral x'
y = fromIntegral y' y = fromIntegral y'
V2 x' y' = windowSizeChangedEventSize sev V2 x' y' = windowSizeChangedEventSize sev
divRes = resFactorNum $ u ^. config . resolution_factor divRes = resFactorNum $ u ^. config . graphics_resolution_factor
handlePressedMouseButton :: MouseButton -> Universe -> Maybe Universe handlePressedMouseButton :: MouseButton -> Universe -> Maybe Universe
handlePressedMouseButton but w = case (_hudElement (_hud $ _uvWorld w), but) of handlePressedMouseButton but w = case (_hudElement (_hud $ _uvWorld w), but) of
+6 -6
View File
@@ -77,11 +77,12 @@ debugMenuOptions :: [MenuOption]
debugMenuOptions = debugMenuOptions =
[ doption ScancodeF debug_seconds_frame "SHOW SECONDS/FRAME" _debug_seconds_frame [ doption ScancodeF debug_seconds_frame "SHOW SECONDS/FRAME" _debug_seconds_frame
, doption ScancodeC debug_noclip "NOCLIP" _debug_noclip , doption ScancodeC debug_noclip "NOCLIP" _debug_noclip
, doption ScancodeS debug_cr_status "SHOW CREATURE STATUS" _debug_cr_status , doption ScancodeT debug_cr_status "SHOW CREATURE STATUS" _debug_cr_status
, doption ScancodeA debug_cr_awareness "SHOW CREATURE AWARENESS" _debug_cr_awareness , doption ScancodeA debug_cr_awareness "SHOW CREATURE AWARENESS" _debug_cr_awareness
, doption ScancodeV debug_view_boundaries "SHOW VIEW BOUNDARIES" _debug_view_boundaries , doption ScancodeV debug_view_boundaries "SHOW VIEW BOUNDARIES" _debug_view_boundaries
, makeEnumOption ScancodeB debug_view_clip_bounds "SHOW ROOM CLIP" return , makeEnumOption ScancodeB debug_view_clip_bounds "SHOW ROOM CLIP" return
, doption ScancodeP debug_pathing "SHOW PATHING" _debug_pathing , doption ScancodeP debug_pathing "SHOW PATHING" _debug_pathing
, doption ScancodeS debug_show_sound "SHOW VISUAL SOUNDS" _debug_show_sound
] ]
where where
doption scode l t rec doption scode l t rec
@@ -93,8 +94,7 @@ gameplayMenu = slTitleOptions
gameplayMenuOptions :: [MenuOption] gameplayMenuOptions :: [MenuOption]
gameplayMenuOptions = gameplayMenuOptions =
[ makeBoolOption ScancodeR rotate_to_wall "ROTATE TO WALL" [ makeBoolOption ScancodeR gameplay_rotate_to_wall "ROTATE TO WALL"
, makeBoolOption ScancodeS show_sound "SHOW VISUAL SOUNDS"
] ]
soundMenu :: ScreenLayer soundMenu :: ScreenLayer
@@ -128,9 +128,9 @@ graphicsMenu = slTitleOptions "OPTIONS:GRAPHICS" graphicsMenuOptions
graphicsMenuOptions :: [MenuOption] graphicsMenuOptions :: [MenuOption]
graphicsMenuOptions = graphicsMenuOptions =
[ makeEnumOption ScancodeS resolution_factor "RESOLUTION" updateFramebufferSize [ makeEnumOption ScancodeS graphics_resolution_factor "RESOLUTION" updateFramebufferSize
, makeBoolOption ScancodeW wall_textured "WALL TEXTURES" , makeBoolOption ScancodeW graphics_wall_textured "WALL TEXTURES"
, makeBoolOption ScancodeD cloud_shadows "CLOUD SHADOWS" , makeBoolOption ScancodeD graphics_cloud_shadows "CLOUD SHADOWS"
] ]
gameOverMenu :: ScreenLayer gameOverMenu :: ScreenLayer
+1 -1
View File
@@ -26,4 +26,4 @@ updateFramebufferSize u = updatePreload divRes x y u
where where
(x,y) = (round $ _windowX cfig, round $ _windowY cfig) (x,y) = (round $ _windowX cfig, round $ _windowY cfig)
cfig = _config u cfig = _config u
divRes = resFactorNum $ u ^. config . resolution_factor divRes = resFactorNum $ u ^. config . graphics_resolution_factor
+3 -3
View File
@@ -37,7 +37,7 @@ doDrawing pdata u = do
camzoom = _cameraZoom w camzoom = _cameraZoom w
trans = _cameraCenter w trans = _cameraCenter w
wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig) wins@(V2 winx winy) = V2 (_windowX cfig) (_windowY cfig)
resFact = resFactorNum $ cfig ^. resolution_factor resFact = resFactorNum $ cfig ^. graphics_resolution_factor
(wallPointsCol,windowPoints) = wallsAndWindows cfig w (wallPointsCol,windowPoints) = wallsAndWindows cfig w
lightPoints = lightsForGloom w lightPoints = lightsForGloom w
viewFroms@(V2 vfx vfy) = _cameraViewFrom w viewFroms@(V2 vfx vfy) = _cameraViewFrom w
@@ -112,7 +112,7 @@ doDrawing pdata u = do
0 0
(fromIntegral nWalls) (fromIntegral nWalls)
--draw walls onto base buffer --draw walls onto base buffer
if cfig ^. wall_textured if cfig ^. graphics_wall_textured
then renderTextureWalls pdata nWalls then renderTextureWalls pdata nWalls
else renderBlankWalls pdata nWalls else renderBlankWalls pdata nWalls
--draw object pictures onto base buffer --draw object pictures onto base buffer
@@ -174,7 +174,7 @@ doDrawing pdata u = do
renderLayer MidLayer shadV layerCounts renderLayer MidLayer shadV layerCounts
--renderWindows pdata windowPoints --renderWindows pdata windowPoints
drawShader (_windowShader pdata) nWins drawShader (_windowShader pdata) nWins
when (_cloud_shadows cfig) $ do when (_graphics_cloud_shadows cfig) $ do
----render transparency depths ----render transparency depths
depthMask $= Enabled depthMask $= Enabled
blend $= Disabled blend $= Disabled
+4 -4
View File
@@ -79,7 +79,7 @@ mcSPic bt = uncurryV translateSPf (_mcPos bt)
soundPics :: Configuration -> World -> Picture soundPics :: Configuration -> World -> Picture
soundPics cfig w soundPics cfig w
| _show_sound cfig = pictures $ M.map (soundPic cfig w) $ _playingSounds w | _debug_show_sound cfig = pictures $ M.map (soundPic cfig w) $ _playingSounds w
| otherwise = [] | otherwise = []
soundPic :: Configuration -> World -> Sound -> Picture soundPic :: Configuration -> World -> Sound -> Picture
@@ -122,9 +122,9 @@ crDisplayInfo cfig w cr
drawCrInfo :: Configuration -> World -> Picture drawCrInfo :: Configuration -> World -> Picture
drawCrInfo cfig w drawCrInfo cfig w
-- | _debug_cr_awareness cfig = setLayer FixedCoordLayer | _debug_cr_status cfig = setLayer FixedCoordLayer
-- $ renderInfoListsAt (2*hw - 200) 0 cfig w $ renderInfoListsAt (2*hw - 200) 0 cfig w
-- $ mapMaybe (crDisplayInfo cfig w) $ IM.elems $ _creatures w $ mapMaybe (crDisplayInfo cfig w) $ IM.elems $ _creatures w
| otherwise = mempty | otherwise = mempty
where where
hw = halfWidth cfig hw = halfWidth cfig
+1 -1
View File
@@ -97,7 +97,7 @@ zoomOutLongGun w
ifConfigWallRotate :: Configuration -> World -> World ifConfigWallRotate :: Configuration -> World -> World
ifConfigWallRotate cfig w ifConfigWallRotate cfig w
| _rotate_to_wall cfig && not (SDL.ButtonRight `S.member` _mouseButtons w) | _gameplay_rotate_to_wall cfig && not (SDL.ButtonRight `S.member` _mouseButtons w)
= rotateToOverlappingWall w = rotateToOverlappingWall w
| otherwise = w | otherwise = w