Work on terminals

This commit is contained in:
2023-05-03 11:19:47 +01:00
parent 61f88aeb4a
commit ed8d8f0e93
8 changed files with 79 additions and 107 deletions
+12 -25
View File
@@ -1,36 +1,23 @@
module Dodge.Terminal.LeftButton where
module Dodge.Terminal.LeftButton (
doTerminalEffectLB,
terminalReturnEffect,
) where
import Control.Monad
import Data.Maybe
import Dodge.Data.World
import Dodge.Terminal--oops
import Dodge.Terminal.ReturnEffect
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)]
doTerminalEffectLB tm w = fromMaybe w $ do
guard (_tmStatus tm == TerminalReady)
s <- w ^? cWorld . lWorld . terminals . ix (_tmID tm) . tmInput . tiText
if null (words s)
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
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 :))
)