Module:MonsterVariantsTable: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
Californ1a (talk | contribs) m (cleanup) |
Californ1a (talk | contribs) m (separate unlock profession) |
||
Line 1: | Line 1: | ||
require('Module:Mw.html extension') |
|||
local editbutton = require('Module:Edit button') |
local editbutton = require('Module:Edit button') |
||
local p = {} |
local p = {} |
||
Line 22: | Line 23: | ||
'?Name = name', |
'?Name = name', |
||
'?= page', |
'?= page', |
||
'?Unlock_level = |
'?Unlock_level = unlock_lvl', |
||
'?Unlock profession # = unlock_profession', |
|||
'?Profession_Level_A = combat', |
'?Profession_Level_A = combat', |
||
'?Profession A # = profession', |
'?Profession A # = profession', |
||
Line 61: | Line 63: | ||
table.sort(data, function(a, b) |
table.sort(data, function(a, b) |
||
-- Determine combat values |
-- Determine combat values |
||
local combatA = a.combat or a. |
local combatA = a.combat or a.unlock_lvl or math.huge |
||
local combatB = b.combat or b. |
local combatB = b.combat or b.unlock_lvl or math.huge |
||
-- Sort in ascending order |
-- Sort in ascending order |
||
return combatA < combatB |
return combatA < combatB |
||
Line 79: | Line 81: | ||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
||
:IF(entry.unlock_lvl == 'N/A') |
|||
⚫ | |||
:addClass('table-na') |
|||
:wikitext('N/A') |
|||
:ELSE() |
|||
⚫ | |||
:END() |
|||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
Revision as of 20:48, 2 January 2025
Module documentation
This documentation is transcluded from Module:MonsterVariantsTable/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:MonsterVariantsTable/doc. [edit]
Module:MonsterVariantsTable's function main is invoked by Template:MonsterVariantsTable.
Module:MonsterVariantsTable requires Module:Edit button.
Module:MonsterVariantsTable requires Module:Mw.html extension.
require('Module:Mw.html extension')
local editbutton = require('Module:Edit button')
local p = {}
function p.main(frame)
return p._main(frame:getParent().args)
end
function p.formatProfessionLevel(profession, level, high)
profession = profession or 'Unknown profession'
local level_text = tostring(level or '?')
if high then
level_text = ('%s➨%d'):format(level_text, high)
end
return ('%s [[File:%s small icon.png|21x21px|link=%s]]'):format(level_text, profession, profession)
end
function p._main(args)
local variant = args[1] or args.variant or ''
local query = {
string.format('[[Variant of::%s]]', variant),
'?Image#64px;x64px = img',
'?Name = name',
'?= page',
'?Unlock_level = unlock_lvl',
'?Unlock profession # = unlock_profession',
'?Profession_Level_A = combat',
'?Profession A # = profession',
'?Version default = default',
'?Variant name = variant',
'?Version anchor = version',
'?-Has subobject#- = subobject',
'sort=Profession Level A',
'order=asc'
}
local results = mw.smw.ask(query)
mw.logObject(results)
if results == nil or results[1] == nil then
return ":''No variants found for "..variant.."''"
end
local filtered = p.filter_versions(results)
local sorted = p.sort_by_combat(filtered)
return tostring(p.create_table(sorted))
end
function p.filter_versions(data)
local filtered = {}
for _,entry in ipairs(data) do
if entry.default == true then
entry.page = ('[[%s|%s]]'):format(entry.subobject, entry.name)
table.insert(filtered, entry)
elseif entry.version == nil then
table.insert(filtered, entry)
end
end
return filtered
end
function p.sort_by_combat(data)
table.sort(data, function(a, b)
-- Determine combat values
local combatA = a.combat or a.unlock_lvl or math.huge
local combatB = b.combat or b.unlock_lvl or math.huge
-- Sort in ascending order
return combatA < combatB
end)
return data
end
function p.insert_row(tbl, entry)
local edit = editbutton("'''?''' (edit)", entry.name)
tbl:tag('tr')
:tag('td')
:wikitext(entry.img)
:done()
:tag('td')
:wikitext(entry.page)
:done()
:tag('td')
:IF(entry.unlock_lvl == 'N/A')
:addClass('table-na')
:wikitext('N/A')
:ELSE()
:wikitext(entry.unlock_lvl and p.formatProfessionLevel(entry.unlock_profession, entry.unlock_lvl) or edit)
:END()
:done()
:tag('td')
:wikitext(entry.combat and p.formatProfessionLevel(entry.profession, entry.combat) or edit)
:done()
:done()
return tbl
end
function p.create_table(results)
local out = mw.html.create('table')
:addClass('wikitable sortable')
:tag('tr')
:tag('th')
:wikitext('Image')
:done()
:tag('th')
:wikitext('Monster')
:done()
:tag('th')
:wikitext('Unlocked at')
:done()
:tag('th')
:wikitext('Combat level')
:done()
:done()
for _,entry in ipairs(results) do
out = p.insert_row(out, entry)
end
return out
end
return p