Module:MonsterVariantsTable: Difference between revisions

Remove border between image and name
m (cleanup)
(Remove border between image and name)
(3 intermediate revisions by 2 users not shown)
Line 1:
require('strict')
require('Module:Mw.html extension')
local editbutton = require('Module:Edit button')
local p = {}
 
function p.main(frame)
returnlocal args = p._main(frame:getParent().args)
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 15 ⟶ 18:
end
 
function p._main(argsvariant)
local variantresults = args[1] or argsmw.variant or ''smw.ask{
string.format ('[[Variant of::%s]]', ):format(variant),
local query = {
'?Image#64px;x64px = img',
string.format('[[Variant of::%s]]', variant),
'?Name = name',
'?Image#64px;x64px = img',
'?Name = namepage',
'?Unlock_level = unlockunlock_lvl',
'?= page',
'?Unlock profession # = unlock_profession',
'?Unlock_level = unlock',
'?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'
}
}
mw.logObject(results)
 
if results == nil localor results[1] == nil mw.smw.ask(query)then
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)
 
local filtered = p.filter_versions(results)
return tostring(p.create_table(sorted))
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 59 ⟶ 60:
 
function p.sort_by_combat(data)
table.sort(data, function(a, b)
-- Determine combat values
local combatA = a.combat or a.unlockunlock_lvl or math.huge
local combatB = b.combat or b.unlockunlock_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'()
:td{ entry.img, addClass = 'plinkt-image no-border' }:done()
:tag('td')
:td{ entry.page, addClass = 'plinkt-link no-border' }:done()
:wikitext(entry.img)
:tag('td'()
:IF(entry.unlock_profession)
:wikitext(entry.unlockunlock_lvl and p.formatProfessionLevel(entry.professionunlock_profession, entry.unlockunlock_lvl) or edit)
:doneELSE()
:addClass('table-na')
:wikitext(entry.img'N/A')
:doneEND()
:done()
:tag('td'()
:wikitext(entry.pagecombat and formatProfessionLevel(entry.profession, entry.combat) or edit)
:done()
:tag('td')
:wikitext(entry.unlock and p.formatProfessionLevel(entry.profession, entry.unlock) or edit)
:done()
:tag('td')
:wikitext(entry.combat and p.formatProfessionLevel(entry.profession, entry.combat) or edit)
:done()
:done()
 
return tbl
end
Line 91 ⟶ 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
 
return out
end
1,483

edits