Module:MonsterVariantsTable: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
Californ1a (talk | contribs) mNo edit summary |
Californ1a (talk | contribs) m (cleanup) |
||
Line 15: | Line 15: | ||
end |
end |
||
function p._main(args |
function p._main(args) |
||
local variant = args[1] or args.variant |
local variant = args[1] or args.variant or '' |
||
local query = { |
local query = { |
||
string.format('[[Variant of::%s |
string.format('[[Variant of::%s]]', variant), |
||
'?Image#64px;x64px=img', |
'?Image#64px;x64px = img', |
||
'? |
'?Name = name', |
||
⚫ | |||
'?= page', |
'?= page', |
||
'?Unlock_level = unlock', |
'?Unlock_level = unlock', |
||
⚫ | |||
'?Profession_Level_A = combat', |
'?Profession_Level_A = combat', |
||
'? |
'?Profession A # = profession', |
||
'? |
'?Version default = default', |
||
'? |
'?Variant name = variant', |
||
'?Version anchor = version', |
|||
⚫ | |||
'sort=Profession Level A', |
|||
⚫ | |||
} |
} |
||
local results = mw.smw.ask(query) |
local results = mw.smw.ask(query) |
||
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 |
local filtered = p.filter_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)) |
return tostring(p.create_table(sorted)) |
||
⚫ | |||
function p.filter_versions(data) |
|||
⚫ | |||
for _,entry in ipairs(data) do |
|||
if entry.default == true 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 |
end |
||
Line 46: | Line 61: | ||
table.sort(data, function(a, b) |
table.sort(data, function(a, b) |
||
-- Determine combat values |
-- Determine combat values |
||
local combatA = a.combat or |
local combatA = a.combat or a.unlock or math.huge |
||
local combatB = b.combat or |
local combatB = b.combat or b.unlock or math.huge |
||
-- Sort in ascending order |
-- Sort in ascending order |
||
return combatA < combatB |
return combatA < combatB |
||
Line 55: | Line 70: | ||
function p.insert_row(tbl, entry) |
function p.insert_row(tbl, entry) |
||
local edit = editbutton("'''?''' (edit)", entry.name) |
|||
tbl:tag('tr') |
tbl:tag('tr') |
||
:tag('td') |
:tag('td') |
||
Line 63: | Line 79: | ||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
||
:wikitext(p.formatProfessionLevel(entry.profession, entry.unlock)) |
:wikitext(entry.unlock and p.formatProfessionLevel(entry.profession, entry.unlock) or edit) |
||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
||
:wikitext(p.formatProfessionLevel(entry.profession, entry.combat)) |
:wikitext(entry.combat and p.formatProfessionLevel(entry.profession, entry.combat) or edit) |
||
:done() |
:done() |
||
:done() |
:done() |
||
return tbl |
return tbl |
||
⚫ | |||
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 |
end |
||
Line 98: | Line 108: | ||
for _,entry in ipairs(results) do |
for _,entry in ipairs(results) do |
||
out = p.insert_row(out, 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 |
end |
||