Module:SummonableHeroList

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

local heroList = function (args, frame) local WEAPON_SORT = Util.getWeaponSortOrder

-- Cargo Query local heroQueryResult = cargo.query('SummoningAvailability,Units,WeaponTypes', 'Units._pageName=page,WeaponType,Rarity,Color,ColorSort', {		join = 'SummoningAvailability._pageName=Units._pageName,Units.WeaponType=WeaponTypes.WikiName',		where = "IFNULL(Properties__full,'') NOT LIKE '%enemy%' AND Rarity IS NOT NULL AND (NOW BETWEEN StartTime AND EndTime)",		groupBy = 'Units._pageName,Rarity',		limit = 1000,	}) for _, v in ipairs(heroQueryResult) do		v.Rarity = tonumber(v.Rarity) v.ColorSort = tonumber(v.ColorSort) end local heroesByWeapon = List.group_by(heroQueryResult, function (v) return v.WeaponType end) local rmin, rmax = List.minmax(List.map(heroQueryResult, function (v) return v.Rarity end))

-- unit table local tbl = mw.html.create('table'):addClass('wikitable'):addClass('default') :css('text-align', 'center'):css('width', '100%') local row = tbl:tag('tr') row:tag('th'):css('width', '4%'):attr('scope', 'row'):wikitext('Rarity') for r = rmax, rmin, -1 do		row:tag('th'):wikitext(mw.getCurrentFrame:expandTemplate {title = 'Rarity', args = {r}}) end

for wep, vs in Hash.sorted_pairs(heroesByWeapon, function (_, _, k1, k2) return WEAPON_SORT[k1] < WEAPON_SORT[k2] end) do		row = tbl:tag('tr') row:tag('th'):wikitext('') for r = rmax, rmin, -1 do			local heroes = List.select(vs, function (v) return v.Rarity == r end) row:tag('td'):wikitext(table.concat(List.map_self(heroes, function (v) return Util.getHeroIcon(v.page, '40px') end))) end end

-- summary table local heroesByColor = List.group_by(heroQueryResult, function (v) return v.Color end) local summary = mw.html.create('table'):addClass('wikitable'):addClass('default'):css('text-align', 'center') row = summary:tag('tr') row:tag('th'):attr('scope', 'row'):wikitext('Rarity') for r = rmax, rmin, -1 do		row:tag('th'):wikitext(mw.getCurrentFrame:expandTemplate {title = 'Rarity', args = {r}}) end

for col, vs in Hash.sorted_pairs(heroesByColor, function (vs1, vs2) return vs1[1].ColorSort < vs2[1].ColorSort end) do		row = summary:tag('tr') row:tag('th'):wikitext(col) for r = rmax, rmin, -1 do			row:tag('td'):wikitext(List.count_if(vs, function (v) return v.Rarity == r end)) end end

return tostring(tbl) .. ' The above table, in numbers by color only. ' .. tostring(summary) end

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