Add System.Directory library, allow for testing file existence

This commit is contained in:
2021-03-26 20:02:27 +01:00
parent 5620e45e0a
commit 485952fe53
2 changed files with 35 additions and 28 deletions
+1
View File
@@ -45,6 +45,7 @@ dependencies:
- foldl
- linear
- aeson
- directory
library:
source-dirs: src
+6
View File
@@ -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