Add 'listores' chat command

master
AntumDeluge 2017-08-03 11:09:16 -07:00
parent 6228eea56b
commit a25011e70e
4 changed files with 50 additions and 20 deletions

View File

@ -7,10 +7,11 @@
#### Chat Commands:
- ***listitems:*** Lists registered craft items available in the game.
- ***listentities:*** Lists registered entities available in the game.
- ***listores:*** Lists registered ores available in the game.
- Invocation: ```/<command> [options] [string1] [string2] ...```
- ***command:*** Name of the command (e.g. *listitems*, *listentities*)
- ***command:*** Name of the command (e.g. *listitems*, *listentities*, etc.)
- ***options:*** Switches to control output behavior.
- ***-v:*** Display description after object name
- ***-v:*** Display description (if available) after object name
- ***string[1,2] ...:*** String parameter(s) to filter output.
- Without any string parameters, all objects registered in game are listed.
- With string parameters, only objects matching any of the strings will be listed.

46
api.lua
View File

@ -71,23 +71,30 @@ end
-- @function getRegistered
-- @local
-- @tparam string r_type Must be either "items" or "entities".
-- @treturn table Either a list of registered item or entity names & descriptions.
-- @treturn table Either a list of registered item or entity names & descriptions.
-- @note Ore names are located in the "ore" field of the registered tables
local function getRegistered(r_type)
if r_type == nil then
r_type = 'items'
end
-- Default is "items"
r_type = r_type or 'items'
local o_names = {}
local objects = {}
local o_temp = {}
if r_type == 'items' then
o_temp = core.registered_items
else
if r_type == 'entities' then
o_temp = core.registered_entities
elseif r_type == 'ores' then
o_temp = core.registered_ores
else
o_temp = core.registered_items
end
for name, def in pairs(o_temp) do
-- Ore names are located in the 'ore' field of the table
if r_type == 'ores' then
name = def.ore
end
table.insert(objects, {name=name, descr=def.description,})
table.insert(o_names, name)
end
@ -294,7 +301,7 @@ end
-- @tparam string player Name of player to receive message output.
-- @tparam string params String list of parameters.
-- @tparam string switches String list of switch options for manipulating output.
-- @tparam string l_type Objects to list (either "items" or "entities").
-- @tparam string l_type Objects to list (either "items", "entities", or "ores").
-- @tparam boolean lower Case-insensitive matching if ***true***.
-- @treturn boolean
function listitems.list(player, params, switches, l_type, lower)
@ -302,7 +309,7 @@ function listitems.list(player, params, switches, l_type, lower)
l_type = l_type or 'items'
lower = lower == nil or lower == true
local types = {'items', 'entities',}
local types = {'items', 'entities', 'ores',}
if not listContains(types, l_type) then
listitems.logWarn('listitems.listitems called with unknown list type: ' .. tostring(l_type))
return false
@ -383,3 +390,24 @@ registerChatCommand('listentities', {
return listitems.list(player, params, switches, 'entities')
end,
})
--- Lists registered ores.
--
-- @chatcmd listores
-- @chatparam [-v]
-- @chatparam [string1]
-- @chatparam [string2]
-- @chatparam ...
-- @treturn boolean
registerChatCommand('listores', {
params = '[-v] [' .. S('string1') .. '] [' .. S('string2') .. '] ...',
description = S('List registered ores'),
func = function(player, params)
local switches = extractSwitches(string.split(params, ' '))
params = removeListDuplicates(switches[2])
switches = switches[1]
return listitems.list(player, params, switches, 'ores')
end,
})

View File

@ -5,7 +5,7 @@ not_luadoc = true
--wrap = true
boilerplate = true
local function tagoutput(value)
local function italic(value)
return '<i>' .. value .. '</i>'
end
@ -13,11 +13,11 @@ new_type('setting', 'Settings')
new_type('chatcmd', 'Chat Commands', false, 'chatparam')
custom_tags = {
{'default',
format = tagoutput,
format = italic,
},
{'type2',
title = 'Type',
format = tagoutput,
format = italic,
},
{'dfield',
title = 'Definition Fields',
@ -38,14 +38,14 @@ custom_tags = {
},
{'settype',
title = 'Type',
format = function(item)
return '<i>' .. item .. '</i>'
end,
}
format = italic,
},
{'note',
title = 'Notes',
format = italic,
},
}
alias('tchatparam', 'chatparam')
local function chatcmd_handler(item)
local output = item.name
for i, p in ipairs(item.tags.chatparam) do

View File

@ -4,6 +4,7 @@
## Help output description
List registered items =
List registered entities =
List registered ores =
## Help output parameters
options =