fix error in movement caused by numlock modifier
This commit is contained in:
parent
efb5046ec7
commit
927d7af132
2 changed files with 56 additions and 14 deletions
|
@ -66,7 +66,10 @@ preLoad gd = do
|
||||||
(MsgKeyboardEvent time win motion False keysym) -> do
|
(MsgKeyboardEvent time win motion False keysym) -> do
|
||||||
translator <- liftIO $ atomically $ readTVar (gameActionTranslation gd)
|
translator <- liftIO $ atomically $ readTVar (gameActionTranslation gd)
|
||||||
case
|
case
|
||||||
((SDL.keysymScancode keysym, SDL.keysymModifier keysym) `M.lookup`
|
(
|
||||||
|
( SDL.keysymScancode keysym
|
||||||
|
, translateSDLModifiers (SDL.keysymModifier keysym)
|
||||||
|
) `M.lookup`
|
||||||
translator)
|
translator)
|
||||||
of
|
of
|
||||||
Just action ->
|
Just action ->
|
||||||
|
|
|
@ -14,20 +14,59 @@ import Types.Subsystems
|
||||||
|
|
||||||
type Progress = (Float, T.Text)
|
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 :: ActionTranslation
|
||||||
defaultTranslation = M.fromList
|
defaultTranslation = M.fromList
|
||||||
[ ((SDL.ScancodeW, SDL.fromNumber SDLRaw.KMOD_NONE), MoveUp)
|
[ ((SDL.ScancodeW, nonmod), MoveUp)
|
||||||
, ((SDL.ScancodeS, SDL.fromNumber SDLRaw.KMOD_NONE), MoveDown)
|
, ((SDL.ScancodeS, nonmod), MoveDown)
|
||||||
, ((SDL.ScancodeA, SDL.fromNumber SDLRaw.KMOD_NONE), MoveLeft)
|
, ((SDL.ScancodeA, nonmod), MoveLeft)
|
||||||
, ((SDL.ScancodeD, SDL.fromNumber SDLRaw.KMOD_NONE), MoveRight)
|
, ((SDL.ScancodeD, nonmod), MoveRight)
|
||||||
, ((SDL.ScancodeSpace, SDL.fromNumber SDLRaw.KMOD_NONE), Jump)
|
, ((SDL.ScancodeSpace, nonmod), Jump)
|
||||||
, ((SDL.ScancodeSpace, SDL.fromNumber SDLRaw.KMOD_LSHIFT), JumpDown)
|
, ((SDL.ScancodeSpace, nonmod {modLeftShift = True}), JumpDown)
|
||||||
, ((SDL.ScancodeF, SDL.fromNumber SDLRaw.KMOD_NONE), Activate)
|
, ((SDL.ScancodeF, nonmod), Activate)
|
||||||
, ((SDL.Scancode1, SDL.fromNumber SDLRaw.KMOD_NONE), ReleasePowerup1)
|
, ((SDL.Scancode1, nonmod), ReleasePowerup1)
|
||||||
, ((SDL.Scancode2, SDL.fromNumber SDLRaw.KMOD_NONE), ReleasePowerup2)
|
, ((SDL.Scancode2, nonmod), ReleasePowerup2)
|
||||||
, ((SDL.Scancode3, SDL.fromNumber SDLRaw.KMOD_NONE), ReleasePowerup3)
|
, ((SDL.Scancode3, nonmod), ReleasePowerup3)
|
||||||
, ((SDL.ScancodeLCtrl, SDL.fromNumber SDLRaw.KMOD_NONE), Spit)
|
, ((SDL.ScancodeLCtrl, nonmod), Spit)
|
||||||
, ((SDL.ScancodePause, SDL.fromNumber SDLRaw.KMOD_NONE), Pause)
|
, ((SDL.ScancodePause, nonmod), Pause)
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue