Module:Experience/table: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(Created page with "require('strict') require('Module:Mw.html extension') local data = mw.loadData('Module:Experience/data') local yesno = require('Module:Yesno') local lang = mw.language.getContentLanguage() local p = {} function p.main(frame) local args = frame:getParent().args local default_collapsed = yesno(args.collapsed) local collapsed = {} for _, label in ipairs(data.labels) do local this_collapsed = yesno(template_args['collapsed-' .. label.name:tolower()]) if this_colla...") |
mNo edit summary |
||
Line 13:
for _, label in ipairs(data.labels) do
local this_collapsed = yesno(
if this_collapsed == nil then
this_collapsed = default_collapsed
|
Revision as of 08:47, 27 November 2024
Module documentation
This documentation is transcluded from Module:Experience/table/doc. [edit] [history] [purge]
Module:Experience/table's function main is invoked by Template:Experience table.
Module:Experience/table requires Module:Mw.html extension.
Module:Experience/table requires Module:Yesno.
Module:Experience/table requires strict.
Module:Experience/table loads data from Module:Experience/data.
Implements {{Experience table}}
. See there for documentation.
require('strict')
require('Module:Mw.html extension')
local data = mw.loadData('Module:Experience/data')
local yesno = require('Module:Yesno')
local lang = mw.language.getContentLanguage()
local p = {}
function p.main(frame)
local args = frame:getParent().args
local default_collapsed = yesno(args.collapsed)
local collapsed = {}
for _, label in ipairs(data.labels) do
local this_collapsed = yesno(args['collapsed-' .. label.name:tolower()])
if this_collapsed == nil then
this_collapsed = default_collapsed
end
collapsed[label.name] = this_collapsed
end
return p._main{ collapsed = collapsed }
end
--[[
Creates tables of expreience for {{Experience table}}
args.collapsed = { Novice = boolean, Apprentice = boolean, ... }: Whether the
corresponding table should automatically be collapsed
]]
function p._main(args)
args = args or {}
local collapsed = args.collapsed or {}
local result = {}
for _, label in ipairs(data.labels) do
local t = mw.html.create('table')
:addClass('wikitable mw-collapsible')
:addClass(collapsed[label.name] and 'mw-collapsed' or nil)
:tag('caption')
:wikitext(('%s (%s-%s)'):format(label.name, label.min, label.max))
:done()
:tag('tr')
:tag('th')
:wikitext('Level')
:done()
:tag('th')
:wikitext('Experience')
:done()
:tag('th')
:wikitext('XP to next level')
:done()
:IF(label.knowledge)
:tag('th')
:wikitext('Knowledge XP')
:done()
:END()
:done()
for level = label.min, label.max do
local next_level_node
if data.level[level+1] then
next_level_node = mw.html.create('td')
:wikitext(lang:formatNum(data.level[level+1] - data.level[level]))
:done()
else
-- Max level
next_level_node = mw.html.create('td')
:addClass('table-na')
:wikitext('N/A')
:done()
end
t:tag('tr')
:tag('td')
:wikitext(level)
:done()
:tag('td')
:wikitext(data.level[level])
:done()
:node(next_level_node)
:IF(label.knowledge)
:tag('td')
:wikitext(lang:formatNum(data.knowledge[level] or 0))
:done()
:END()
:done()
end
table.insert(result, tostring(t))
end
return table.concat(result, '')
end
return p