Module:VoiceActorsList

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

function p._voiceActorList(lang) local heroesQuery = List.group_by(cargo.query('Units,VoiceActors', 'VoiceActors._pageName=va,Units._pageName=page,Units.Name=name', { where = 'Units._pageName IS NOT NULL', join = ('Units.Actor%s HOLDS VoiceActors.%s'):format(lang, lang == 'JP' and 'NameJPJA' or 'Name'), groupBy = 'VoiceActors.Name,Units._pageName', limit = 5000, }), function (x) return x.va end) local vas = List.select(List.map_self(cargo.query('VoiceActors', '_pageName=Name', {		groupBy = '_pageName',		where = ("Language='%s'"):format(lang),		orderBy = '_pageName',		limit = 500,	}), function (x) return x.Name end), function (x) return heroesQuery[x] end)

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

-- Add table headers tbl:tag('th') :wikitext('Voice actor / actress')

tbl:tag('th') :wikitext('Hero')

-- Go through all the voice actors for _, va in ipairs(vas) do		local tr = tbl:tag('tr')

-- Add the va name + link tr:tag('td') :wikitext(' ' .. va .. '')

-- Create a table where we'll add all the heroes the actor / actress has voiced. local heroTable = tr:tag('td'):css('padding', '8px'):tag('div') :css('display', 'flex'):css('flex-flow', 'wrap'):css('justify-content', 'center')

-- Add all the heroes + portrait icons to the hero table for _, hero in pairs(heroesQuery[va]) do			heroTable:tag('div') :css('margin', '3px') :wikitext(Util.getHeroIcon(hero.page, '75px') .. ' ' .. hero.name .. '') end end

return tostring(tbl) end

function p.voiceActorList(frame) local args = frame.args return p._voiceActorList(args[1]) end

return p