Module:BuildsList

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

function p.main local outputWikitext = "" local types = {} -- types[i] = {movetype, movetype name, weaponslist}; weaponslist[i] = {weapontype, weapontype name} local tbls = {} for _,v in ipairs(cargo.query( "Units=h,HeroBuilds=b,MoveTypes=m,WeaponTypes=w", "b._pageName=pg,MoveType,WeaponType,h._pageName=Hero,COUNT(DISTINCT Hero,IFNULL(Weapon,'n'),IFNULL(Assist,'n'),IFNULL(Special,'n'),IFNULL(PassiveA,'n'),IFNULL(PassiveB,'n'),IFNULL(PassiveC,'n'))=n,m.Name=mname,w.Name=wname,CONCAT(h.Name,': ',h.Title)=hname", {			join = "h._pageName=b.Hero,h.MoveType=m.WikiName,h.WeaponType=w.WikiName", where = "IFNULL(h.Properties__full,'') NOT LIKE '%enemy%'", groupBy = "m.WikiName,w.WikiName,b.Hero", orderBy = "m.Sort,w.Sort,IFNULL(h.IntID,9999)", limit=9000 }	)) do		local move = v["MoveType"] local weapon = v["WeaponType"]

local mtk = ListUtil.find_if(types, function (mt) return mt[1] == move end) if mtk then if ListUtil.none(types[mtk][3], function (wt) return wt[1] == weapon end) then table.insert(types[mtk][3], {weapon, v["wname"]}) end else types[#types + 1] = {move, v["mname"], } end

if not tbls[move] then tbls[move] = {} end if not tbls[move][weapon] then local tbl = mw.html.create("table") :addClass("wikitable") :addClass("sortable") :css("text-align","center") tbl:tag("th"):wikitext("Hero"):attr("colspan",2) tbl:tag("th"):wikitext("Builds") tbls[move][weapon] = tbl end local row = tbls[move][weapon]:tag("tr") row:tag("td"):wikitext("") if v["pg"] == "" then row:tag("td"):wikitext(""..v["hname"].."") else row:tag("td"):wikitext(""..v["hname"].."") end row:tag("td"):wikitext(v["n"]) end for _,m in ipairs(types) do outputWikitext = outputWikitext .. " " .. m[2] .. " "		for _,w in ipairs(m[3]) do outputWikitext = outputWikitext .. " " .. w[2] .. " " .. tostring(tbls[m[1]][w[1]]) end end return outputWikitext end return p