aboutsummaryrefslogtreecommitdiff
path: root/src/Game
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-03-04 18:48:26 +0000
committerJuan J. Martinez <jjm@usebox.net>2023-03-04 20:21:38 +0000
commit677f9396a30754c4030707a8d88009516a20758f (patch)
treef98ba69443a7e7a10d887bc95cb56e00376df0e1 /src/Game
parent08b8750ce53d9c6800a09026912eb261de3a36e5 (diff)
downloadspace-plat-hs-677f9396a30754c4030707a8d88009516a20758f.tar.gz
space-plat-hs-677f9396a30754c4030707a8d88009516a20758f.zip
Fix: controller device added uses joystick index
While the other events rely on joystick's instance ID.
Diffstat (limited to 'src/Game')
-rw-r--r--src/Game/Controller.hs8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/Game/Controller.hs b/src/Game/Controller.hs
index 47698f9..01dfd1b 100644
--- a/src/Game/Controller.hs
+++ b/src/Game/Controller.hs
@@ -23,12 +23,14 @@ data Controls = Controls
deriving (Show)
processControllerEvents :: Controls -> [SDL.EventPayload] -> IO Controls
-processControllerEvents controls (SDL.ControllerDeviceEvent (SDL.ControllerDeviceEventData SDL.ControllerDeviceAdded joyId) : t) = do
+processControllerEvents controls (SDL.ControllerDeviceEvent (SDL.ControllerDeviceEventData SDL.ControllerDeviceAdded joyIndex) : t) = do
if isNothing controls.joyId
then do
- joyName <- peekCAString =<< SDL.Raw.gameControllerNameForIndex (fromIntegral joyId)
+ joyName <- peekCAString =<< SDL.Raw.gameControllerNameForIndex (fromIntegral joyIndex)
putStrLn $ "Connected gamepad: " ++ show joyName
- gc <- SDL.Raw.gameControllerOpen (fromIntegral joyId)
+ gc <- SDL.Raw.gameControllerOpen (fromIntegral joyIndex)
+ joy <- SDL.Raw.gameControllerGetJoystick gc
+ joyId <- SDL.Raw.joystickInstanceID joy
processControllerEvents controls {joyId = Just joyId, gc = Just gc} t
else processControllerEvents controls t
processControllerEvents controls (SDL.ControllerDeviceEvent (SDL.ControllerDeviceEventData SDL.ControllerDeviceRemoved joyId) : t) = do