Refactor, try to limit dependencies

This commit is contained in:
2022-07-28 00:59:56 +01:00
parent 8aa5c17ab9
commit 160560af5f
418 changed files with 15104 additions and 13342 deletions
+25 -21
View File
@@ -1,24 +1,27 @@
module Dodge.Terminal.LeftButton
where
import Dodge.Data
import Dodge.Terminal -- this goes the wrong way!
module Dodge.Terminal.LeftButton where
import Data.Maybe
import qualified Data.Text as T
import Dodge.Data.World
import Dodge.Terminal--oops
import LensHelp
import qualified Data.Text as T
import Data.Maybe
doTerminalEffectLB :: Terminal -> World -> World
doTerminalEffectLB tm w = guardDisconnected tm w $ fromMaybe w $ do
s <- fmap T.unpack $ w ^? cWorld . terminals . ix (_tmID tm) . tmInput . tiText
if null (words s)
then Just $ defocusTerminalInput w
else return $ terminalReturnEffect tm w
doTerminalEffectLB tm w = guardDisconnected tm w $
fromMaybe w $ do
s <- fmap T.unpack $ w ^? cWorld . 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 <- fmap T.unpack $ w ^? cWorld . terminals . ix (_tmID tm) . tmInput . tiText
return $ runTerminalString s tm $ w
& cWorld . terminals . ix (_tmID tm) . tmFutureLines .~ [makeTermLine ('>':s)]
terminalReturnEffect tm w = guardDisconnected tm w $
fromMaybe w $ do
s <- fmap T.unpack $ w ^? cWorld . terminals . ix (_tmID tm) . tmInput . tiText
return $
runTerminalString s tm $
w
& cWorld . terminals . ix (_tmID tm) . tmFutureLines .~ [makeTermLine ('>' : s)]
defocusTerminalInput :: World -> World
defocusTerminalInput w = fromMaybe w $ do
@@ -26,8 +29,9 @@ defocusTerminalInput w = fromMaybe w $ do
return $ w & cWorld . terminals . ix tmid . tmInput . tiFocus %~ const False
runTerminalString :: String -> Terminal -> World -> World
runTerminalString s tm w = w & cWorld . terminals . ix (_tmID tm) %~
( (tmInput .~ TerminalInput T.empty True (0,0))
. (tmFutureLines ++.~ commandFutureLines s tm w)
. (tmCommandHistory %~ take 10 . (s:))
)
runTerminalString s tm w =
w & cWorld . terminals . ix (_tmID tm)
%~ ( (tmInput .~ TerminalInput T.empty True (0, 0))
. (tmFutureLines ++.~ commandFutureLines s tm w)
. (tmCommandHistory %~ take 10 . (s :))
)