Module:HeroListByType

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

function p.heroChart local moveTypes = Hash.invert(Util.getMoveSortOrder) local weaponTypes = cargo.query('WeaponTypes', '_pageName,Name,WikiName', {		groupBy = '_pageName',		orderBy = 'ColorSort,Sort',		limit = 50,	})

local heroQuery = cargo.query('Units', "IFNULL(CONCAT(Name,': ',Title),Name)=Hero,_pageName,WeaponType,MoveType", {		where = "IFNULL(Properties__full,'') NOT LIKE '%enemy%'",		groupBy = '_pageName',		orderBy = 'IFNULL(IntID,9999)',		limit = 5000,	}) local grid = Hash.map_self(List.group_by(heroQuery, function (v) return v.WeaponType end), function (vs)		return Hash.map_self(List.group_by(vs, function (v) return v.MoveType end), function (vs) return table.concat(List.map_self(vs, function (v) return "" end), " ") end)	end)

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

-- Add table headers tbl:tag('th'):css('min-width', '8%') for _, mov in ipairs(moveTypes) do		tbl:tag('th'):wikitext((' %s'):format(mov, mov)) end

for _, wep in ipairs(weaponTypes) do		if grid[wep.WikiName] then local tr = tbl:tag('tr') tr:tag('th'):wikitext(' ' .. "" .. wep.Name.. "") for _, move in ipairs(moveTypes) do				tr:tag('td'):tag('div'):css('display', 'inline-block'):wikitext(grid[wep.WikiName] and grid[wep.WikiName][move] or '') end end end

return tostring(tbl) end

return p