Editing Module:MonsterVariantsTable

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

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')
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(frame:getParent().args)
return p._main(args[1] or args.variant or '')
end
end


local function formatProfessionLevel(profession, level, high)
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 15:
end
end


function p._main(variant)
function p._main(args, Avariant)
local variant = args[1] or args.variant or Avariant or ''
local results = mw.smw.ask{
local query = {
('[[Variant of::%s]]'):format(variant),
string.format('[[Variant of::%s]] [[Has query::+]] OR [[Has subobject::<q>[[Variant of::%s]]</q>]]', variant, variant),
'?Image#64px;x64px = img',
'?Image#64px;x64px=img',
'?Name = name',
'?Has subobject.Image#64px;x64px=img2',
'?= page',
'?Name=name',
'?Unlock_level = unlock_lvl',
'?= page',
'?Unlock profession # = unlock_profession',
'?Unlock_level = unlock',
'?Profession_Level_A = combat',
'?Has subobject.Unlock_level = unlock2',
'?Profession A # = profession',
'?Profession_Level_A = combat',
'?Version default = default',
'?Has subobject.Profession_Level_A = combat2',
'?Variant name = variant',
'?Profession A #=profession',
'?Version anchor = version',
'?-Version subobject#- = superobject',
'?Has subobject.Profession A #=profession2'
}
'sort=Profession Level A',

'order=asc'
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 filtered = p.filter_versions(results)
local sorted = p.sort_by_combat(results)
--local debug_str = '<pre>'..mw.text.jsonEncode(sorted, mw.text.JSON_PRETTY)..'</pre>'
local sorted = p.sort_by_combat(filtered)

return p.create_table(sorted)
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.superobject, entry.name)
table.insert(filtered, entry)
elseif entry.version == nil then
table.insert(filtered, entry)
end
end
return filtered
end
end


function p.sort_by_combat(data)
function p.sort_by_combat(data)
table.sort(data, function(a, b)
table.sort(data, function(a, b)
-- Determine combat values
-- Determine combat values
local combatA = a.combat or a.unlock_lvl or math.huge
local combatA = a.combat or (a.combat2 and a.combat2[1]) or math.huge
local combatB = b.combat or b.unlock_lvl or math.huge
local combatB = b.combat or (b.combat2 and b.combat2[1]) or math.huge
-- Sort in ascending order
-- Sort in ascending order
return combatA < combatB
return combatA < combatB
end)
end)
return data
return data
end
end


function p.insert_row(tbl, entry)
function p.insert_row(tbl, entry)
tbl:tag('tr')
local edit = editbutton("'''?''' (edit)", entry.name)
tbl:tr()
:tag('td')
:wikitext(entry.img)
: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()
:done()
:td()
:tag('td')
:wikitext(entry.combat and formatProfessionLevel(entry.profession, entry.combat) or edit)
:wikitext(entry.page)
:done()
:tag('td')
:wikitext(p.formatProfessionLevel(entry.profession, entry.unlock))
:done()
:tag('td')
:wikitext(p.formatProfessionLevel(entry.profession, entry.combat))
:done()
:done()
:done()
:done()

return tbl
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
end


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 align-right-3 align-right-4')
:addClass('wikitable sortable')
:tr()
:tag('tr')
:tag('th')
:th{ 'Monster', attr = { colspan = 2 } }:done()
:th('Unlocked at'):done()
:wikitext('Image')
:th('Combat level'):done()
: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)
local edit = editbutton("'''?''' (edit)", 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
end

return out
return out
end
end
Please note that all contributions to Brighter Shores Wiki are considered to be released under the CC BY-NC-SA 3.0 (see Brighter Shores:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template

This page is a member of a hidden category: