Start to refactor terminals
This commit is contained in:
@@ -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
|
||||
@@ -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 :))
|
||||
)
|
||||
Reference in New Issue
Block a user