Module:MonsterVariantsTable: Difference between revisions

Remove border between image and name
mNo edit summary
(Remove border between image and name)
(4 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(args, Avariantvariant)
local results = mw.smw.ask{
local variant = args[1] or args.variant or Avariant or ''
('[[Variant of::%s]]'):format(variant),
local query = {
'?Image#64px;x64px = img',
string.format('[[Variant of::%s]] [[Has query::+]] OR [[Has subobject::<q>[[Variant of::%s]]</q>]]', variant, variant),
'?Name = name',
'?Image#64px;x64px=img',
'?= page',
'?Has subobject.Image#64px;x64px=img2',
'?Unlock_level = unlock_lvl',
'?Name=name',
'?Unlock profession # = unlock_profession',
'?= page',
'?Profession_Level_A = combat',
'?Unlock_level = unlock',
'?Profession A # = profession',
'?Has subobject.Unlock_level = unlock2',
'?Version default = default',
'?Profession_Level_A = combat',
'?Variant name = variant',
'?Has subobject.Profession_Level_A = combat2',
'?Version anchor = version',
'?Profession A #=profession',
'?-Has subobject.Profession#- A= #=profession2subobject',
'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 sortedfiltered = p.sort_by_combatfilter_versions(results)
local sorted = p.sort_by_combat(filtered)
--local debug_str = '<pre>'..mw.text.jsonEncode(sorted, mw.text.JSON_PRETTY)..'</pre>'
 
return tostring(p.create_table(sorted))--..debug_str
end
 
function p.filter_versions(data)
local filtered = {}
for _, entry in ipairs(data) do
if entry.default 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.combat2 and a.combat2[1])unlock_lvl or math.huge
local combatB = b.combat or (b.combat2 and b.combat2[1])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')
tbl:tagtr('td')
:td{ entry.img, addClass = 'plinkt-image no-border' }:done()
:wikitext(entry.img)
:td{ entry.page, addClass = 'plinkt-link no-border' }:done()
:td()
:IF(entry.unlock_profession)
:wikitext(entry.unlock_lvl and formatProfessionLevel(entry.unlock_profession, entry.unlock_lvl) or edit)
:ELSE()
:addClass('table-na')
:wikitext('N/A')
:END()
:done()
:tag('td'()
:wikitext(entry.pagecombat and formatProfessionLevel(entry.profession, entry.combat) or edit)
:done()
:tag('td')
:wikitext(p.formatProfessionLevel(entry.profession, entry.unlock))
:done()
:tag('td')
:wikitext(p.formatProfessionLevel(entry.profession, entry.combat))
:done()
:done()
 
return tbl
end
 
function p.get_entry(entry, param)
return entry[param]
or (type(entry[param..'2']) == 'table' and entry[param..'2'][1])
or (type(entry[param..'2']) == 'string' and entry[param..'2'])
end
 
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
local editout = editbuttonp.insert_row("'''?''' (edit)"out, entry.name)
local built_entry = {
combat = p.get_entry(entry, 'combat') or edit,
img = p.get_entry(entry, 'img') or mw.ustring.format('[[File:%s.png|64px|x64px]]', entry.name),
unlock = p.get_entry(entry, 'unlock') or edit,
profession = p.get_entry(entry, 'profession') or nil,
page = entry.page
}
out = p.insert_row(out, built_entry)
end
 
return out
end
1,483

edits