Cleanup
This commit is contained in:
@@ -4,29 +4,15 @@ import Dodge.SoundLogic
|
||||
import Dodge.WorldEvent.Cloud
|
||||
import Dodge.Data
|
||||
import Dodge.Inventory.Lock
|
||||
import Dodge.Placement.Instance.Terminal
|
||||
import Dodge.Data.WorldEffect
|
||||
import Dodge.Data.Terminal
|
||||
import Dodge.Data
|
||||
import Dodge.Default
|
||||
--import Dodge.Base
|
||||
import Dodge.SoundLogic
|
||||
import Color
|
||||
import Justify
|
||||
import LensHelp
|
||||
import Sound.Data
|
||||
import ListHelp (safeUncons,safeHead)
|
||||
|
||||
import Data.Char
|
||||
import Data.Maybe
|
||||
import Data.Foldable
|
||||
import qualified Data.Map.Strict as M
|
||||
import qualified IntMapHelp as IM
|
||||
import qualified Data.Text as T
|
||||
--import Text.Read
|
||||
|
||||
import System.Random
|
||||
import Control.Lens
|
||||
|
||||
doWorldEffect :: WdWd -> World -> World
|
||||
doWorldEffect we = case we of
|
||||
@@ -39,6 +25,7 @@ doWorldEffect we = case we of
|
||||
MakeStartCloudAt p -> makeStartCloudAt p
|
||||
TorqueCr x cid -> torqueCr x cid
|
||||
SoundStart so p sid mi -> soundStart so p sid mi
|
||||
WdWdNegateTrig trid -> triggers . ix trid %~ not
|
||||
|
||||
accessTerminal :: Maybe Int -> World -> World
|
||||
accessTerminal mtmid w = case mtmid of
|
||||
@@ -64,42 +51,6 @@ torqueCr x cid w
|
||||
|
||||
|
||||
|
||||
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)]
|
||||
|
||||
commandFutureLines :: String -> Terminal -> World -> [TerminalLine]
|
||||
commandFutureLines s tm w = fromMaybe [errline "^ INVALID COMMAND"] $ do
|
||||
(str,args) <- safeUncons $ words s
|
||||
command <- find (\tc -> _tcString tc == str || str `elem` _tcAlias tc) (getCommands tm)
|
||||
case doTerminalCommandEffect (_tcEffect command) tm w of
|
||||
NoArguments tls -> Just tls
|
||||
OneArgument argtype m -> Just $ fromMaybe [errline $ "^ INVALID ARGUMENT: EXPECTS "++ argtype]
|
||||
$ safeHead args >>= (m M.!?)
|
||||
where
|
||||
errline = makeColorTermLine red
|
||||
|
||||
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:))
|
||||
)
|
||||
|
||||
defocusTerminalInput :: World -> World
|
||||
defocusTerminalInput w = fromMaybe w $ do
|
||||
tmid <- w ^? hud . hudElement . subInventory . termID
|
||||
return $ w & terminals . ix tmid . tmInput . tiFocus %~ const False
|
||||
|
||||
doCommandInstant :: String -> Terminal -> World -> World
|
||||
doCommandInstant arg tm w = doLineEffectsInstant tm w $ commandFutureLines arg tm w
|
||||
|
||||
@@ -154,5 +105,5 @@ doTmWdWd tmwdwd = case tmwdwd of
|
||||
TmWdWdTermSound sid -> \tm w -> let tpos = fromMaybe 0 $ w ^? buttons . ix (_tmButtonID tm) . btPos
|
||||
in soundStart TerminalSound tpos sid Nothing w
|
||||
TmWdWdDoDeathTriggers -> doDeathTriggers
|
||||
--TmWdWdfromWdWd f -> \_ -> doWorldEffect f
|
||||
TmWdWdfromWdWd f -> \_ -> doWorldEffect f
|
||||
|
||||
|
||||
Reference in New Issue
Block a user