Module:Item class: Difference between revisions
Jump to navigation
Jump to search
KickahaOta (talk | contribs) (From sandbox: Backed out some changes) |
No edit summary |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
-- | -- | ||
-- Module:Item class | -- Module:Item class | ||
-- | -- | ||
-- This module implements Template:Item class infocard | -- This module implements Template:Item class list and | ||
-- Template:Item class infocard | |||
------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- | ||
Line 10: | Line 11: | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
require('Module:No globals') | |||
local m_util = require('Module:Util') | local m_util = require('Module:Util') | ||
-- Should we use the sandbox version of | -- Should we use the sandbox version of our submodules? | ||
local use_sandbox = m_util.misc.maybe_sandbox('Item class | 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') | 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 | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
function | local function _list(args) | ||
local tbl = mw.html.create('table') | |||
local | :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 | end | ||
return tostring(tbl) | |||
end | |||
local function _infocard(args) | |||
local doInfoCard = require('Module:Infocard').main | |||
local constinfo = nil | local constinfo = nil | ||
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 60: | Line 76: | ||
if constinfo == nil then | if constinfo == nil then | ||
error(string.format(i18n.errors.invalid_class, tostring( | error(string.format(i18n.infocard.errors.invalid_class, tostring(args.name))) | ||
end | end | ||
Line 67: | Line 83: | ||
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 76: | Line 92: | ||
:done() | :done() | ||
end | end | ||
table.insert(infocard_args, string.format(i18n.also_referred_to_as, tostring(ul))) | table.insert(infocard_args, string.format(i18n.infocard.also_referred_to_as, tostring(ul))) | ||
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.infocard.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.infocard.long_lower, tostring(constinfo['long_lower']))) | ||
end | end | ||
table.insert(infocard_args, string.format(i18n.filterid, tostring(filterid))) | table.insert(infocard_args, string.format(i18n.infocard.filterid, tostring(filterid))) | ||
if (constinfo['is_removed'] == true) then | if (constinfo['is_removed'] == true) then | ||
table.insert(infocard_args, i18n.is_removed) | table.insert(infocard_args, i18n.infocard.is_removed) | ||
end | end | ||
-- Output Infocard | -- Output Infocard | ||
infocard_args['header'] = | infocard_args['header'] = args.name | ||
infocard_args['subheader'] = i18n.page .. i18n.info | infocard_args['subheader'] = i18n.infocard.page .. i18n.infocard.info | ||
-- cats | -- cats | ||
Line 98: | Line 114: | ||
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 | ||
-- ---------------------------------------------------------------------------- | |||
-- 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 | return p |
Latest revision as of 15:21, 4 June 2022
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