Add option to register singleword commands

master
Jordan Irwin 2021-04-29 05:53:25 -07:00
parent f643959113
commit 13797c8167
5 changed files with 33 additions and 6 deletions

View File

@ -1,3 +1,3 @@
- add setting to include single word commands, e.g. /listitems
TODO:
- display "searching..." text before search begins, not after

26
api.lua
View File

@ -237,6 +237,7 @@ local function formatMatching(player, nlist, params, switches, nocase)
end
end
else
-- FIXME: messages don't display until after list is loaded
if deep_search then
core.chat_send_player(player, "\n" .. S("Searching in names and descriptions ..."))
else
@ -408,12 +409,14 @@ local function list(player, l_type, params)
end
local help_string = S("List registered items or entities\n\n\tOptions:")
local help_string = S("List registered items or entities") .. "\n\n\t" .. S("Options:")
local options_string = ""
for _, o in ipairs(options) do
help_string = help_string .. "\n\t\t" .. o[1] .. ": " .. o[2]
options_string = options_string .. "\n\t\t" .. o[1] .. ": " .. o[2]
end
local types_string = ""
if known_types ~= nil and #known_types > 0 then
help_string = help_string .. "\n\n\t" .. S("Registered types:") .. " " .. table.concat(known_types, ", ")
types_string = types_string .. "\n\n\t" .. S("Registered types:") .. " " .. table.concat(known_types, ", ")
end
--- General *list* chat command.
@ -430,7 +433,7 @@ end
-- @treturn boolean
registerChatCommand("list", {
params = S("type") .. " [options] [" .. S("string1") .. "] [" .. S("string2") .. "] ...",
description = help_string,
description = help_string .. options_string .. types_string,
func = function(player, params)
local params = string.split(params, " ")
local l_type = table.remove(params, 1)
@ -439,3 +442,18 @@ registerChatCommand("list", {
return list(player, l_type, params)
end,
})
if listitems.enable_singleword then
for _, kt in ipairs(known_types) do
registerChatCommand("list" .. kt, {
params = "[options] [" .. S("string1") .. "] [" .. S("string2") .. "] ...",
description = S("List registered @1", kt) .. "\n\n\t" .. S("Options:") .. options_string,
func = function(player, params)
local params = string.split(params, " ")
params = table.concat(params, " ")
return list(player, kt, params)
end,
})
end
end

View File

@ -2,10 +2,12 @@
## Help output description
List registered @1=
List registered items or entities=
Display descriptions=
Don't search descriptions=
Registered types:=
Options:=
## Help output parameters
type=

View File

@ -12,7 +12,7 @@
-- @script settings.lua
listitems.debug = core.settings:get_bool("enable_debug_mods") or false
listitems.debug = core.settings:get_bool("enable_debug_mods", false)
--- Displays items in a bulleted list.
@ -23,3 +23,7 @@ listitems.debug = core.settings:get_bool("enable_debug_mods") or false
-- @settype boolean
-- @default true
listitems.bullet_list = core.settings:get_bool("listitems.bullet_list", true)
--- Registers "/list<type>" commands.
listitems.enable_singleword = core.settings:get_bool("listitems.enable_singleword", true)

View File

@ -1,3 +1,6 @@
# Displays items in a bulleted list.
listitems.bullet_list (Bulleted list) bool true
# Registers "/list<type>" commands.
listitems.enable_singleword (Enable singleword commands) bool true