Allow terminals to block input
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
module Dodge.Event.Keyboard
|
||||
( handleKeyboardEvent
|
||||
, handleTextInput
|
||||
, guardDisconnectedID
|
||||
) where
|
||||
import Dodge.Terminal
|
||||
import Dodge.InputFocus
|
||||
@@ -30,20 +31,26 @@ import qualified Data.Text as T
|
||||
-- dealt with using key presses (handlePressedKey)
|
||||
-- also, note that this currently "doubles" the inputs to both terminals if both
|
||||
-- are open
|
||||
handleTextInput :: T.Text -> Universe -> IO (Maybe Universe)
|
||||
handleTextInput text u = return . Just $ u
|
||||
handleTextInput :: T.Text -> Universe -> Universe
|
||||
handleTextInput text u = u
|
||||
& menuLayers . ix 0 . scInput %~ updateText
|
||||
& updateTerminalText
|
||||
where
|
||||
updateTerminalText = case u ^? uvWorld . hud . hudElement . subInventory of
|
||||
Just (DisplayTerminal tmid) | hasfocus tmid
|
||||
-> uvWorld . terminals . ix tmid . tmInput . tiText %~ updateText
|
||||
-> uvWorld %~ \w -> guardDisconnectedID tmid w (w & terminals . ix tmid . tmInput . tiText %~ updateText)
|
||||
_ -> id
|
||||
hasfocus tmid = fromMaybe False $ u ^? uvWorld . terminals . ix tmid . tmInput . tiFocus
|
||||
updateText s = case T.unpack text of
|
||||
";" -> s
|
||||
_ -> s `T.append` T.toUpper text
|
||||
|
||||
guardDisconnectedID :: Int -> World -> World -> World
|
||||
guardDisconnectedID tmid w w' = case w ^? terminals . ix tmid . tmStatus of
|
||||
Just TerminalReady -> w'
|
||||
_ -> w
|
||||
|
||||
|
||||
{- | Handles keyboard press and release.
|
||||
On release, remove scancode from the 'Set' of pressed keys.
|
||||
On press, adds the scancode, and perhaps applies a direct effect:
|
||||
|
||||
Reference in New Issue
Block a user