Add modules for config file
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
module LoadConfig
|
||||
where
|
||||
import Data.Aeson
|
||||
import GHC.Generics
|
||||
import Foreign.C.Types
|
||||
|
||||
data Configuration = Configuration
|
||||
{ windowxsize :: Int
|
||||
, windowysize :: Int
|
||||
} deriving (Generic, Show)
|
||||
|
||||
instance ToJSON Configuration where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Configuration
|
||||
|
||||
loadConfig :: IO (Int,Int)
|
||||
loadConfig = do
|
||||
mayConfig <- decodeFileStrict "config.json"
|
||||
case mayConfig of
|
||||
Just config -> return (windowxsize config,windowysize config)
|
||||
Nothing -> do
|
||||
putStrLn "invalid config.json, loading default config"
|
||||
return (800,600)
|
||||
Reference in New Issue
Block a user