From b9353d40500dc27812a435d115fe9eaaed8a7cdc Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Fri, 3 Mar 2023 21:57:13 +0000 Subject: Better Gamepad support handling connection/disconnection --- src/Game/Utils.hs | 24 +----------------------- 1 file changed, 1 insertion(+), 23 deletions(-) (limited to 'src/Game/Utils.hs') diff --git a/src/Game/Utils.hs b/src/Game/Utils.hs index e2b320a..d4dae94 100644 --- a/src/Game/Utils.hs +++ b/src/Game/Utils.hs @@ -1,30 +1,8 @@ -module Game.Utils (rect, isPressed, isPressedGamepad) where +module Game.Utils (rect) where import Foreign.C.Types (CInt) import qualified SDL -import qualified SDL.Input.GameController as SDL import SDL.Vect (V2 (..)) rect :: Int -> Int -> Int -> Int -> SDL.Rectangle CInt rect x y w h = SDL.Rectangle (SDL.P $ V2 (fromIntegral x) (fromIntegral y)) (V2 (fromIntegral w) (fromIntegral h)) - -isPressed :: SDL.Keycode -> [SDL.EventPayload] -> Maybe Bool -isPressed code events - | any (isEventKey SDL.Pressed code) events = Just True - | any (isEventKey SDL.Released code) events = Just False - | otherwise = Nothing - where - isEventKey :: SDL.InputMotion -> SDL.Keycode -> SDL.EventPayload -> Bool - isEventKey expected keycode (SDL.KeyboardEvent (SDL.KeyboardEventData _ motion False ksym)) = expected == motion && SDL.keysymKeycode ksym == keycode - isEventKey _ _ _ = False - -isPressedGamepad :: SDL.ControllerButton -> [SDL.EventPayload] -> Maybe Bool -isPressedGamepad button events - | any (isEventButton SDL.ControllerButtonPressed button) events = Just True - | any (isEventButton SDL.ControllerButtonReleased button) events = Just False - | otherwise = Nothing - where - isEventButton :: SDL.ControllerButtonState -> SDL.ControllerButton -> SDL.EventPayload -> Bool - -- FIXME: may be don't hardcode it to joystick 0 - isEventButton expected bu (SDL.ControllerButtonEvent (SDL.ControllerButtonEventData 0 b state)) = expected == state && bu == b - isEventButton _ _ _ = False -- cgit v1.2.3