Start to refactor terminals

This commit is contained in:
2024-11-05 21:14:53 +00:00
parent 79b03ef6ec
commit 7e1b5f0921
12 changed files with 335 additions and 341 deletions
-23
View File
@@ -1,23 +0,0 @@
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
-28
View File
@@ -1,28 +0,0 @@
module Dodge.Terminal.ReturnEffect
where
import Control.Monad
import Data.Maybe
import Dodge.Data.World
import LensHelp
import Dodge.Terminal -- this should be rethought
terminalReturnEffect :: Terminal -> World -> World
terminalReturnEffect tm w = fromMaybe w $ do
guard $ _tmStatus tm == TerminalReady
s <- w ^? cWorld . lWorld . terminals . ix (_tmID tm) . tmInput . tiText
let pc = maybe "" (++ " ") $ tm ^? tmPartialCommand . _Just . tcString
return $
runTerminalString (pc ++ s) tm $
w
& cWorld . lWorld . terminals . ix (_tmID tm) . tmPartialCommand .~ Nothing
& cWorld . lWorld . terminals . ix (_tmID tm) . tmFutureLines .~
[makeTermLine (pc ++ "> " ++ s)]
runTerminalString :: String -> Terminal -> World -> World
runTerminalString s tm w =
w & cWorld . lWorld . terminals . ix (_tmID tm)
%~ ( (tmInput .~ TerminalInput {_tiText = mempty, _tiFocus = True, _tiSel = (0, 0)})
. (tmFutureLines ++.~ commandFutureLines s tm w)
. (tmCommandHistory %~ take 10 . (s :))
)