Add System.Directory library, allow for testing file existence
This commit is contained in:
@@ -45,6 +45,7 @@ dependencies:
|
||||
- foldl
|
||||
- linear
|
||||
- aeson
|
||||
- directory
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
|
||||
@@ -10,6 +10,8 @@ import qualified GHC.Int
|
||||
import qualified SDL
|
||||
import SDL.Internal.Numbered as SDL.Internal.Numbered
|
||||
|
||||
import System.Directory
|
||||
|
||||
data Configuration = Configuration
|
||||
{ windowxsize :: Int,
|
||||
windowysize :: Int
|
||||
@@ -133,6 +135,9 @@ instance FromJSON KeyConfig where
|
||||
|
||||
loadKeyConfig :: IO KeyConfigSDL
|
||||
loadKeyConfig = do
|
||||
fExists <- doesFileExist "keys.json"
|
||||
if fExists
|
||||
then do
|
||||
mayConfig <- decodeFileStrict "keys.json"
|
||||
print mayConfig
|
||||
case mayConfig of
|
||||
@@ -160,6 +165,7 @@ loadKeyConfig = do
|
||||
putStrLn "invalid keys.json, loading default config"
|
||||
-- This is duplicated but not sure how to reduce
|
||||
return defaultKeyConfigSDL
|
||||
else return defaultKeyConfigSDL
|
||||
|
||||
getSdlScancode :: Int -> SDL.Scancode
|
||||
getSdlScancode x = SDL.Internal.Numbered.fromNumber (fromIntegral x) :: SDL.Scancode
|
||||
Reference in New Issue
Block a user