Partially successful change of terminals to external entities

This commit is contained in:
2022-06-06 12:49:14 +01:00
parent 597336499c
commit eb38874102
12 changed files with 141 additions and 167 deletions
+13 -9
View File
@@ -30,9 +30,13 @@ import qualified Data.Text as T
-- also, note that this currently "doubles" the inputs to both terminals if both
-- are open
handleTextInput :: T.Text -> Universe -> IO (Maybe Universe)
handleTextInput text = return . Just . (menuLayers . ix 0 . scInput %~ updateText)
. (uvWorld . hud . hudElement . subInventory . termParams . termInput . _Just %~ updateText)
handleTextInput text u = return . Just $ u
& menuLayers . ix 0 . scInput %~ updateText
& updateTerminalText
where
updateTerminalText = case u ^? uvWorld . hud . hudElement . subInventory of
Just (DisplayTerminal tmid True) -> uvWorld . terminals . ix tmid . tmInput . _Just %~ updateText
_ -> id
updateText s = case T.unpack text of
";" -> s
_ -> s `T.append` T.toUpper text
@@ -60,8 +64,8 @@ handlePressedKey _ scode u = case scode of
ScancodeF5 -> return . Just $ doQuicksave u
ScancodeF9 -> return . Just $ loadSaveSlot QuicksaveSlot u
ScancodeSemicolon -> return . Just $ gotoTerminal u
_ | null (_menuLayers u) -> case u ^? uvWorld . hud . hudElement . subInventory . termParams . termInput . _Just of
Just {} -> return $ uvWorld (handlePressedKeyTerminal scode) u
_ | null (_menuLayers u) -> case u ^? uvWorld . hud . hudElement . subInventory of
Just (DisplayTerminal tmid True) -> return $ uvWorld (handlePressedKeyTerminal tmid scode) u
_ -> return $ uvWorld (Just . handlePressedKeyInGame scode) u
_ -> handlePressedKeyInMenu (head $ _menuLayers u) scode u
@@ -80,12 +84,12 @@ handlePressedKeyInGame scode w = case scode of
_ -> w
handlePressedKeyTerminal :: Scancode -> World -> Maybe World
handlePressedKeyTerminal scode w = case scode of
ScancodeEscape -> Just $ w & hud . hudElement . subInventory .~ NoSubInventory
ScancodeReturn -> Just $ w & doTerminalEffect
handlePressedKeyTerminal :: Int -> Scancode -> World -> Maybe World
handlePressedKeyTerminal tmid scode w = case scode of
ScancodeEscape -> Just $ w & hud . hudElement . subInventory . onInputLine .~ False
ScancodeReturn -> Just $ w & doTerminalEffect (w ^?! terminals . ix tmid)
ScancodeBackspace -> Just $ w
& hud . hudElement . subInventory . termParams . termInput . _Just %~ doBackspace
& terminals . ix tmid . tmInput . _Just %~ doBackspace
& backspaceTimer .~ 5
_ -> Just w
where