Module:HeroListByAvailability

local p = {} local cargo = mw.ext.cargo local Util = require 'Module:Util' local Hash = require 'Module:HashUtil' local List = require 'Module:ListUtil' local HeroUtil = require 'Module:HeroUtil'

local ROWS = (function 	local RARITY_TXTS = Util.getRarityTexts	local r3 = RARITY_TXTS[3]	local r4 = RARITY_TXTS[4]	local r5 = RARITY_TXTS[5]	return {		{r5, 'Regular summoning pool', function (u) return List.equal(u.avail.nonfocus, {5}) and not u.properties.revivalOnly end},		{r5, 'Revival-only summoning pool', function (u) return List.equal(u.avail.nonfocus, {5}) and u.properties.revivalOnly end},		{r4 .. ' – ' .. r5, 'Regular summoning pool', function (u) return List.equal(u.avail.nonfocus, {4, 5}) end},		{r3 .. ' – ' .. r4, 'Regular summoning pool', function (u) return List.equal(u.avail.nonfocus, {3, 4}) end},		{r3 .. ' – ' .. r4, 'GHB', function (u) return u.properties.ghb end},		{r4 .. ' – ' .. r5, 'TT', function (u) return u.properties.tempest end},		{r5, 'Special', function (u) return u.properties.special and List.equal(u.avail.focus, {5}) end}, {r4 .. ' – ' .. r5, 'Special', function (u) return u.properties.special and List.equal(u.avail.focus, {4, 5}) end}, {r5, 'Legendary', function (u) return u.properties.legendary end}, {r5, 'Mythic', function (u) return u.properties.mythic end}, {r4, 'Story', function (u) return u.properties.story end}, {'N/A', '', function (u) return true end}, } end)

p.heroList = function (frame) local WEAPON_SORT = Util.getWeaponSortOrder

-- Cargo Query local availability = HeroUtil.getLowestRarities {current = true} local heroQueryResult = cargo.query(		'Units,SummoningAvailability',		"Units._pageName=page,WeaponType,Properties__full", {			join = 'Units._pageName=SummoningAvailability._pageName',			where = "IFNULL(Properties__full,'') NOT LIKE '%enemy%' AND (SummoningAvailability._pageName IS NULL OR (NOW BETWEEN StartTime AND EndTime))",			groupBy = "Units._pageName",			limit = 1000,		}) for _, v in ipairs(heroQueryResult) do		v.properties = List.to_set(mw.text.split(v.Properties__full, '%s*,%s*')) v.avail = availability[v.page] or {nonfocus = {}, focus = {}, reward = {}} end

local heroesByWeapon = List.group_by(heroQueryResult, function (v) return v.WeaponType end) Hash.map_self(heroesByWeapon, function (vs)		return List.group_by(vs, function (v) return (List.find_if(ROWS, function (r) return r[3](v) end)) end)	end)

-- Initialize the table local tbl = mw.html.create('table'):addClass('wikitable'):addClass('unsortable') :css('text-align', 'center'):css('width', '100%')

-- Table headers local tr = tbl:tag('tr') tr:tag('th'):attr('rowspan', 2):attr('scope', 'col'):wikitext('Weapon') for _, r in ipairs(ROWS) do		tr:tag('th'):wikitext(r[1]) end tr = tbl:tag('tr') for _, r in ipairs(ROWS) do		tr:tag('td'):wikitext(r[2]) end

for w, vs in Hash.sorted_pairs(heroesByWeapon, function (_, _, k1, k2) return WEAPON_SORT[k1] < WEAPON_SORT[k2] end) do		tr = tbl:tag('tr') tr:tag('th'):wikitext('') for i = 1, #ROWS do			local td = tr:tag('td') if vs[i] then td:wikitext(table.concat(List.map(vs[i], function (v) return Util.getHeroIcon(v.page, '40px') end))) end end end

return tostring(tbl) end

return p