Module:MonsterVariantsTable: Difference between revisions

m
no edit summary
(Created page with "local p = {} function p.main(frame) return p._main(frame:getParent().args) end function p._main(args) local variant = args[1] or args.variant or 'Thug' local query = { string.format('Variant of::%s Has query::+ OR [[Has subobject::<q>Variant of::%s</q>]]', variant, variant), '?Image#64px;x64px=img', '?Has subobject.Image#64px;x64px=img2', '?= page', '?Unlock_level = unlock', '?Has subobject.Unlock_level = u...")
 
mNo edit summary
(3 intermediate revisions by the same user not shown)
Line 1:
local editbutton = require('Module:Edit button')
local p = {}
 
Line 5 ⟶ 6:
end
 
function p._mainformatProfessionLevel(argsprofession, level, high)
profession = profession or 'Unknown profession'
local variant = args[1] or args.variant or 'Thug'
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(args, Avariant)
local variant = args[1] or args.variant or Avariant or 'Thug'
local query = {
string.format('[[Variant of::%s]] [[Has query::+]] OR [[Has subobject::<q>[[Variant of::%s]]</q>]]', variant, variant),
'?Image#64px;x64px=img',
'?Has subobject.Image#64px;x64px=img2',
'?Name=name',
'?= page',
'?Unlock_level = unlock',
Line 16 ⟶ 27:
'?Profession_Level_A = combat',
'?Has subobject.Profession_Level_A = combat2',
'?Profession A #=profession',
'?Has subobject.Profession A #=profession2'
}
 
local results = mw.smw.ask(query)
if results == nil or results[1] == nil then
return ":''No variants found for "..variant.."''"
end
local sorted = p.sort_by_combat(results)
--local debug_str = '<pre>'..mw.text.jsonEncode(sorted, mw.text.JSON_PRETTY)..'</pre>'
return tostring(p.create_table(sorted))--..debug_str
Line 45 ⟶ 63:
:done()
:tag('td')
:wikitext(p.formatProfessionLevel(entry.profession, entry.unlock))
:done()
:tag('td')
:wikitext(p.formatProfessionLevel(entry.profession, entry.combat))
:done()
:done()
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
 
Line 74 ⟶ 98:
for _,entry in ipairs(results) do
local edit = editbutton("'''?''' (edit)", entry.name)
local built_entry = {
combat = entryp.combat or get_entry(entry.combat2[1], or entry.combat2'combat') or ''edit,
img = entryp.get_entry(entry, 'img') or entrymw.img2ustring.format('[1[File:%s.png|64px|x64px] or]', entry.img2 or ''name),
unlock = entryp.unlock or get_entry(entry.unlock2[1], or entry.unlock2'unlock') or ''edit,
profession = p.get_entry(entry, 'profession') or nil,
page = entry.page
}
7,248

edits