rename debug terminal to console #1

Open
ross wants to merge 1 commits from renameConsole into master
2 changed files with 29 additions and 29 deletions
@@ -1,6 +1,6 @@
{-# LANGUAGE TupleSections #-}
module Dodge.Debug.Terminal where
module Dodge.Debug.Console where
import Data.Foldable
import Dodge.Item.Location.Initialize
@@ -19,14 +19,14 @@ import LensHelp
import MaybeHelp
import Text.Read (readMaybe)
applyTerminalString :: [String] -> Universe -> Universe
applyTerminalString ss = case ss of
applyConsoleString :: [String] -> Universe -> Universe
applyConsoleString ss = case ss of
[] -> id
[s] -> applyTerminalCommand s
(s : ss') -> applyTerminalCommandArguments s ss'
[s] -> applyConsoleCommand s
(s : ss') -> applyConsoleCommandArguments s ss'
applyTerminalCommand :: String -> Universe -> Universe
applyTerminalCommand s = case s of
applyConsoleCommand :: String -> Universe -> Universe
applyConsoleCommand s = case s of
"NOCLIP" -> uvConfig . debug_booleans . at Noclip %~ toggleJust
['L', x] ->
(uvWorld . cWorld . lWorld %~ initSpecificCrItemLocations 0)
@@ -39,8 +39,8 @@ applyTerminalCommand s = case s of
(ibt, n) <- parseItem [x]
return $ uvWorld %~ flip (foldl' (&)) (replicate n (snd . createItemYou (itemFromBase ibt)))
applyTerminalCommandArguments :: String -> [String] -> Universe -> Universe
applyTerminalCommandArguments command args u = case command of
applyConsoleCommandArguments :: String -> [String] -> Universe -> Universe
applyConsoleCommandArguments command args u = case command of
"IT" -> fromMaybe u $ do
(ibt, n) <- parseItem args
return $ u & uvWorld %~ flip (foldl' (&)) (replicate n (snd . createItemYou (itemFromBase ibt)))
@@ -75,33 +75,33 @@ parseItem [] = Nothing
parseNum :: [String] -> Int
parseNum xs = fromMaybe 1 $ xs ^? ix 0 >>= readMaybe
showTerminalError :: String -> String -> Universe -> Universe
showTerminalError cmd s = uvScreenLayers .:~ InputScreen cmd s
showConsoleError :: String -> String -> Universe -> Universe
showConsoleError cmd s = uvScreenLayers .:~ InputScreen cmd s
applySetTerminalString :: String -> Universe -> Universe
applySetTerminalString [] = id
applySetTerminalString var = case key' of
"" -> showTerminalError ("set " ++ var) ("Unable to read as argument as float: " ++ val)
applySetConsoleString :: String -> Universe -> Universe
applySetConsoleString [] = id
applySetConsoleString var = case key' of
"" -> showConsoleError ("set " ++ var) ("Unable to read as argument as float: " ++ val)
"hp" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crHP .~ round (fromJust val')
-- "invcap" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crInvCapacity .~ round (fromJust val')
-- "mass" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crMass .~ fromJust val'
-- "mvspeed" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crMvType . mvSpeed .~ fromJust val'
"mvspeed" -> uvWorld . cWorld . lWorld . creatures . ix 0 . crType . avMoveSpeed .~ fromJust val'
_ -> showTerminalError ("set " ++ var) ("Invalid set command: " ++ key) -- never reached?
_ -> showConsoleError ("set " ++ var) ("Invalid set command: " ++ key) -- never reached?
where
(key, val) = getSplitString var
val' = readMaybe val :: Maybe Float
key' = if isNothing val' then "" else key
--autoCompleteTerminal :: String -> String -> Universe -> IO (Maybe Universe)
--autoCompleteTerminal s _ =
--autoCompleteConsole :: String -> String -> Universe -> IO (Maybe Universe)
--autoCompleteConsole s _ =
-- return
-- . (popScreen' >=> pushScreen' (InputScreen (T.pack input_str) valid_commands))
-- where
-- (key, val) = getSplitString $ tail s
-- command_options = case val of
-- "" -> filter (isInfixOf key) (validTerminalCommands "")
-- _ -> filter (isInfixOf val) (validTerminalCommands key)
-- "" -> filter (isInfixOf key) (validConsoleCommands "")
-- _ -> filter (isInfixOf val) (validConsoleCommands key)
-- -- basic autocomplete if single option available (or as far as possible)
-- input_str = case (key, val) of
-- (_, "") ->
@@ -117,7 +117,7 @@ applySetTerminalString var = case key' of
-- else ">" ++ key ++ " " ++ longestCommonPrefix command_options
-- command_options' =
-- if not (null command_options) && head command_options == key
-- then validTerminalCommands key
-- then validConsoleCommands key
-- else command_options
--
-- --val' = Debug.Trace.trace key tail val
@@ -129,12 +129,12 @@ getSplitString str = case break (== ' ') str of
(a, _) -> (a, "")
isValidCommand :: String -> String -> Bool
isValidCommand arg1 arg2 = arg2 `elem` validTerminalCommands arg1
validTerminalCommands :: String -> [String]
validTerminalCommands "set" = ["hp", "invcap", "invsel", "mass", "mvspeed"]
validTerminalCommands "god" = ["on", "off"]
validTerminalCommands _ = ["set", "spawn", "god"]
isValidCommand arg1 arg2 = arg2 `elem` validConsoleCommands arg1
validConsoleCommands :: String -> [String]
validConsoleCommands "set" = ["hp", "invcap", "invsel", "mass", "mvspeed"]
validConsoleCommands "god" = ["on", "off"]
validConsoleCommands _ = ["set", "spawn", "god"]
validConsoleCommands _ = ["set", "spawn", "god"]
loadme :: a
loadme = undefined
+2 -2
View File
@@ -11,7 +11,7 @@ import qualified Data.Map.Strict as M
import Data.Maybe
import Dodge.Data.ScreenPos
import Dodge.Data.Universe
import Dodge.Debug.Terminal
import Dodge.Debug.Console
import Dodge.Menu.Option
import Dodge.SelectionList
import Dodge.Update.Input.Text
@@ -34,7 +34,7 @@ doInputScreenInput s u =
checkEndStatus
| ispressed ScancodeReturn =
(uvScreenLayers %~ tail)
. applyTerminalString (words $ map toUpper s)
. applyConsoleString (words $ map toUpper s)
. (uvWorld . worldEventFlags . at InventoryChange ?~ ())
| ispressed ScancodeEscape = uvScreenLayers %~ tail
| otherwise = id