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
|
||||
|
||||
+34
-28
@@ -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,33 +135,37 @@ instance FromJSON KeyConfig where
|
||||
|
||||
loadKeyConfig :: IO KeyConfigSDL
|
||||
loadKeyConfig = do
|
||||
mayConfig <- decodeFileStrict "keys.json"
|
||||
print mayConfig
|
||||
case mayConfig of
|
||||
Just config ->
|
||||
return
|
||||
KeyConfigSDL
|
||||
{ moveUpKey = getSdlScancode $ moveUpBinding config,
|
||||
moveDownKey = getSdlScancode $ moveDownBinding config,
|
||||
moveLeftKey = getSdlScancode $ moveLeftBinding config,
|
||||
moveRightKey = getSdlScancode $ moveRightBinding config,
|
||||
pauseKey = getSdlScancode $ pauseBinding config,
|
||||
escapeKey = getSdlScancode $ escapeBinding config,
|
||||
dropItemKey = getSdlScancode $ dropItemBinding config,
|
||||
toggleMapKey = getSdlScancode $ toggleMapBinding config,
|
||||
reloadKey = getSdlScancode $ reloadBinding config,
|
||||
testEventKey = getSdlScancode $ testEventBinding config,
|
||||
spaceActionKey = getSdlScancode $ spaceActionBinding config,
|
||||
rotateCameraPlusKey = getSdlScancode $ rotateCameraPlusBinding config,
|
||||
rotateCameraMinusKey = getSdlScancode $ rotateCameraMinusBinding config,
|
||||
zoomInKey = getSdlScancode $ zoomInBinding config,
|
||||
zoomOutKey = getSdlScancode $ zoomOutBinding config,
|
||||
newKey = getSdlScancode $ newBinding config
|
||||
}
|
||||
Nothing -> do
|
||||
putStrLn "invalid keys.json, loading default config"
|
||||
-- This is duplicated but not sure how to reduce
|
||||
return defaultKeyConfigSDL
|
||||
fExists <- doesFileExist "keys.json"
|
||||
if fExists
|
||||
then do
|
||||
mayConfig <- decodeFileStrict "keys.json"
|
||||
print mayConfig
|
||||
case mayConfig of
|
||||
Just config ->
|
||||
return
|
||||
KeyConfigSDL
|
||||
{ moveUpKey = getSdlScancode $ moveUpBinding config,
|
||||
moveDownKey = getSdlScancode $ moveDownBinding config,
|
||||
moveLeftKey = getSdlScancode $ moveLeftBinding config,
|
||||
moveRightKey = getSdlScancode $ moveRightBinding config,
|
||||
pauseKey = getSdlScancode $ pauseBinding config,
|
||||
escapeKey = getSdlScancode $ escapeBinding config,
|
||||
dropItemKey = getSdlScancode $ dropItemBinding config,
|
||||
toggleMapKey = getSdlScancode $ toggleMapBinding config,
|
||||
reloadKey = getSdlScancode $ reloadBinding config,
|
||||
testEventKey = getSdlScancode $ testEventBinding config,
|
||||
spaceActionKey = getSdlScancode $ spaceActionBinding config,
|
||||
rotateCameraPlusKey = getSdlScancode $ rotateCameraPlusBinding config,
|
||||
rotateCameraMinusKey = getSdlScancode $ rotateCameraMinusBinding config,
|
||||
zoomInKey = getSdlScancode $ zoomInBinding config,
|
||||
zoomOutKey = getSdlScancode $ zoomOutBinding config,
|
||||
newKey = getSdlScancode $ newBinding config
|
||||
}
|
||||
Nothing -> 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
|
||||
getSdlScancode x = SDL.Internal.Numbered.fromNumber (fromIntegral x) :: SDL.Scancode
|
||||
|
||||
Reference in New Issue
Block a user