Broken commit (removed loadKeyConfig)

This commit is contained in:
2021-08-27 11:58:11 +01:00
parent c4df048d31
commit 3ff04576ab
25 changed files with 122 additions and 200 deletions
+3 -103
View File
@@ -1,6 +1,9 @@
{-# LANGUAGE DeriveGeneric #-}
--{-# LANGUAGE OverloadedStrings #-}
module Dodge.Config.KeyConfig
( KeyConfigSDL (..)
, defaultKeyConfigSDL
)
where
--import Data.Aeson
--import Foreign.C.Types
@@ -10,26 +13,6 @@ import qualified SDL
--import qualified SDL.Internal.Numbered
--import System.Directory
data KeyConfig = KeyConfig
{ moveUpBinding :: Int,
moveDownBinding :: Int,
moveLeftBinding :: Int,
moveRightBinding :: Int,
pauseBinding :: Int,
escapeBinding :: Int,
dropItemBinding :: Int,
toggleMapBinding :: Int,
reloadBinding :: Int,
testEventBinding :: Int,
spaceActionBinding :: Int,
rotateCameraPlusBinding :: Int,
rotateCameraMinusBinding :: Int,
zoomInBinding :: Int,
zoomOutBinding :: Int,
newBinding :: Int
}
deriving (Generic, Show)
data KeyConfigSDL = KeyConfigSDL
{ moveUpKey :: SDL.Scancode
, moveDownKey :: SDL.Scancode
@@ -72,86 +55,3 @@ defaultKeyConfigSDL =
, newMapKey = SDL.ScancodeN
, modifierKey = SDL.ScancodeCapsLock
}
--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 = return defaultKeyConfigSDL
--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