Module:Experience/Album
Jump to navigation
Jump to search
Module documentation
This documentation is transcluded from Module:Experience/Album/doc. [edit] [history] [purge]
Module:Experience/Album's function main is invoked by Template:Album XP.
Module:Experience/Album's function table is invoked by Template:Album XP/Table.
Module:Experience/Album requires strict.
Module:Experience/Album loads data from Module:Experience/data.
Implements {{Album XP}}
and {{Album XP/Table}}
require('strict')
local data = mw.loadData('Module:Experience/data').album
local lang = mw.language.getContentLanguage()
local p = {}
-- Given a level, returns the album XP (if known).
-- If not known, returns the given "default" argument
function p.main(frame)
local args = frame:getParent().args
if args[1] == nil then
error('{{Album XP}} transcluded without level')
end
local raw = (args[2] or ''):lower() == 'raw'
local level = tonumber(args[1])
local xp = p._main(level)
if xp ~= nil then
if raw then
return tostring(xp)
end
return lang:formatNum(xp)
end
return args.default or ''
end
-- Return the album XP at a given level, or nil if unknown / out of bounds
function p._main(level)
return data[level]
end
-- Returns the table to be shown on [[Album#Experience]]
function p.table()
local out = mw.html.create('table')
:addClass('wikitable align-right-1 align-right-2')
:tag('tr')
:tag('th'):wikitext('Level'):done()
:tag('th'):wikitext('Experience'):done()
:done()
local unknown_xp = mw.html.create('td')
:addClass('table-bg-gray')
:css{ ['text-align'] = 'center' }
:wikitext("''Unknown''")
:done()
for level = 0, 500 do
local row = out:tag('tr')
:tag('td'):wikitext(tostring(level)):done()
if data[level] ~= nil then
row:tag('td'):wikitext(lang:formatNum(data[level])):done()
else
row:node(unknown_xp)
end
end
return out
end
return p