module Dodge.Terminal.LeftButton ( doTerminalEffectLB, terminalReturnEffect, ) where import Control.Monad import Data.Maybe import Dodge.Data.World import Dodge.Terminal.ReturnEffect import LensHelp doTerminalEffectLB :: Terminal -> World -> World doTerminalEffectLB tm w = fromMaybe w $ do guard (_tmStatus tm == TerminalReady) s <- w ^? cWorld . lWorld . terminals . ix (_tmID tm) . tmInput . tiText if null (words s) && null (_tmPartialCommand tm) then Just $ defocusTerminalInput w else return $ terminalReturnEffect tm w 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