Module:TeamRoster

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_esports = require('Module:EsportsUtil') local util_game = require('Module:GameUtil') local util_html = require('Module:HtmlUtil') local util_table = require('Module:TableUtil') local util_text = require('Module:TextUtil') local util_toggle = require('Module:ToggleUtil') local util_vars = require('Module:VarsUtil') local m_country = require('Module:Country') local m_role = require('Module:Role') local m_team = require('Module:Team') local Sprite = require('Module:Sprite').sprite local lang = mw.getLanguage('en') local s = {}

function s.RoleSprite(id) return Sprite{ id, size = '15', type = 'Role', notext = true, nolink = true, } end

function s.FlagSprite(id) return Sprite{ id, type = 'Flag', notext = true, nolink = true, } end

local PLAYER_FIELD_LIST = { 'Name', 'Link', 'Flag', 'Role', 'FootnoteN' }

local h = {}

local p = {} function p.main(frame) local args = util_args.merge(true) for k, _ in pairs(args) do		if tostring(k):match('^[a-z]+%d+$') then return k .. ''		end end util_vars.setGlobalIndex('rosterN') local playerData = h.getPlayerData(args) local teamData = h.getTeamData(args, playerData) h.storeCargo(playerData, teamData, args.nocargo) return h.makeOutput(playerData, teamData, args) end

function h.getPlayerData(args) local i = 1 local playerData = {} while i <= util_game.players_per_team or args[i] do		playerData[i] = args[i] and util_args.splitArgs(args[i], PLAYER_FIELD_LIST) or {} h.castPlayerRow(playerData[i], i)		i = i + 1 end h.cropPlayerResults(playerData) h.addTeamDataToPlayers(playerData, args) return playerData end

function h.castPlayerRow(row, i)	row.N = i	row.Flag = h.getFlag(row.Flag) row.Role = util_args.splitMapConcat(row.Role, nil, m_role.roleonly, ',') row.Link = util_esports.ucfirstLink(row.Link, row.Name) row.UniqueLine = util_cargo.getUniqueLine('rosterN', i)	row._table = 'TournamentPlayers' end

function h.getFlag(flag) if flag then return m_country.name(flag) end return nil end

function h.cropPlayerResults(playerData) for k, v in ipairs(playerData) do		if k > util_game.players_per_team and not v.Name then playerData[k] = nil end end end

function h.addTeamDataToPlayers(playerData, args) for i, row in ipairs(playerData) do		h.addTeamDataToOnePlayer(i, row, args) end end

function h.addTeamDataToOnePlayer(i, row, args) row.TeamLink = m_team.teamlinkname(args.team) end

function h.getTeamData(args, playerData) local teamData = { _table = 'TournamentRosters', Team = m_team.teamlinkname(args.team), TeamLink = m_team.teamlinkname(args.team), Tournament = util_vars.getVar('Event Name'), UniqueLine = util_cargo.getUniqueLine('rosterN'), IsComplete = util_args.castAsBool(args.isincomplete), Team_Markup = m_team.rightlonglinked(args.team), }	h.addPageAndTeam(teamData) h.addPlayerDataToTeam(teamData, playerData) return teamData end

function h.addPageAndTeam(teamData) teamData.PageAndTeam = mw.title.getCurrentTitle.text .. '_' .. teamData.Team end

function h.addPlayerDataToTeam(teamData, playerData) teamData.Roster = h.concatPlayerParam(playerData, 'Name') teamData.RosterLinks = h.concatPlayerParam(playerData, 'Link') teamData.Roster_Linked = h.concatPlayerLinked(playerData) teamData.Roles = h.concatPlayerParam(playerData, 'Role') teamData.Flags = h.concatPlayerParam(playerData, 'Flag') end

function h.concatPlayerParam(playerData, param) local ret = {} for _, player in ipairs(playerData) do		ret[#ret+1] = player[param] end return util_table.concat(ret, ';;') end

function h.concatPlayerLinked(playerData) local ret = {} for _, player in ipairs(playerData) do		ret[#ret+1] = util_text.intLinkOrText(player.Link, player.Name) end return util_table.concat(ret, ';;') end

function h.storeCargo(playerData, teamData, nocargo) if util_cargo.doWeStoreCargo(nocargo, '') then util_cargo.store(teamData) h.storePlayers(playerData) end end

function h.storePlayers(playerData) for _, row in ipairs(playerData) do		if row.Link then util_cargo.store(row) end end end

function h.makeOutput(playerData, teamData, args) util_toggle.initSectionToggler local tbl = h.initTable h.printCaption(tbl, args.seed) h.printHeader(tbl, teamData.Team, args.footnoteteamn) h.printLogo(tbl, teamData.Team) h.printPlayers(tbl, playerData) return tbl end function h.initTable local tbl = mw.html.create('table') :addClass('wikitable tournament-roster') return tbl end

function h.printCaption(tbl, seed) tbl:tag('caption') :addClass('tournament-roster-span') :wikitext(seed) end

function h.printHeader(tbl, team, footnoten) local th = tbl:tag('tr'):tag('th') :addClass('tournament-roster-header') local outerdiv = th:tag('div') :css('position','relative') h.printNameAndFootnote(outerdiv, team, footnoten) local innerdiv = outerdiv:tag('div') :css({ position = "absolute", right = "2px", top = '0' }) h.printOneToggler(innerdiv, 'Show', 'RosterLogos', false) h.printOneToggler(innerdiv, 'Hide', 'RosterPlayers', true) end

function h.printNameAndFootnote(div, team, footnoten) div:wikitext(m_team.mediumplainlinked(team)) :wikitext(util_html.makeFootnoteN(footnoten)) end

function h.printOneToggler(div, image, class, isHidden) local span = div:tag('span') :addClass(class) :wikitext((''):format(image)) util_toggle.tagSectionToggler(span, isHidden) end

function h.printLogo(tbl, team) local logo_tr = tbl:tag('tr') :addClass('RosterLogos') local logo = logo_tr:tag('td') :addClass('tournament-roster-logo-cell') :wikitext(m_team.square(team, { size = 123, title = "Click to Show Roster" })) util_toggle.tagSectionToggler(logo_tr) end

function h.printPlayers(tbl, playerData) for _, player in ipairs(playerData) do		h.printOnePlayer(tbl, player) end end

function h.printOnePlayer(tbl, player) local tr = h.initPlayerRow(tbl) h.printPlayerCell(tr, player) end

function h.initPlayerRow(tbl) local tr = tbl:tag('tr') :addClass('RosterPlayers') util_toggle.tagSectionToggle(tr, true) return tr end

function h.printPlayerCell(tr, player) local td = tr:tag('td') :addClass('tournament-roster-player-cell') h.printRole(td, player.Role) h.printFlagAndName(td, player) end

function h.printRole(td, role) td:tag('span') :addClass('tournament-roster-role') :wikitext(util_args.splitMapConcat(role, nil, s.RoleSprite)) end

function h.printFlagAndName(td, player) td:tag('span') :addClass('tournament-roster-player') :wikitext(s.FlagSprite(player.Flag)) :wikitext(' ') :wikitext(util_text.intLink(player.Link, player.Name)) if player.FootnoteN then td:wikitext(util_html.makeFootnoteN(player.FootnoteN)) end end

return p