Update help strings for "ctool" chat command

This commit is contained in:
Jordan Irwin 2021-07-30 17:17:48 -07:00
parent c98f6a656e
commit 4d959e69cb

View File

@ -32,6 +32,9 @@ local param_def = {
old_item = {name=S("old_item"), desc=S("Technical name of item to be replaced.")}, old_item = {name=S("old_item"), desc=S("Technical name of item to be replaced.")},
new_item = {name=S("new_item"), desc=S("Technical name of item to be used in place.")}, new_item = {name=S("new_item"), desc=S("Technical name of item to be used in place.")},
ore = {name=S("ore"), desc=S("Ore technical name.")}, ore = {name=S("ore"), desc=S("Ore technical name.")},
action = {name=S("action"),
desc=S('Action to execute. Can be one of "@1", "@2", or "@3".', "status", "setmode", "setnode")},
value = {name=S("value"), desc=S('Mode or node to be set for tool (not required for "@1" action).', "status")},
} }
local cmd_repo = { local cmd_repo = {
@ -62,6 +65,10 @@ local cmd_repo = {
cmd = "remove_ores", cmd = "remove_ores",
params = {"ore"}, params = {"ore"},
}, },
tool = {
cmd = "ctool",
params = {"action", "value"},
},
param = { param = {
missing = S("Missing parameter."), missing = S("Missing parameter."),
excess = S("Too many parameters."), excess = S("Too many parameters."),
@ -468,12 +475,11 @@ end
-- @chatcmd ctool -- @chatcmd ctool
-- @param action Action to execute. Can be "status", "setmode", or "setnode". -- @param action Action to execute. Can be "status", "setmode", or "setnode".
-- @param value Mode or node to be set for tool. -- @param value Mode or node to be set for tool.
core.register_chatcommand("ctool", { core.register_chatcommand(cmd_repo.tool.cmd, {
privs = {server=true}, privs = {server=true},
description = S("Manage settings for wielded cleaner tool.") .. "\n\n" description = S("Manage settings for wielded cleaner tool.") .. "\n\n"
.. S("Params:") .. "\n action: Action to execute. Can be one of \"status\", \"setmode\", or \"setnode\"." .. format_params(cmd_repo.tool.cmd),
.. "\n value: Mode or node to be set for tool.", params = cmd_repo.tool.help.param_string,
params = "<action> <value>",
func = function(name, param) func = function(name, param)
local action, value = param local action, value = param
local idx = param:find(" ") local idx = param:find(" ")
@ -483,23 +489,25 @@ core.register_chatcommand("ctool", {
value = param[2] value = param[2]
end end
local help = format_help(cmd_repo.tool.cmd)
local player = core.get_player_by_name(name) local player = core.get_player_by_name(name)
local stack = player:get_wielded_item() local stack = player:get_wielded_item()
local iname = aux.tool:format_name(stack) local iname = aux.tool:format_name(stack)
local imeta = stack:get_meta() local imeta = stack:get_meta()
if iname ~= "cleaner:pencil" then if iname ~= "cleaner:pencil" then
return false, S("Unrecognized wielded item: @1", iname) return false, S("Unrecognized wielded item: @1", iname) .. "\n\n" .. help
end end
if action == "status" then if action == "status" then
core.chat_send_player(name, iname .. ": " core.chat_send_player(name, iname .. ": " .. S("mode") .. "=" .. imeta:get_string("mode")
.. S("mode=@1, node=@2", imeta:get_string("mode"), imeta:get_string("node"))) .. ", " .. S("node") .. "=" .. imeta:get_string("node"))
return true return true
end end
if not action or not value then if not action or not value then
return false, S("Missing parameter.") return false, S("Missing parameter.") .. "\n\n" .. help
end end
if action == "setmode" then if action == "setmode" then
@ -507,7 +515,7 @@ core.register_chatcommand("ctool", {
elseif action == "setnode" then elseif action == "setnode" then
stack = aux.tool:set_node(stack, value, name) stack = aux.tool:set_node(stack, value, name)
else else
return false, S("Unrecognized action: @1", action) return false, S("Unrecognized action: @1", action) .. "\n\n" .. help
end end
return player:set_wielded_item(stack) return player:set_wielded_item(stack)