This commit is contained in:
2022-06-02 09:29:44 +01:00
parent b6e2b6ef21
commit 98cb8f2264
8 changed files with 57 additions and 48 deletions
+9 -4
View File
@@ -29,20 +29,25 @@ helpCommand = TerminalCommand
, _tcHelp = "DISPLAYS HELP FOR A SPECIFIC COMMAND. TO DISPLAY AVAILABLE COMMANDS USE \"COMMANDS\"."
, _tcArgumentType = Just "AN AVAILABLE COMMAND"
, _tcArguments = \w -> fromMaybe [] $ do
commands <- w ^? hud . hudElement . subInventory . termParams . termCommands
commands <- getCommands w
return $ map _tcString commands
, _tcEffect = helpf
}
helpf :: [String] -> World -> Either String World
helpf [] w = helpf ["HELP"] w
helpf (str:_) w = maybe (Left "") Right $ do
commands <- w ^? hud . hudElement . subInventory . termParams . termCommands
commands <- getCommands w
command <- find (\tc -> _tcString tc == str || str `elem` _tcAlias tc) commands
return $ w & infoClearInput
([TerminalLineDisplay 0 $ const ("COMMAND:" ++ _tcString command,white)
,TerminalLineDisplay 0 $ const ("ALIASES:" ++ unwords (_tcAlias command),white) ]
++ stringToTermPara (_tcHelp command ++ " " ++ argumentHelp (_tcArgumentType command))
)
getCommands :: World -> Maybe [TerminalCommand]
getCommands w = do
commands1 <- w ^? hud . hudElement . subInventory . termParams . termScrollCommands
commands2 <- w ^? hud . hudElement . subInventory . termParams . termWriteCommands
return $ commands1 ++ commands2
infoClearInput :: [TerminalLine] -> World -> World
infoClearInput tls = hud . hudElement . subInventory . termParams %~
@@ -81,7 +86,7 @@ commandsCommand = TerminalCommand
, _tcArguments = const []
, _tcEffect = const $ \w -> Right $ w & infoClearInput
(TerminalLineDisplay 0 (const ("AVAILABLE COMMANDS:",white))
: stringToTermPara (unwords (maybe [""] (map _tcString) $ w ^? hud . hudElement . subInventory . termParams . termCommands))
: stringToTermPara (unwords (maybe [""] (map _tcString) $ getCommands w))
)
}
@@ -103,7 +108,7 @@ doTerminalEffect w = fromMaybe w $ do
doTerminalEffect' :: String -> World -> World
doTerminalEffect' s w = fromMaybe (w & badinput) $ do
commands <- w ^? hud . hudElement . subInventory . termParams . termCommands
commands <- getCommands w
if null (words s) then Just $ disconnectTerminal w else do
let (str:args) = words s
command <- find (\tc -> _tcString tc == str || str `elem` _tcAlias tc) commands