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