Module:TeamRoster

local util_html = require('Module:HTMLUtil') local m_team = require('Module:Team') local m_role = require('Module:Role') local Flag = mw.loadData('Module:Flagnames')

local p = {}

function p.teamRoster(frame) local args = frame if frame == mw.getCurrentFrame then args = require( 'Module:ProcessArgs' ).merge( true ) else frame = mw.getCurrentFrame end local lang = mw.getLanguage('en') -- global indexing variable for toggle IDs & cargo local rosterN = tonumber(frame:callParserFunction('#var', 'rosterN')) or 1 frame:callParserFunction('#vardefine', 'rosterN', rosterN + 1) local title = tostring(mw.title.getCurrentTitle) local thisteam = m_team.teamlinkname(args.team) -- TODO: add actual footnote support eventually local cargo = true if lang:lc(args['nocargo'] or 'no' ) == 'yes' or not mw.title.getCurrentTitle:inNamespace(0) then cargo = false end local iscomplete = "Yes" if lang:lc(args['isincomplete'] or 'no' ) == 'yes' then iscomplete = "No" end --markup / data that we will eventually store in cargo local data = { Roster = {}, RosterLinks = {}, Roster_Linked = {}, Roles = {}, Flags = {}, IsUsed = {}, Footnotes = {}, UniqueLine = {}, }	local constants = { Team = m_team.teamname(thisteam), TeamLink = thisteam, Team_Markup = m_team.rightlonglinked(thisteam), Roles_Markup = m_role.onlyimage(roles), Tournament = frame:callParserFunction('#var','Event Name'), IsComplete = iscomplete, UniqueLine = title .. '_' .. rosterN, PageAndTeam = title .. '_' .. thisteam, ['_table'] = "TournamentRosters" }	--markup we need to make that we won't store in cargo local data2 = { Flags = {}, Roles_Markup = {}, }	local Flags = {} local footnoteteamn = util_html.makeFootnoteN(args['footnoteteamn']) -- do all needed markup here local i = 1 while i <= 4 or args['player' .. i] do data.Flags[i] = args['flag' .. i] or '' data2.Flags[i] = Flag[lang:lc(args['flag' .. i] or '')] data.Roster[i] = args['player' .. i] or '' data.RosterLinks[i] = args['link' .. i] or data.Roster[i] data.Roles[i] = args['role' .. i] or '' data.Footnotes[i] = args['footnote' .. i] or '' if args['role' .. i] then roles = mw.text.split(args['role' .. i],',') for index, role in ipairs(roles) do				role = mw.text.trim(role) roles[index] = m_role.onlyimage(role) end data2.Roles_Markup[i] = table.concat(roles) else data2.Roles_Markup[i] = '' end if lang:ucfirst(args['isunused' .. i] or 'No') == 'Yes' then data.Roster_Linked[i] = "' .. data.Roster[i] .. "" data.IsUsed[i] = 'No' else data.Roster_Linked[i] = "' .. data.Roster[i] .. "" data.IsUsed[i] = 'Yes' end playerdata = { Name = data.Roster[i], Link = data.RosterLinks[i], ['_table'] = "TournamentPlayers", TeamLink = thisteam, Role = data.Roles[i], Active = data.IsUsed[i], UniqueLine = title .. '_' .. rosterN .. '_' .. i,		} if cargo then frame:callParserFunction('#cargo_store:', playerdata) end i = i + 1 end -- constants that are defined here to clean up later code local togglePlayers = '_tog_object _toggle_inithide _toggle RosterPlayers Roster' .. rosterN .. 'Players' local toggleLogos = '_tog_object _toggle RosterLogos Roster' .. rosterN .. 'Logo' local togglerPlayers = '_tog_object _toggler_show-Roster' .. rosterN .. 'Players _tog_object _toggler_hide-Roster' .. rosterN .. 'Logo' local togglerLogos = '_tog_object _toggler_show-Roster' .. rosterN .. 'Logo _tog_object _toggler_hide-Roster' .. rosterN .. 'Players' local roleStyle = { height = '0', overflow = 'visible', position = 'relative', ['z-index'] = '99', opacity = '0.5', float = 'right' }	local playerStyle = { position = 'relative', ['z-index'] = '100' }	-- end constants -- make top part of table & logo local tbl = mw.html.create('table') :addClass('wikitable') :css({ ['margin-top'] = '2px', width = "150px" }) :tag('caption') :tag('span') :css('font-weight','700') :wikitext(args['seed']) :done :done :tag('tr') :addClass(logotoggle) :tag('th') :css({ 					['text-align'] = 'center',					['line-height'] = "130%",					['font-size'] = '80%',					padding = '0',				}) :tag('div') :css('position','relative') :tag('div') :css({ position = "absolute", right = "2px" }) :tag('span') :addClass(toggleLogos) :addClass(togglerPlayers) :wikitext('') :done :tag('span') :addClass(togglePlayers) :addClass(togglerLogos) :wikitext('') :done :done :wikitext(m_team.mediumplainlinked(thisteam) .. footnoteteamn) :done :done :done :tag('tr') :addClass(toggleLogos) :tag('td') :css({ ["text-align"] = "center", ["line-height"] = '133px', width = '150px', padding = '0 3px' }) :addClass(togglerPlayers) :wikitext(m_team.square(thisteam, { size = 123 })) :done :done -- print players to table local j = 1 while j < i do		tbl:tag('tr') :addClass(togglePlayers) :tag('td') :css({ ['font-weight'] = '700', ['line-height'] = '22px', width = '150px' }) :tag('span') :css(roleStyle) :wikitext(data2.Roles_Markup[j]) :done :tag('span') :css(playerStyle) :wikitext(data2.Flags[j]) :wikitext(' ') :wikitext(data.Roster_Linked[j]) :done :done :done j = j + 1 end data.UniqueLine = nil -- store cargo if we're doing that if cargo then for key, value in pairs(data) do			data[key] = table.concat(value, ';;') end for key, value in pairs(constants) do			data[key] = value end frame:callParserFunction('#cargo_store:', data) end output = tostring(tbl) return output end return p