fix error in movement caused by numlock modifier

movable_objects2
nek0 1 year ago
parent efb5046ec7
commit 927d7af132
  1. 5
      src/Main.hs
  2. 65
      src/Types/Util.hs

@ -66,7 +66,10 @@ preLoad gd = do
(MsgKeyboardEvent time win motion False keysym) -> do
translator <- liftIO $ atomically $ readTVar (gameActionTranslation gd)
case
((SDL.keysymScancode keysym, SDL.keysymModifier keysym) `M.lookup`
(
( SDL.keysymScancode keysym
, translateSDLModifiers (SDL.keysymModifier keysym)
) `M.lookup`
translator)
of
Just action ->

@ -14,20 +14,59 @@ import Types.Subsystems
type Progress = (Float, T.Text)
type ActionTranslation = M.Map (SDL.Scancode, SDL.KeyModifier) Action
type ActionTranslation = M.Map (SDL.Scancode, ActionModifiers) Action
data ActionModifiers = ActionModifiers
{ modLeftShift :: Bool
, modRightShift :: Bool
, modLeftCtrl :: Bool
, modRightCtrl :: Bool
, modLeftAlt :: Bool
, modAltGr :: Bool
, modCapsLock :: Bool
}
deriving (Show, Eq, Ord)
compareSDLModifiers
:: ActionModifiers
-> SDL.KeyModifier
-> Bool
compareSDLModifiers mod sdlmod =
modLeftShift mod == SDL.keyModifierLeftShift sdlmod &&
modRightShift mod == SDL.keyModifierRightShift sdlmod &&
modLeftCtrl mod == SDL.keyModifierLeftCtrl sdlmod &&
modRightCtrl mod == SDL.keyModifierRightCtrl sdlmod &&
modLeftAlt mod == SDL.keyModifierLeftAlt sdlmod &&
modAltGr mod == SDL.keyModifierAltGr sdlmod &&
modCapsLock mod == SDL.keyModifierCapsLock sdlmod
translateSDLModifiers
:: SDL.KeyModifier
-> ActionModifiers
translateSDLModifiers sdlmod = ActionModifiers
{ modLeftShift = SDL.keyModifierLeftShift sdlmod
, modRightShift = SDL.keyModifierRightShift sdlmod
, modLeftCtrl = SDL.keyModifierLeftCtrl sdlmod
, modRightCtrl = SDL.keyModifierRightCtrl sdlmod
, modLeftAlt = SDL.keyModifierLeftAlt sdlmod
, modAltGr = SDL.keyModifierAltGr sdlmod
, modCapsLock = SDL.keyModifierCapsLock sdlmod
}
nonmod = ActionModifiers False False False False False False False
defaultTranslation :: ActionTranslation
defaultTranslation = M.fromList
[ ((SDL.ScancodeW, SDL.fromNumber SDLRaw.KMOD_NONE), MoveUp)
, ((SDL.ScancodeS, SDL.fromNumber SDLRaw.KMOD_NONE), MoveDown)
, ((SDL.ScancodeA, SDL.fromNumber SDLRaw.KMOD_NONE), MoveLeft)
, ((SDL.ScancodeD, SDL.fromNumber SDLRaw.KMOD_NONE), MoveRight)
, ((SDL.ScancodeSpace, SDL.fromNumber SDLRaw.KMOD_NONE), Jump)
, ((SDL.ScancodeSpace, SDL.fromNumber SDLRaw.KMOD_LSHIFT), JumpDown)
, ((SDL.ScancodeF, SDL.fromNumber SDLRaw.KMOD_NONE), Activate)
, ((SDL.Scancode1, SDL.fromNumber SDLRaw.KMOD_NONE), ReleasePowerup1)
, ((SDL.Scancode2, SDL.fromNumber SDLRaw.KMOD_NONE), ReleasePowerup2)
, ((SDL.Scancode3, SDL.fromNumber SDLRaw.KMOD_NONE), ReleasePowerup3)
, ((SDL.ScancodeLCtrl, SDL.fromNumber SDLRaw.KMOD_NONE), Spit)
, ((SDL.ScancodePause, SDL.fromNumber SDLRaw.KMOD_NONE), Pause)
[ ((SDL.ScancodeW, nonmod), MoveUp)
, ((SDL.ScancodeS, nonmod), MoveDown)
, ((SDL.ScancodeA, nonmod), MoveLeft)
, ((SDL.ScancodeD, nonmod), MoveRight)
, ((SDL.ScancodeSpace, nonmod), Jump)
, ((SDL.ScancodeSpace, nonmod {modLeftShift = True}), JumpDown)
, ((SDL.ScancodeF, nonmod), Activate)
, ((SDL.Scancode1, nonmod), ReleasePowerup1)
, ((SDL.Scancode2, nonmod), ReleasePowerup2)
, ((SDL.Scancode3, nonmod), ReleasePowerup3)
, ((SDL.ScancodeLCtrl, nonmod), Spit)
, ((SDL.ScancodePause, nonmod), Pause)
]

Loading…
Cancel
Save