Module:Item class
Implements {{item class list}} and {{item class infocard}}.
The above documentation is transcluded from Module:Item class/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
-------------------------------------------------------------------------------
--
-- Module:Item class
--
-- This module implements Template:Item class list and
-- Template:Item class infocard
-------------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- Includes
-- ----------------------------------------------------------------------------
require('Module:No globals')
local m_util = require('Module:Util')
-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('Item class')
local m_game = use_sandbox and mw.loadData('Module:Game/sandbox') or mw.loadData('Module:Game')
-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:Item class/config/sandbox') or mw.loadData('Module:Item class/config')
local i18n = cfg.i18n
-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------
local function _list(args)
local tbl = mw.html.create('table')
:attr('class', 'wikitable sortable')
local tr = mw.html.create('tr')
local headers = {
i18n.list.item_class,
i18n.list.internal_name,
i18n.list.internal_id,
}
for _, h in ipairs(headers) do
tr
:tag('th')
:wikitext(h)
end
tbl:node(tr)
for id, class_data in pairs(m_game.constants.item.classes) do
tr = mw.html.create('tr')
if not cfg.list.skip_ids[id] and not class_data.disabled and class_data.long_lower then
local fields = {
m_util.html.wikilink(m_util.string.first_to_upper(class_data.long_lower)),
class_data.name,
id,
}
for _, f in ipairs(fields) do
tr
:tag('td')
:wikitext(f)
end
tbl:node(tr)
end
end
return tostring(tbl)
end
local function _infocard(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.infocard.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.infocard.also_referred_to_as, tostring(ul)))
end
if (args.verbose) then
table.insert(infocard_args, string.format(i18n.infocard.long_upper, tostring(constinfo['long_upper'])))
table.insert(infocard_args, string.format(i18n.infocard.long_lower, tostring(constinfo['long_lower'])))
end
table.insert(infocard_args, string.format(i18n.infocard.filterid, tostring(filterid)))
if (constinfo['is_removed'] == true) then
table.insert(infocard_args, i18n.infocard.is_removed)
end
-- Output Infocard
infocard_args['header'] = args.name
infocard_args['subheader'] = i18n.infocard.page .. i18n.infocard.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 = {}
--
-- Template:Item class list
--
p.list = m_util.misc.invoker_factory(_list, {
wrappers = cfg.wrappers.item_class_list,
})
--
-- Template:Item class infocard
--
p.infocard = m_util.misc.invoker_factory(_infocard, {
wrappers = cfg.wrappers.item_class_infocard,
})
return p