Module:SkillsTable

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

local makeFieldText = function (skillrows) return not skillrows and '—' or table.concat(List.map(skillrows, function (row) local page, name = row.SkillPage, row.SkillName return page == name and ('%s'):format(page) or ('%s'):format(page, name) end), ' ') end

local main = function local heroes = cargo.query('Units', "_pageName=page,IFNULL(CONCAT(Name,': ',Title),Name)=hero,MoveType,WeaponType", {		where = "IFNULL(Properties__full,'') NOT LIKE '%enemy%'",		groupBy = '_pageName',		limit = 1000,	})

local _, AFTER = Util.getSkillChains local heroSkills = List.group_by(CargoUtil.full_query( 'UnitSkills=US,Skills=S,Units=U', "U._pageName=Hero,S._pageName=SkillPage,S.Name=SkillName,S.WikiName=WikiName,Scategory", { join = 'US.skill=S.WikiName,US.WikiName=U.WikiName', where = "S.WikiName IS NOT NULL AND U.WikiName IS NOT NULL AND IFNULL(U.Properties__full,'') NOT LIKE '%enemy%'", groupBy = 'US.skill,US.WikiName', orderBy = 'Hero,skillPos', }), function (v) return v.Hero end) Hash.map_self(heroSkills, function (skills)		local skills_set = List.to_set(List.map(skills, function (v) return v.WikiName end))		List.keep_if(skills, function (v) -- none of the skill's descendents can be learned by the hero return List.none(AFTER[v.WikiName], function (skill) return skills_set[skill] end) end)		return List.group_by(skills, function (v) return v.Scategory end)	end)

local theUnit = nil local builder = HeroTableBuilder.new

local skillFieldFunc = function (elem, cat) local skills = heroSkills[theUnit.page] elem:wikitext(makeFieldText(skills and skills[cat])) end

builder:heroIcon:css('width', '30px') builder:heroLink:css('width', '15%') builder:moveType:css('width', '4%') builder:weaponType:css('width', '4%') builder:column('Weapon', function (elem) skillFieldFunc(elem, 'weapon') end):css('width', '12%') builder:column('Assist', function (elem) skillFieldFunc(elem, 'assist') end):css('width', '12%') builder:column('Special', function (elem) skillFieldFunc(elem, 'special') end):css('width', '12%') builder:column('Passive A', function (elem) skillFieldFunc(elem, 'passivea') end):css('width', '12%') builder:column('Passive B', function (elem) skillFieldFunc(elem, 'passiveb') end):css('width', '12%') builder:column('Passive C', function (elem) skillFieldFunc(elem, 'passivec') end):css('width', '12%')

for _, v in ipairs(heroes) do		theUnit = v		builder:addHero(v.page, v.hero, v.MoveType, v.WeaponType) end

return builder:build:addClass('wikitable'):css('text-align', 'center'):css('width', '100%') end

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