Cleanup warnings

This commit is contained in:
jgk
2021-05-17 22:39:18 +02:00
parent d7fcdbf550
commit 69f915a894
102 changed files with 1243 additions and 1185 deletions
+85 -82
View File
@@ -2,14 +2,13 @@
{-# LANGUAGE OverloadedStrings #-}
module Dodge.Config.KeyConfig
where
import Data.Aeson
import Foreign.C.Types
--import Data.Aeson
--import Foreign.C.Types
import GHC.Generics
import qualified GHC.Int
--import qualified GHC.Int
import qualified SDL
import qualified SDL.Internal.Numbered
import System.Directory
--import qualified SDL.Internal.Numbered
--import System.Directory
data KeyConfig = KeyConfig
{ moveUpBinding :: Int,
@@ -51,6 +50,7 @@ data KeyConfigSDL = KeyConfigSDL
}
deriving (Generic, Show)
defaultKeyConfigSDL :: KeyConfigSDL
defaultKeyConfigSDL =
KeyConfigSDL
{ moveUpKey = SDL.ScancodeW,
@@ -71,82 +71,85 @@ defaultKeyConfigSDL =
newKey = SDL.ScancodeN
}
instance ToJSON KeyConfig where
toEncoding = genericToEncoding defaultOptions
instance FromJSON KeyConfig where
parseJSON = withObject "KeyConfig" $ \o -> do
moveUpBinding <- o .:? "moveUp" .!= 119
moveDownBinding <- o .:? "moveDown" .!= 115
moveLeftBinding <- o .:? "moveLeft" .!= 97
moveRightBinding <- o .:? "moveRight" .!= 100
pauseBinding <- o .:? "pause" .!= 112
escapeBinding <- o .:? "escape" .!= 27
dropItemBinding <- o .:? "dropItem" .!= 102
toggleMapBinding <- o .:? "toggleMap" .!= 109
reloadBinding <- o .:? "reload" .!= 114
testEventBinding <- o .:? "testEvent" .!= 116
spaceActionBinding <- o .:? "spaceAction" .!= 32
rotateCameraPlusBinding <- o .:? "rotateCameraPlus" .!= 113
rotateCameraMinusBinding <- o .:? "rotateCameraMinus" .!= 101
zoomInBinding <- o .:? "zoomIn" .!= 106
zoomOutBinding <- o .:? "zoomOut" .!= 107
newBinding <- o .:? "new" .!= 110
return
KeyConfig
{ moveUpBinding = moveUpBinding,
moveDownBinding = moveDownBinding,
moveLeftBinding = moveLeftBinding,
moveRightBinding = moveRightBinding,
pauseBinding = pauseBinding,
escapeBinding = escapeBinding,
dropItemBinding = dropItemBinding,
toggleMapBinding = toggleMapBinding,
reloadBinding = reloadBinding,
testEventBinding = testEventBinding,
spaceActionBinding = spaceActionBinding,
rotateCameraPlusBinding = rotateCameraPlusBinding,
rotateCameraMinusBinding = rotateCameraMinusBinding,
zoomInBinding = zoomInBinding,
zoomOutBinding = zoomOutBinding,
newBinding = newBinding
}
--instance ToJSON KeyConfig where
-- toEncoding = genericToEncoding defaultOptions
--
--instance FromJSON KeyConfig where
-- parseJSON = withObject "KeyConfig" $ \o -> do
-- moveUpBinding <- o .:? "moveUp" .!= 119
-- moveDownBinding <- o .:? "moveDown" .!= 115
-- moveLeftBinding <- o .:? "moveLeft" .!= 97
-- moveRightBinding <- o .:? "moveRight" .!= 100
-- pauseBinding <- o .:? "pause" .!= 112
-- escapeBinding <- o .:? "escape" .!= 27
-- dropItemBinding <- o .:? "dropItem" .!= 102
-- toggleMapBinding <- o .:? "toggleMap" .!= 109
-- reloadBinding <- o .:? "reload" .!= 114
-- testEventBinding <- o .:? "testEvent" .!= 116
-- spaceActionBinding <- o .:? "spaceAction" .!= 32
-- rotateCameraPlusBinding <- o .:? "rotateCameraPlus" .!= 113
-- rotateCameraMinusBinding <- o .:? "rotateCameraMinus" .!= 101
-- zoomInBinding <- o .:? "zoomIn" .!= 106
-- zoomOutBinding <- o .:? "zoomOut" .!= 107
-- newBinding <- o .:? "new" .!= 110
-- return
-- KeyConfig
-- { moveUpBinding = moveUpBinding,
-- moveDownBinding = moveDownBinding,
-- moveLeftBinding = moveLeftBinding,
-- moveRightBinding = moveRightBinding,
-- pauseBinding = pauseBinding,
-- escapeBinding = escapeBinding,
-- dropItemBinding = dropItemBinding,
-- toggleMapBinding = toggleMapBinding,
-- reloadBinding = reloadBinding,
-- testEventBinding = testEventBinding,
-- spaceActionBinding = spaceActionBinding,
-- rotateCameraPlusBinding = rotateCameraPlusBinding,
-- rotateCameraMinusBinding = rotateCameraMinusBinding,
-- zoomInBinding = zoomInBinding,
-- zoomOutBinding = zoomOutBinding,
-- newBinding = newBinding
-- }
loadKeyConfig :: IO KeyConfigSDL
loadKeyConfig = do
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 do
putStrLn "No keys.json found, loading default config"
return defaultKeyConfigSDL
loadKeyConfig = return defaultKeyConfigSDL
getSdlScancode :: Int -> SDL.Scancode
getSdlScancode x = SDL.Internal.Numbered.fromNumber (fromIntegral x) :: SDL.Scancode
--loadKeyConfig' :: IO KeyConfigSDL
--loadKeyConfig' = do
-- 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 do
-- putStrLn "No keys.json found, loading default config"
-- return defaultKeyConfigSDL
--
--getSdlScancode :: Int -> SDL.Scancode
--getSdlScancode x = SDL.Internal.Numbered.fromNumber (fromIntegral x) :: SDL.Scancode