Editing Module:MonsterVariantsTable
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
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 5: | Line 4: | ||
function p.main(frame) |
function p.main(frame) |
||
return p._main(frame:getParent().args) |
|||
return p._main(args[1] or args.variant or '') |
|||
end |
end |
||
function p.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 18: | Line 16: | ||
end |
end |
||
function p._main( |
function p._main(args) |
||
local |
local variant = args[1] or args.variant or '' |
||
local query = { |
|||
string.format('[[Variant of::%s]]', variant), |
|||
'?Image#64px;x64px = img', |
|||
'?Name = name', |
|||
'?Name = name', |
|||
'?= page', |
|||
'?Unlock_level = unlock_lvl', |
|||
'?Unlock profession # = unlock_profession', |
|||
'?Profession_Level_A = combat', |
|||
'?Profession A # = profession', |
|||
'?Version default = default', |
|||
'?Version default = default', |
|||
'?Variant name = variant', |
|||
'?Version anchor = version', |
|||
'?-Has subobject#- = subobject', |
|||
'sort=Profession Level A', |
|||
'order=asc' |
|||
⚫ | |||
} |
|||
⚫ | |||
⚫ | |||
local results = mw.smw.ask(query) |
|||
⚫ | |||
⚫ | |||
return ":''No variants found for "..variant.."''" |
return ":''No variants found for "..variant.."''" |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
function p.filter_versions(data) |
function p.filter_versions(data) |
||
local filtered = {} |
local filtered = {} |
||
for _, |
for _,entry in ipairs(data) do |
||
if entry.default then |
if entry.default == true then |
||
entry.page = ('[[%s|%s]]'):format(entry. |
entry.page = ('[[%s|%s]]'):format(entry.subobject, entry.name) |
||
table.insert(filtered, entry) |
table.insert(filtered, entry) |
||
elseif entry.version == nil then |
elseif entry.version == nil then |
||
Line 60: | Line 61: | ||
function p.sort_by_combat(data) |
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 |
end |
||
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:tag('tr') |
||
:tag('td') |
|||
:td{ entry.img, addClass = 'plinkt-image no-border' }:done() |
|||
:wikitext(entry.img) |
|||
:td{ entry.page, addClass = 'plinkt-link no-border' }:done() |
|||
: |
:done() |
||
:tag('td') |
|||
⚫ | |||
:wikitext(entry.page) |
|||
⚫ | |||
:done() |
|||
:tag('td') |
|||
⚫ | |||
:addClass('table-na') |
:addClass('table-na') |
||
:wikitext('N/A') |
:wikitext('N/A') |
||
:ELSE() |
|||
⚫ | |||
:END() |
:END() |
||
:done() |
:done() |
||
: |
:tag('td') |
||
:wikitext(entry.combat and formatProfessionLevel(entry.profession, entry.combat) or edit) |
:wikitext(entry.combat and p.formatProfessionLevel(entry.profession, entry.combat) or edit) |
||
:done() |
:done() |
||
:done() |
:done() |
||
⚫ | |||
return tbl |
return tbl |
||
end |
end |
||
Line 93: | Line 98: | ||
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') |
||
: |
:tag('tr') |
||
:tag('th') |
|||
:th{ 'Monster', attr = { colspan = 2 } }:done() |
|||
: |
:wikitext('Image') |
||
:done() |
|||
:tag('th') |
|||
:wikitext('Monster') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Unlocked at') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Combat level') |
|||
:done() |
|||
:done() |
:done() |
||
for _, |
for _,entry in ipairs(results) do |
||
out = p.insert_row(out, entry) |
out = p.insert_row(out, entry) |
||
end |
end |
||
return out |
return out |
||
end |
end |