Allow for events to do io
This commit is contained in:
@@ -22,21 +22,21 @@ On release, remove scancode from the 'Set' of pressed keys.
|
||||
On press, adds the scancode, and perhaps applies a direct effect:
|
||||
see 'handlePressedKeyInGame'.
|
||||
-}
|
||||
handleKeyboardEvent :: KeyboardEventData -> Universe -> Maybe Universe
|
||||
handleKeyboardEvent :: KeyboardEventData -> Universe -> IO (Maybe Universe)
|
||||
handleKeyboardEvent kev u = case keyboardEventKeyMotion kev of
|
||||
Released -> Just $ u & uvWorld . keys %~ S.delete kcode
|
||||
Released -> return . Just $ u & uvWorld . keys %~ S.delete kcode
|
||||
Pressed -> handlePressedKey (keyboardEventRepeat kev) kcode
|
||||
(u & uvWorld . keys %~ S.insert kcode)
|
||||
where
|
||||
kcode = (keysymScancode . keyboardEventKeysym) kev
|
||||
|
||||
handlePressedKey :: Bool -> Scancode -> Universe -> Maybe Universe
|
||||
handlePressedKey True _ w = Just w
|
||||
handlePressedKey _ ScancodeF5 w = Just $ doQuicksave w
|
||||
handlePressedKey _ ScancodeF9 w = Just $ loadSaveSlot QuicksaveSlot w
|
||||
handlePressedKey _ ScancodeSemicolon w = Just $ gotoTerminal w
|
||||
handlePressedKey :: Bool -> Scancode -> Universe -> IO (Maybe Universe)
|
||||
handlePressedKey True _ w = return $ Just w
|
||||
handlePressedKey _ ScancodeF5 w = return . Just $ doQuicksave w
|
||||
handlePressedKey _ ScancodeF9 w = return . Just $ loadSaveSlot QuicksaveSlot w
|
||||
handlePressedKey _ ScancodeSemicolon w = return . Just $ gotoTerminal w
|
||||
handlePressedKey _ scode w
|
||||
| null (_menuLayers w) = uvWorld (handlePressedKeyInGame scode) w
|
||||
| null (_menuLayers w) = return $ uvWorld (handlePressedKeyInGame scode) w
|
||||
| otherwise = handlePressedKeyInMenu (head $ _menuLayers w) scode w
|
||||
|
||||
handlePressedKeyInGame :: Scancode -> World -> Maybe World
|
||||
|
||||
Reference in New Issue
Block a user