diff --git a/src/Dodge/Terminal/LeftButton.hs b/src/Dodge/Terminal/LeftButton.hs new file mode 100644 index 000000000..cf83a6d29 --- /dev/null +++ b/src/Dodge/Terminal/LeftButton.hs @@ -0,0 +1,33 @@ +module Dodge.Terminal.LeftButton + where +import Dodge.Data +import Dodge.Terminal -- this goes the wrong way! +import LensHelp + +import qualified Data.Text as T +import Data.Maybe + +doTerminalEffectLB :: Terminal -> World -> World +doTerminalEffectLB tm w = guardDisconnected tm w $ fromMaybe w $ do + s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . tiText + if null (words s) + then Just $ defocusTerminalInput w + else return $ terminalReturnEffect tm w + +terminalReturnEffect :: Terminal -> World -> World +terminalReturnEffect tm w = guardDisconnected tm w $ fromMaybe w $ do + s <- fmap T.unpack $ w ^? terminals . ix (_tmID tm) . tmInput . tiText + return $ runTerminalString s tm $ w + & terminals . ix (_tmID tm) . tmFutureLines .~ [makeTermLine ('>':s)] + +defocusTerminalInput :: World -> World +defocusTerminalInput w = fromMaybe w $ do + tmid <- w ^? hud . hudElement . subInventory . termID + return $ w & terminals . ix tmid . tmInput . tiFocus %~ const False + +runTerminalString :: String -> Terminal -> World -> World +runTerminalString s tm w = w & terminals . ix (_tmID tm) %~ + ( (tmInput .~ TerminalInput T.empty True (0,0)) + . (tmFutureLines ++.~ commandFutureLines s tm w) + . (tmCommandHistory %~ take 10 . (s:)) + )