Module:MonsterVariantsTable: Difference between revisions

Fix unlock_level logic for when it's N/A. Use plinkt styling. Align levels to the right.
m (separate unlock profession)
(Fix unlock_level logic for when it's N/A. Use plinkt styling. Align levels to the right.)
Line 1:
require('strict')
require('Module:Mw.html extension')
local editbutton = require('Module:Edit button')
Line 4 ⟶ 5:
 
function p.main(frame)
returnlocal args = p._main(frame:getParent().args)
local variant =return p._main(args[1] or args.variant or '')
end
 
local function p.formatProfessionLevel(profession, level, high)
profession = profession or 'Unknown profession'
local level_text = tostring(level or '?')
Line 16 ⟶ 18:
end
 
function p._main(argsvariant)
local results = mw.smw.ask(query){
local variant = args[1] or args.variant or ''
string.format('[[Variant of::%s]]', ):format(variant),
local query = {
string.format('[[Variant of::%s]]', variant),
'?Image#64px;x64px = img',
'?Name = name',
Line 34 ⟶ 35:
'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)
Line 73 ⟶ 72:
function p.insert_row(tbl, entry)
local edit = editbutton("'''?''' (edit)", entry.name)
tbl:tag('tr'()
:td{ entry.img, addClass = 'plinkt-image' }:done()
:tag('td')
:td{ entry.page, addClass = 'plinkt-link' }:done()
:wikitext(entry.img)
:donetd()
:IF(entry.unlock_lvl == 'N/A'unlock_profession)
:tag('td')
:wikitext(entry.unlock_lvl and p.formatProfessionLevel(entry.unlock_profession, entry.unlock_lvl) or edit)
:wikitext(entry.page)
:doneELSE()
: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()
Line 98 ⟶ 93:
function p.create_table(results)
local out = mw.html.create('table')
:addClass('wikitable sortable align-right-3 align-right-4')
:tag('tr'()
:th{ 'Monster', attr = { colspan = 2 } }:done()
:tag('th')
:wikitextth('ImageUnlocked at'):done()
:th('Combat level'):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
1,483

edits