From 677f9396a30754c4030707a8d88009516a20758f Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 4 Mar 2023 18:48:26 +0000 Subject: Fix: controller device added uses joystick index While the other events rely on joystick's instance ID. --- src/Game/Controller.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Game/Controller.hs') 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 -- cgit v1.2.3