Add file
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
module Dodge.Terminal.LeftButton
|
||||
where
|
||||
import Dodge.Data
|
||||
import Dodge.Terminal -- this goes the wrong way!
|
||||
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 ^? 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 ^? terminals . ix (_tmID tm) . tmInput . tiText
|
||||
return $ runTerminalString s tm $ w
|
||||
& terminals . ix (_tmID tm) . tmFutureLines .~ [makeTermLine ('>':s)]
|
||||
|
||||
defocusTerminalInput :: World -> World
|
||||
defocusTerminalInput w = fromMaybe w $ do
|
||||
tmid <- w ^? hud . hudElement . subInventory . termID
|
||||
return $ w & terminals . ix tmid . tmInput . tiFocus %~ const False
|
||||
|
||||
runTerminalString :: String -> Terminal -> World -> World
|
||||
runTerminalString s tm w = w & terminals . ix (_tmID tm) %~
|
||||
( (tmInput .~ TerminalInput T.empty True (0,0))
|
||||
. (tmFutureLines ++.~ commandFutureLines s tm w)
|
||||
. (tmCommandHistory %~ take 10 . (s:))
|
||||
)
|
||||
Reference in New Issue
Block a user