Module:PassivesTable/sandbox

local cargo = mw.ext.cargo local Util = require 'Module:Util' local List = require 'Module:ListUtil' local Hash = require 'Module:HashUtil' local escq = require 'Module:EscQ'.main1

local collectArgs = function (cat, args) local entries = {} for level = 1, math.huge do		local namekey = ('passive%s%d'):format(cat, level) local name = args[namekey] local unlock = args[namekey .. 'Unlock'] if not Util.isNilOrEmpty(name) then entries[#entries + 1] = {name = name, unlock = unlock} elseif Util.isNilOrEmpty(unlock) then break end end return entries end

local CATEGORIES = {'A', 'B', 'C'}

local passivesList = function (args, frame) local cat_entries = Hash.generate(CATEGORIES, function (cat) return collectArgs(cat, args) end) local all_entries = List.reduce(Hash.values(cat_entries), List.concat_self, {}) if #all_entries == 0 then return ' This hero owns no Passive skills. '	end

local skillQuery = Hash.from_ipairs(cargo.query('Skills', '_pageName=page,Name=name,Description=desc,SP=cost,Icon=icon', { where = ("Name IN (%s)"):format(table.concat(List.map(all_entries, function (v) return ("'%s'"):format(escq(v.name)) end), ',')), groupBy = 'Name', limit = 100, }), function (v) return v.name, v end)

local RARITY_TXT = Util.getRarityTexts

local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default'):addClass('skills-table'):css('text-align', 'center') tbl:tag('th'):css('width', '30px'):wikitext('Type') tbl:tag('th'):css('width', '40px') tbl:tag('th'):css('width', '120px'):wikitext('Name') tbl:tag('th'):wikitext('Description') tbl:tag('th'):css('width', '50px'):wikitext('SP') tbl:tag('th'):css('width', '50px'):wikitext(frame:expandTemplate {title = 'Hover', args = {'Unlock',		'Skills are listed at the lowest rarity they can be learned at, regardless of whether or not the Hero can be obtained at that rarity.'}})

for cat, entries in Hash.sorted_pairs(cat_entries) do		for level, v in ipairs(entries) do			local skill = skillQuery[v.name] local tr = tbl:tag('tr') if level == 1 then tr:tag('th'):attr('scope', 'rowgroup'):attr('rowspan', #entries):wikitext(cat) end tr:tag('td'):wikitext((''):format(skill and skill.icon or 'Passive_No_Image.png')) tr:tag('td'):wikitext(skill and ('%s'):format(skill.page, v.name) or ('%s'):format(v.name)) tr:tag('td'):wikitext(skill and skill.desc or '?') tr:tag('td'):wikitext(skill and (skill.cost == '0' and '—' or skill.cost) or '?') tr:tag('td'):wikitext(RARITY_TXT[tonumber(v.unlock)] or '?') end end

return tostring(tbl) end

return require 'Module:MakeMWModule'.makeMWModule {passivesList = passivesList}