This commit is contained in:
2023-05-01 22:35:33 +01:00
parent 7b8b8750a9
commit 61f88aeb4a
9 changed files with 120 additions and 121 deletions
+16 -21
View File
@@ -22,7 +22,6 @@ import Data.Char
import Data.Foldable
import qualified Data.Map.Strict as M
import Data.Maybe
--import qualified Data.Text as T
import Dodge.Data.World
import Dodge.Default
import Dodge.SoundLogic
@@ -38,7 +37,6 @@ basicTerminal =
, _tmFutureLines = []
, _tmMaxLines = 14
, _tmTitle = "TERMINAL"
, _tmInput = defaultTerminalInput
, _tmScrollCommands = [quitCommand]
, _tmWriteCommands = [helpCommand, commandsCommand]
, _tmBootProgram = TerminalBootLines connectionBlurb
@@ -112,11 +110,6 @@ connectionBlurb =
termSoundLine :: SoundID -> TerminalLine
termSoundLine sid = TerminalLineEffect 0 (TmWdWdTermSound sid)
-- where
-- termsound tm w = soundStart TerminalSound tpos sid Nothing w
-- where
-- tpos = fromMaybe 0 $ w ^? buttons . ix (_tmButtonID tm) . btPos
termTextColor :: Color
termTextColor = greyN 0.9
@@ -141,14 +134,14 @@ commandColor = yellow
doTerminalCommandEffect :: TerminalCommandEffect -> Terminal -> World -> EffectArguments
doTerminalCommandEffect tce = case tce of
TerminalCommandArguments eas -> \_ _ -> eas
TerminalCommandEffectDamageCoding -> \_ -> OneArgument "A DAMAGE TYPE" . getDamageCoding
TerminalCommandEffectSensorParameter -> \tm -> OneArgument "A SENSOR PARAMETER" . sensorInfoMap tm
TerminalCommandEffectLinkedObject -> \tm _ -> OneArgument "A LINKED OBJECT" (togglesToEffects tm)
TerminalCommandEffectHelp -> \tm -> OneArgument "AN AVAILABLE COMMAND" . getCommandsHelp tm
TerminalCommandEffectDamageCoding -> \_ -> OneArgument "a damage type" . getDamageCoding
TerminalCommandEffectSensorParameter -> \tm -> OneArgument "a sensor parameter" . sensorInfoMap tm
TerminalCommandEffectLinkedObject -> \tm _ -> OneArgument "a linked object" (togglesToEffects tm)
TerminalCommandEffectHelp -> \tm -> OneArgument "an available command" . getCommandsHelp tm
TerminalCommandEffectNoArgumentsStr str -> \_ _ -> NoArguments (makeTermPara str)
TerminalCommandEffectCommands -> \tm _ ->
NoArguments
( makeTermLine "AVAILABLE COMMANDS:" :
( makeTermLine "Available commands:" :
makeColorTermPara commandColor (unwords (map _tcString $ getCommands tm))
)
TerminalCommandEffectSingleCommand eff followingLines -> \_ _ -> NoArguments $ TerminalLineEffect 0 (TmWdWdfromWdWd eff) : map makeTermLine followingLines
@@ -156,9 +149,9 @@ doTerminalCommandEffect tce = case tce of
argumentHelp :: TerminalCommand -> Terminal -> World -> (String, Maybe [String])
argumentHelp tc tm w = case doTerminalCommandEffect (_tcEffect tc) tm w of
NoArguments{} -> ("ANY ARGUMENTS PROVIDED TO THIS COMMAND ARE IGNORED.", Nothing)
NoArguments{} -> ("Any arguments provided to this command are ignored.", Nothing)
OneArgument argtype argm ->
( "EXPECTS " ++ argtype ++ " AS ARGUMENT. AVAILABLE ARGUMENTS: "
( "Expects " ++ argtype ++ " as argument. Available arguments: "
, Just (M.keys argm)
)
@@ -192,10 +185,10 @@ getDamageCoding = decodedtmap . _sensorCoding . _cwgParams . _cwGen . _cWorld
sensorInfoMap :: Terminal -> World -> M.Map String [TerminalLine]
sensorInfoMap tm w =
M.fromList
[ ("REQUIREMENT", getSensor _proxRequirement tm w)
, ("DISTANCE", getSensor _proxDist tm w)
, ("CURRENTSTATUS", getSensor _proxStatus tm w)
, ("PASTSTATUS", getSensor _sensToggle tm w)
[ ("Requirement", getSensor _proxRequirement tm w)
, ("Distance", getSensor _proxDist tm w)
, ("Currentstatus", getSensor _proxStatus tm w)
, ("Paststatus", getSensor _sensToggle tm w)
]
getSensor :: Show a => (Sensor -> a) -> Terminal -> World -> [TerminalLine]
@@ -270,9 +263,11 @@ commandFutureLines s tm w = fromMaybe [errline "^ INVALID COMMAND"] $ do
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] $
OneArgument argtype m ->
let setpartial = TerminalLineTerminalEffect 0 (TmTmSetPartialCommand (Just str))
: makeTermPara ("expects " ++ argtype ++ " as an argument")
in Just $
fromMaybe setpartial $
safeHead args >>= (m M.!?)
where
errline = makeColorTermLine red