Module:Item class/sandbox: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 38: | Line 38: | ||
local filterid = nil | local filterid = nil | ||
for id, row in pairs(m_game.constants.item.classes) do | for id, row in pairs(m_game.constants.item.classes) do | ||
if row['full'] == | if row['full'] == args.name then | ||
constinfo = row | constinfo = row | ||
filterid = id | filterid = id | ||
Line 46: | Line 46: | ||
if constinfo == nil then | if constinfo == nil then | ||
error(string.format(i18n.errors.invalid_class, tostring( | error(string.format(i18n.errors.invalid_class, tostring(args.name))) | ||
end | end | ||
Line 53: | Line 53: | ||
local infocard_args = {} | local infocard_args = {} | ||
if | if args.name_list ~= nil then | ||
local names = m_util.string.split( | local names = m_util.string.split(args.name_list, ',%s*') | ||
local ul = mw.html.create('ul') | local ul = mw.html.create('ul') | ||
for _, item in ipairs(names) do | for _, item in ipairs(names) do | ||
Line 65: | Line 65: | ||
end | end | ||
if ( | if (args.verbose) then | ||
table.insert(infocard_args, string.format(i18n.long_upper, tostring(constinfo['long_upper']))) | table.insert(infocard_args, string.format(i18n.long_upper, tostring(constinfo['long_upper']))) | ||
table.insert(infocard_args, string.format(i18n.long_lower, tostring(constinfo['long_lower']))) | table.insert(infocard_args, string.format(i18n.long_lower, tostring(constinfo['long_lower']))) | ||
Line 77: | Line 77: | ||
-- Output Infocard | -- Output Infocard | ||
infocard_args['header'] = | infocard_args['header'] = args.name | ||
infocard_args['subheader'] = i18n.page .. i18n.info | infocard_args['subheader'] = i18n.page .. i18n.info | ||
Line 84: | Line 84: | ||
local cats = { | local cats = { | ||
'Item classes', | 'Item classes', | ||
args.name, | |||
} | } | ||
-- Done | -- Done | ||
return doInfoCard(infocard_args) .. m_util.misc.add_category(cats, {ignore_blacklist= | return doInfoCard(infocard_args) .. m_util.misc.add_category(cats, {ignore_blacklist=args.debug}) | ||
end | end | ||
Revision as of 18:32, 4 March 2022
This is the module sandbox page for Module:Item class (diff).
The above documentation is transcluded from Module:Item class/doc.
Editors can experiment in this module's sandbox and testcases pages.
Please add categories to the /doc subpage. Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Please add categories to the /doc subpage. Subpages of this module.
-------------------------------------------------------------------------------
--
-- Module:Item class infocard
--
-- This module implements Template:Item class infocard
-------------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- Includes
-- ----------------------------------------------------------------------------
local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local m_game = mw.loadData('Module:Game')
local i18n = {
page = '[[Item class]]',
info = m_util.html.abbr('(?)', 'Item classes categorize items. Classes are often used to restrict items or skill gems to a specific class or by item filters'),
also_referred_to_as = 'Also referred to as: %s',
filterid = 'Item filter ID: %s',
is_removed = "''Removed from the game.''",
long_upper = 'Long uppercase name: %s',
long_lower = 'Long lowercase name: %s',
errors = {
invalid_class = 'The item class name "%s" is invalid.',
},
}
-- ----------------------------------------------------------------------------
-- Main function
-- ----------------------------------------------------------------------------
local function _main(args)
local doInfoCard = require('Module:Infocard').main
local constinfo = nil
local filterid = nil
for id, row in pairs(m_game.constants.item.classes) do
if row['full'] == args.name then
constinfo = row
filterid = id
break
end
end
if constinfo == nil then
error(string.format(i18n.errors.invalid_class, tostring(args.name)))
end
--
local infocard_args = {}
if args.name_list ~= nil then
local names = m_util.string.split(args.name_list, ',%s*')
local ul = mw.html.create('ul')
for _, item in ipairs(names) do
ul
:tag('li')
:wikitext(item)
:done()
end
table.insert(infocard_args, string.format(i18n.also_referred_to_as, tostring(ul)))
end
if (args.verbose) then
table.insert(infocard_args, string.format(i18n.long_upper, tostring(constinfo['long_upper'])))
table.insert(infocard_args, string.format(i18n.long_lower, tostring(constinfo['long_lower'])))
end
table.insert(infocard_args, string.format(i18n.filterid, tostring(filterid)))
if (constinfo['is_removed'] == true) then
table.insert(infocard_args, i18n.is_removed)
end
-- Output Infocard
infocard_args['header'] = args.name
infocard_args['subheader'] = i18n.page .. i18n.info
-- cats
local cats = {
'Item classes',
args.name,
}
-- Done
return doInfoCard(infocard_args) .. m_util.misc.add_category(cats, {ignore_blacklist=args.debug})
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
p.main = m_util.misc.invoker_factory(_main, {
wrappers = 'Template:Item class infocard',
})
return p