Module:MonsterVariantsTable: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
Californ1a (talk | contribs) m (cleanup) |
(look only for version type subobjects, not all subobjects, when filtering) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
require('strict') |
|||
require('Module:Mw.html extension') |
|||
local editbutton = require('Module:Edit button') |
local editbutton = require('Module:Edit button') |
||
local p = {} |
local p = {} |
||
function p.main(frame) |
function p.main(frame) |
||
local args = frame:getParent().args |
|||
return p._main(args[1] or args.variant or '') |
|||
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 15: | Line 18: | ||
end |
end |
||
function p._main( |
function p._main(variant) |
||
local |
local results = mw.smw.ask{ |
||
⚫ | |||
local query = { |
|||
⚫ | |||
⚫ | |||
'?Name = name', |
|||
⚫ | |||
'?= page', |
|||
⚫ | |||
'?= page', |
|||
'?Unlock profession # = unlock_profession', |
|||
⚫ | |||
'?Profession_Level_A = combat', |
|||
'?Profession A # = profession', |
|||
'?Version default = default', |
|||
'?Variant name = variant', |
|||
'?Version anchor = version', |
|||
'?-Version subobject#- = superobject', |
|||
'sort=Profession Level A', |
|||
'order=asc' |
|||
⚫ | |||
} |
|||
⚫ | |||
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 |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
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. |
entry.page = ('[[%s|%s]]'):format(entry.superobject, entry.name) |
||
table.insert(filtered, entry) |
table.insert(filtered, entry) |
||
elseif entry.version == nil then |
elseif entry.version == nil then |
||
Line 59: | Line 60: | ||
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:tr() |
||
:td{ entry.img, addClass = 'plinkt-image no-border' }:done() |
|||
⚫ | |||
:td{ entry.page, addClass = 'plinkt-link no-border' }:done() |
|||
⚫ | |||
⚫ | |||
:IF(entry.unlock_profession) |
|||
⚫ | |||
⚫ | |||
:addClass('table-na') |
|||
⚫ | |||
⚫ | |||
:done() |
:done() |
||
: |
:td() |
||
:wikitext(entry. |
:wikitext(entry.combat and formatProfessionLevel(entry.profession, entry.combat) or edit) |
||
:done() |
|||
:tag('td') |
|||
⚫ | |||
:done() |
|||
:tag('td') |
|||
:wikitext(entry.combat and p.formatProfessionLevel(entry.profession, entry.combat) or edit) |
|||
:done() |
:done() |
||
:done() |
:done() |
||
⚫ | |||
return tbl |
return tbl |
||
end |
end |
||
Line 91: | 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') |
|||
⚫ | |||
:tag('th') |
|||
:wikitext('Unlocked at') |
|||
⚫ | |||
: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 |
||
return out |
return out |
||
end |
end |
Latest revision as of 13:31, 7 January 2025
Module documentation
This documentation is transcluded from Module:MonsterVariantsTable/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:MonsterVariantsTable/doc. [edit]
Module:MonsterVariantsTable's function main is invoked by Template:MonsterVariantsTable.
Module:MonsterVariantsTable requires Module:Edit button.
Module:MonsterVariantsTable requires Module:Mw.html extension.
Module:MonsterVariantsTable requires strict.
require('strict')
require('Module:Mw.html extension')
local editbutton = require('Module:Edit button')
local p = {}
function p.main(frame)
local args = frame:getParent().args
return p._main(args[1] or args.variant or '')
end
local function formatProfessionLevel(profession, level, high)
profession = profession or 'Unknown profession'
local level_text = tostring(level or '?')
if high then
level_text = ('%s➨%d'):format(level_text, high)
end
return ('%s [[File:%s small icon.png|21x21px|link=%s]]'):format(level_text, profession, profession)
end
function p._main(variant)
local results = mw.smw.ask{
('[[Variant of::%s]]'):format(variant),
'?Image#64px;x64px = img',
'?Name = name',
'?= page',
'?Unlock_level = unlock_lvl',
'?Unlock profession # = unlock_profession',
'?Profession_Level_A = combat',
'?Profession A # = profession',
'?Version default = default',
'?Variant name = variant',
'?Version anchor = version',
'?-Version subobject#- = superobject',
'sort=Profession Level A',
'order=asc'
}
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)
return p.create_table(sorted)
end
function p.filter_versions(data)
local filtered = {}
for _, entry in ipairs(data) do
if entry.default then
entry.page = ('[[%s|%s]]'):format(entry.superobject, 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.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
function p.insert_row(tbl, entry)
local edit = editbutton("'''?''' (edit)", entry.name)
tbl:tr()
:td{ entry.img, addClass = 'plinkt-image no-border' }:done()
: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()
:td()
:wikitext(entry.combat and formatProfessionLevel(entry.profession, entry.combat) or edit)
:done()
:done()
return tbl
end
function p.create_table(results)
local out = mw.html.create('table')
:addClass('wikitable sortable align-right-3 align-right-4')
:tr()
:th{ 'Monster', attr = { colspan = 2 } }:done()
:th('Unlocked at'):done()
:th('Combat level'):done()
:done()
for _, entry in ipairs(results) do
out = p.insert_row(out, entry)
end
return out
end
return p