diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-03-03 21:57:13 +0000 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-03-03 21:57:13 +0000 |
commit | b9353d40500dc27812a435d115fe9eaaed8a7cdc (patch) | |
tree | 5636739d530b6aba8c760cd2a84595b2af6dc6d8 /src/Game/Utils.hs | |
parent | ef0a75834870eced4371edd6d50916d4e1bd432f (diff) | |
download | space-plat-hs-b9353d40500dc27812a435d115fe9eaaed8a7cdc.tar.gz space-plat-hs-b9353d40500dc27812a435d115fe9eaaed8a7cdc.zip |
Better Gamepad support handling connection/disconnection
Diffstat (limited to 'src/Game/Utils.hs')
-rw-r--r-- | src/Game/Utils.hs | 24 |
1 files changed, 1 insertions, 23 deletions
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 |