{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module LoadConfig where
import Data.Aeson
--import Foreign.C.Types
import GHC.Generics
--import qualified GHC.Int
--import qualified SDL
--import System.Directory

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)
