This commit is contained in:
2022-07-27 12:49:23 +01:00
parent 6554d219dc
commit 8d17ce66e9
106 changed files with 2911 additions and 2678 deletions
-112
View File
@@ -1,112 +0,0 @@
--{-# LANGUAGE FlexibleInstances #-}
--{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-}
module Dodge.Config.Data where
import Data.Aeson
import qualified Data.Set as S
import GHC.Generics
import Control.Lens
--import Data.Enum.Set.Base
{-# ANN module "HLint: ignore Use camelCase" #-}
data Configuration = Configuration
{ _volume_master :: Float
, _volume_sound :: Float
, _volume_music :: Float
, _graphics_wall_textured :: Bool
, _graphics_cloud_shadows :: Bool
, _graphics_object_shadows :: Bool
, _graphics_resolution_factor :: ResFactor
, _windowX :: Float
, _windowY :: Float
, _windowPosX :: Int
, _windowPosY :: Int
, _gameplay_rotate_to_wall :: Bool
, _debug_view_clip_bounds :: RoomClipping
, _debug_booleans :: S.Set DebugBool -- consider using Data.BitSet
}
deriving (Generic, Show)
data DebugBool
= Show_ms_frame
| Show_debug
| Show_sound
| Noclip
| Cr_status
| Cr_awareness
| Mouse_position
| View_boundaries
| Walls_info
| Pathing
| Remove_LOS
| Cull_more_lights
| Close_shape_culling
| Show_bound_box
| Bound_box_screen
| Show_wall_search_rays
| Show_dda_test
| Show_far_wall_detect
| Show_select
| Inspect_wall
| Show_nodes_near_select
| Show_path_between
deriving (Generic, Eq,Ord,Bounded, Enum, Show)
data ResFactor = FullRes | HalfRes | QuarterRes
deriving (Generic, Show, Eq, Ord, Enum, Bounded)
instance ToJSON ResFactor where
toEncoding = genericToEncoding defaultOptions
instance FromJSON ResFactor
data RoomClipping = NoRoomClipBoundaries | AllRoomClipBoundaries | IntersectingRoomClipBoundaries
deriving (Generic, Show, Eq, Ord, Enum, Bounded)
instance ToJSON RoomClipping where
toEncoding = genericToEncoding defaultOptions
instance FromJSON RoomClipping
resFactorNum :: ResFactor -> Int
resFactorNum rf = case rf of
FullRes -> 1
HalfRes -> 2
QuarterRes -> 4
makeLenses ''Configuration
instance ToJSON DebugBool where
toEncoding = genericToEncoding defaultOptions
instance ToJSON Configuration where
toEncoding = genericToEncoding defaultOptions
--deriving instance Generic a => Generic (EnumSet Word a)
--instance FromJSON (EnumSet Word a)
instance FromJSON DebugBool
instance FromJSON Configuration
defaultConfig :: Configuration
defaultConfig = Configuration
{ _volume_master = 1
, _volume_sound = 1
, _volume_music = 1
, _graphics_wall_textured = True
, _graphics_cloud_shadows = True
, _graphics_object_shadows = True
, _graphics_resolution_factor = FullRes
, _windowX = 800
, _windowY = 600
, _windowPosX = 0
, _windowPosY = 0
, _gameplay_rotate_to_wall = True
, _debug_booleans = S.singleton Show_ms_frame
, _debug_view_clip_bounds = NoRoomClipBoundaries
-- , _debug_show_sound = False
-- , _debug_seconds_frame = True
-- , _debug_noclip = False
-- , _debug_mouse_position = False
-- , _debug_cr_status = False
-- , _debug_cr_awareness = False
-- , _debug_view_boundaries = False
-- , _debug_pathing = False
-- , _debug_walls = False
-- , _debug_remove_LOS = False
-- , _debug_cull_more_lights = False
}
debugOn :: DebugBool -> Configuration -> Bool
debugOn db = S.member db . _debug_booleans
+13 -13
View File
@@ -1,22 +1,22 @@
module Dodge.Config.Load
( loadDodgeConfig
) where
import Dodge.Config.Data
module Dodge.Config.Load (
loadDodgeConfig,
) where
import Data.Aeson
import Dodge.Data.Config
import System.Directory
loadDodgeConfig :: IO Configuration
loadDodgeConfig = do
fExists <- doesFileExist "data/dodge.config.json"
if fExists
then do
mayConfig <- decodeFileStrict "data/dodge.config.json"
case mayConfig of
Just config -> return config
Nothing -> do
putStrLn "invalid data/dodge.config.json, loading defaults"
then do
mayConfig <- decodeFileStrict "data/dodge.config.json"
case mayConfig of
Just config -> return config
Nothing -> do
putStrLn "invalid data/dodge.config.json, loading defaults"
return defaultConfig
else do
putStrLn "No data/data/dodge.config.json found, loading defaults"
return defaultConfig
else do
putStrLn "No data/data/dodge.config.json found, loading defaults"
return defaultConfig
+28 -26
View File
@@ -1,51 +1,53 @@
{-|
{- |
IO actions that apply config side effects and save configuration settings to disk.
-}
module Dodge.Config.Update
( saveConfig
, setVolThen
, applyWorldConfig
, setVol
) where
--import Dodge.Data.SoundOrigin
import Dodge.Config.Data
import Sound
import Data.Preload
import Preload.Update
module Dodge.Config.Update (
saveConfig,
setVolThen,
applyWorldConfig,
setVol,
) where
import qualified Data.Aeson.Encode.Pretty as AEP
import qualified Data.ByteString.Lazy as BS
--import Control.Monad (when)
import Data.Preload
import Dodge.Data.Config
import Preload.Update
import Sound
{- |
Write the current world configuration to disk as a json file.
-}
-}
saveConfig :: Configuration -> (a -> IO a) -> a -> IO a
saveConfig cfig f x = do
putStrLn "Saving config to data/dodge.config.json"
BS.writeFile "data/dodge.config.json"
$ AEP.encodePretty' (AEP.Config (AEP.Spaces 2) compare AEP.Generic False) cfig
BS.writeFile "data/dodge.config.json" $
AEP.encodePretty' (AEP.Config (AEP.Spaces 2) compare AEP.Generic False) cfig
f x
{- |
Apply the volume settings from the world configuration to the running game.
-}
-}
setVol :: Configuration -> IO ()
setVol cfig = do
setSoundVolume ( _volume_master cfig * _volume_sound cfig)
setMusicVolume ( _volume_master cfig * _volume_music cfig)
setSoundVolume (_volume_master cfig * _volume_sound cfig)
setMusicVolume (_volume_master cfig * _volume_music cfig)
-- what?
setVolThen :: Configuration -> (a -> IO a) -> a -> IO a
setVolThen cfig f a = do
setVol cfig
setVol cfig
f a
{- |
Apply /all/ of the values in the world configuration to the running game.
-}
applyWorldConfig
:: Configuration
-> PreloadData
-> IO PreloadData
-}
applyWorldConfig ::
Configuration ->
PreloadData ->
IO PreloadData
applyWorldConfig cfig pdata = do
setVol cfig
setVol cfig
pdataResizeUpdate (x `div` divRes) (y `div` divRes) x y pdata
where
x = round $ _windowX cfig