Module:ExtendedRosterLine

local util_args = require('Module:ArgsUtil') local util_esports = require("Module:EsportsUtil") local util_footnote = require('Module:FootnoteUtil') local util_map = require('Module:MapUtil') local util_table = require('Module:TableUtil') local util_text = require('Module:TextUtil') local util_vars = require('Module:VarsUtil')

local Country = require('Module:Country') local Region = require('Module:Region') local Role = require('Module:Role')

local COLS = { 'res', 'country', 'role', 'id', 'name', res = { class = 'res', rowspan = true }, country = { class = 'country', rowspan = true }, role = { class = 'role' }, id = { class = 'id', rowspan = true }, name = { class = 'name', rowspan = true }, }

local ROW_INDEX

local h = {} local p = {}

function p.main(frame) local args = util_args.merge h.castArgs(args) ROW_INDEX = util_vars.setGlobalIndex('erl-toggle') local cols = h.setCols(args, nores) h.addInitData(cols, args) local output = mw.html.create local tr = h.makeRowInit(output, cols) local roleData = h.getRoleData(args) h.printRoles(output, tr, cols, roleData) return output end

function h.setCols(args, nores) local cols = mw.clone(COLS) h.setRes(cols, nores) return cols end

function h.setRes(cols, nores) if util_vars.getBool('nores') then table.remove(cols, 1) end end

function h.castArgs(args) args.res = Region(args.res) end

function h.addInitData(cols, args) cols.res.text = args.res:image cols.country.text = Country(args.flag):image cols.id.text = util_esports.playerLinked(args.player) cols.name.text = args.name if args.footnote then cols.id.footnoten = args.footnote end end

function h.makeRowInit(output, cols) local tr = output:tag('tr') :addClass('multirow-highlighter') :attr('data-highlight-row', ROW_INDEX) local roleCell for _, v in ipairs(cols) do		local col = cols[v] local td = tr:tag('td') :wikitext(col.text) :addClass(h.getClass(col.class)) if col.footnoten then util_footnote.tagFootnotePlain(td, col.footnoten) end col.cell = td	end return tr end

function h.getClass(str) if not str then return nil end return 'extended-rosters-' .. str end

function h.getRoleData(args) local rolesData = {} if not args.roles or args.roles == 1 then rolesData[#rolesData+1] = h.roleFromArgs(args.role1 or args.role, args.r1 or args.r)	else for i = 1, tonumber(args.roles) do rolesData[#rolesData+1] = h.roleFromArgs(args['role' .. i], args['r' .. i]) end end return rolesData end

function h.roleFromArgs(rolename, rounds) local tbl = rounds and util_text.split(rounds or '') or {} util_map.inPlace(tbl, h.roundFromStr) tbl.role = rolename return tbl end

function h.roundFromStr(str) return util_text.split(str,'') end

function h.printRoles(output, tr, cols, rolesData) h.printRowspans(cols, #rolesData) h.printRoleLine(tr, table.remove(rolesData, 1), cols.role.cell) for _, row in ipairs(rolesData) do		local tr_next = output:tag('tr') :addClass('multirow-highlighter') :attr('data-highlight-row', ROW_INDEX) h.printRoleLine(tr_next, row) end end

function h.printRowspans(cols, rowspan) for _, v in ipairs(cols) do		local col = cols[v] if col.rowspan then col.cell:attr('rowspan', rowspan) end end end

function h.printRoleLine(tr, roleData, cell) if not cell then cell = tr:tag('td') :addClass(h.getClass('role')) end cell:wikitext(Role(roleData.role):image) for _, cellData in ipairs(roleData) do		h.printRoleCell(tr, cellData) end end

function h.printRoleCell(tr, cellData) local td = tr:tag('td') :addClass(h.getClass('round')) for _, game in ipairs(cellData) do		game = util_text.trim(game) if game == '' then game = nil end if game == 'y' then h.yes(td) elseif game == 'n' then h.no(td) elseif game == 'x' then -- pass else td:wikitext(Role(game):image{size=13}) end end end

function h.yes(cell) cell:tag('div') :addClass('greencheck') :attr('title','Player Started') end

function h.no(cell) cell:tag('div') :addClass('redx') :attr('title', 'Player Did Not Start') end

return p