module Dodge.InputFocus (inTextInputFocus) where import Dodge.Data.Terminal.Status import Data.Maybe import Dodge.Data.World import LensHelp inTextInputFocus :: World -> Bool inTextInputFocus = isJust . inputFocusI inputFocusI :: World -> Maybe ((String -> Identity String) -> World -> Identity World) inputFocusI = textInputFocus textInputFocus :: Applicative f => World -> Maybe ((String -> f String) -> World -> f World) textInputFocus w = case w ^? hud . subInventory of Just NoSubInventory{} -> case he ^? diSelection . _Just . _1 of Just (-1) -> Just $ hud . diInvFilter . _Just Just 2 -> Just $ hud . diCloseFilter . _Just _ -> Nothing Just CombineInventory{} -> case he ^? subInventory . ciSelection . _Just . _1 of Just (-1) -> Just $ hud . subInventory . ciFilter . _Just _ -> Nothing Just DisplayTerminal{_termID = tmid} -> do -- connectionstatus <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus -- guard $ connectionstatus == TerminalTextInput return $ cWorld . lWorld . terminals . ix tmid . tmStatus . tiText _ -> Nothing where he = w ^. hud