module Dodge.Terminal.LeftButton where import Data.Maybe import Dodge.Data.World import Dodge.Terminal--oops import LensHelp doTerminalEffectLB :: Terminal -> World -> World doTerminalEffectLB tm w = guardDisconnected tm w $ fromMaybe w $ do s <- w ^? cWorld . lWorld . 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 <- w ^? cWorld . lWorld . terminals . ix (_tmID tm) . tmInput . tiText return $ runTerminalString s tm $ w & cWorld . lWorld . terminals . ix (_tmID tm) . tmFutureLines .~ [makeTermLine ('>' : s)] defocusTerminalInput :: World -> World defocusTerminalInput w = fromMaybe w $ do tmid <- w ^? hud . hudElement . subInventory . termID return $ w & cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const False runTerminalString :: String -> Terminal -> World -> World runTerminalString s tm w = w & cWorld . lWorld . terminals . ix (_tmID tm) %~ ( (tmInput .~ TerminalInput mempty True (0, 0)) . (tmFutureLines ++.~ commandFutureLines s tm w) . (tmCommandHistory %~ take 10 . (s :)) )