Module:MonsterVariantsTable: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
Californ1a (talk | contribs) m (separate unlock profession) |
(Fix unlock_level logic for when it's N/A. Use plinkt styling. Align levels to the right.) |
||
Line 1: | Line 1: | ||
require('strict') |
|||
require('Module:Mw.html extension') |
require('Module:Mw.html extension') |
||
local editbutton = require('Module:Edit button') |
local editbutton = require('Module:Edit button') |
||
Line 4: | Line 5: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = frame:getParent().args |
|||
⚫ | |||
end |
end |
||
function |
local function formatProfessionLevel(profession, level, high) |
||
profession = profession or 'Unknown profession' |
profession = profession or 'Unknown profession' |
||
local level_text = tostring(level or '?') |
local level_text = tostring(level or '?') |
||
Line 16: | Line 18: | ||
end |
end |
||
function p._main( |
function p._main(variant) |
||
⚫ | |||
⚫ | |||
⚫ | |||
local query = { |
|||
⚫ | |||
'?Image#64px;x64px = img', |
'?Image#64px;x64px = img', |
||
'?Name = name', |
'?Name = name', |
||
Line 34: | Line 35: | ||
'order=asc' |
'order=asc' |
||
} |
} |
||
⚫ | |||
mw.logObject(results) |
mw.logObject(results) |
||
if results == nil or results[1] == nil then |
if results == nil or results[1] == nil then |
||
return ":''No variants found for "..variant.."''" |
return ":''No variants found for "..variant.."''" |
||
end |
end |
||
local filtered = p.filter_versions(results) |
local filtered = p.filter_versions(results) |
||
local sorted = p.sort_by_combat(filtered) |
local sorted = p.sort_by_combat(filtered) |
||
return |
return p.create_table(sorted) |
||
end |
end |
||
function p.filter_versions(data) |
function p.filter_versions(data) |
||
local filtered = {} |
local filtered = {} |
||
for _,entry in ipairs(data) do |
for _, entry in ipairs(data) do |
||
if entry.default |
if entry.default then |
||
entry.page = ('[[%s|%s]]'):format(entry.subobject, entry.name) |
entry.page = ('[[%s|%s]]'):format(entry.subobject, entry.name) |
||
table.insert(filtered, entry) |
table.insert(filtered, entry) |
||
Line 73: | Line 72: | ||
function p.insert_row(tbl, entry) |
function p.insert_row(tbl, entry) |
||
local edit = editbutton("'''?''' (edit)", entry.name) |
local edit = editbutton("'''?''' (edit)", entry.name) |
||
tbl: |
tbl:tr() |
||
:td{ entry.img, addClass = 'plinkt-image' }:done() |
|||
:tag('td') |
|||
:td{ entry.page, addClass = 'plinkt-link' }:done() |
|||
:wikitext(entry.img) |
|||
: |
:td() |
||
⚫ | |||
:tag('td') |
|||
⚫ | |||
:wikitext(entry.page) |
|||
: |
:ELSE() |
||
:tag('td') |
|||
⚫ | |||
:addClass('table-na') |
:addClass('table-na') |
||
:wikitext('N/A') |
:wikitext('N/A') |
||
:ELSE() |
|||
⚫ | |||
:END() |
:END() |
||
:done() |
:done() |
||
: |
:td() |
||
:wikitext(entry.combat and |
:wikitext(entry.combat and formatProfessionLevel(entry.profession, entry.combat) or edit) |
||
:done() |
:done() |
||
:done() |
:done() |
||
Line 98: | Line 93: | ||
function p.create_table(results) |
function p.create_table(results) |
||
local out = mw.html.create('table') |
local out = mw.html.create('table') |
||
:addClass('wikitable sortable') |
:addClass('wikitable sortable align-right-3 align-right-4') |
||
: |
:tr() |
||
:th{ 'Monster', attr = { colspan = 2 } }:done() |
|||
:tag('th') |
|||
:th('Unlocked at'):done() |
|||
:done() |
:th('Combat level'):done() |
||
:tag('th') |
|||
:wikitext('Monster') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Unlocked at') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Combat level') |
|||
:done() |
|||
:done() |
:done() |
||
for _,entry in ipairs(results) do |
for _, entry in ipairs(results) do |
||
out = p.insert_row(out, entry) |
out = p.insert_row(out, entry) |
||
end |
end |