aboutsummaryrefslogtreecommitdiff
path: root/src/Game/Controller.hs
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-02-07 16:08:13 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-02-07 16:08:13 +0000
commit9534c490c5c318e6c29ebf881ac5350545f479e5 (patch)
treea1d3e04db1fbeae883502668e1444763c2a28a69 /src/Game/Controller.hs
parent54d3f5a32758eb92606338d28a13652bcf51375c (diff)
downloadspace-plat-hs-9534c490c5c318e6c29ebf881ac5350545f479e5.tar.gz
space-plat-hs-9534c490c5c318e6c29ebf881ac5350545f479e5.zip
Using OverloadedRecordDot
Diffstat (limited to 'src/Game/Controller.hs')
-rw-r--r--src/Game/Controller.hs46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/Game/Controller.hs b/src/Game/Controller.hs
index ec1cdf3..b5cd685 100644
--- a/src/Game/Controller.hs
+++ b/src/Game/Controller.hs
@@ -9,14 +9,14 @@ import qualified SDL.Raw
import Prelude hiding (init)
data Controls = Controls
- { cUp :: Bool,
- cDown :: Bool,
- cLeft :: Bool,
- cRight :: Bool,
- cA :: Bool,
- cB :: Bool,
- cMenu :: Bool,
- cJoy :: Maybe SDL.Raw.Joystick
+ { up :: Bool,
+ down :: Bool,
+ left :: Bool,
+ right :: Bool,
+ a :: Bool,
+ b :: Bool,
+ menu :: Bool,
+ joy :: Maybe SDL.Raw.Joystick
}
deriving (Show)
@@ -39,29 +39,29 @@ init = do
updateGamepad :: [SDL.EventPayload] -> Controls -> Controls
updateGamepad events controls
- | isNothing $ cJoy controls = controls
+ | isNothing $ controls.joy = controls
-- XXX: deal with disconnection/reconnection
| otherwise =
controls
- { cUp = fromMaybe (cUp controls) $ isPressedGamepad SDL.ControllerButtonDpadUp events,
- cDown = fromMaybe (cDown controls) $ isPressedGamepad SDL.ControllerButtonDpadDown events,
- cLeft = fromMaybe (cLeft controls) $ isPressedGamepad SDL.ControllerButtonDpadLeft events,
- cRight = fromMaybe (cRight controls) $ isPressedGamepad SDL.ControllerButtonDpadRight events,
- cA = fromMaybe (cA controls) $ isPressedGamepad SDL.ControllerButtonA events,
- cB = fromMaybe (cB controls) $ isPressedGamepad SDL.ControllerButtonB events,
- cMenu = fromMaybe (cMenu controls) $ isPressedGamepad SDL.ControllerButtonStart events
+ { up = fromMaybe controls.up $ isPressedGamepad SDL.ControllerButtonDpadUp events,
+ down = fromMaybe controls.down $ isPressedGamepad SDL.ControllerButtonDpadDown events,
+ left = fromMaybe controls.left $ isPressedGamepad SDL.ControllerButtonDpadLeft events,
+ right = fromMaybe controls.right $ isPressedGamepad SDL.ControllerButtonDpadRight events,
+ a = fromMaybe controls.a $ isPressedGamepad SDL.ControllerButtonA events,
+ b = fromMaybe controls.b $ isPressedGamepad SDL.ControllerButtonB events,
+ menu = fromMaybe controls.menu $ isPressedGamepad SDL.ControllerButtonStart events
}
updateKeyboard :: [SDL.EventPayload] -> Controls -> Controls
updateKeyboard events controls =
controls
- { cUp = fromMaybe (cUp controls) $ isPressed SDL.KeycodeUp events,
- cDown = fromMaybe (cDown controls) $ isPressed SDL.KeycodeDown events,
- cLeft = fromMaybe (cLeft controls) $ isPressed SDL.KeycodeLeft events,
- cRight = fromMaybe (cRight controls) $ isPressed SDL.KeycodeRight events,
- cA = fromMaybe (cA controls) $ isPressed SDL.KeycodeZ events,
- cB = fromMaybe (cB controls) $ isPressed SDL.KeycodeX events,
- cMenu = fromMaybe (cMenu controls) $ isPressed SDL.KeycodeReturn events
+ { up = fromMaybe controls.up $ isPressed SDL.KeycodeUp events,
+ down = fromMaybe controls.down $ isPressed SDL.KeycodeDown events,
+ left = fromMaybe controls.left $ isPressed SDL.KeycodeLeft events,
+ right = fromMaybe controls.right $ isPressed SDL.KeycodeRight events,
+ a = fromMaybe controls.a $ isPressed SDL.KeycodeZ events,
+ b = fromMaybe controls.b $ isPressed SDL.KeycodeX events,
+ menu = fromMaybe controls.menu $ isPressed SDL.KeycodeReturn events
}
update :: [SDL.EventPayload] -> Controls -> Controls