Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

Documentation for this module may be created at Module:ExtendedRoster/doc

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 i18n = require("Module:I18nUtil")

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

local ReplaceRedirects = require('Module:ReplaceRedirects')

local LINE_ARGS = { 'Flag', 'Residency', 'Player', 'Name', 'Role', 'Roles', 'Role1', 'Role2', 'Role3', 'Role4', 'Role5', 'Role6', 'RoundData', 'RoundData1', 'RoundData2', 'RoundData3', 'RoundData4', 'RoundData5', 'RoundData6', 'Footnote' }
local ROW_INDEX = 0

local h = {}
local p = {}
function p.main(frame)
	local args = util_args.merge()
	h.castArgs(args)
	local RoundData = util_map.arraySafe(args, util_args.splitArgs, LINE_ARGS)
	util_map.arraySafe(RoundData, h.processRoundData)
	local cols, output, tbl = Start.wrap(args)
	util_map.arrayInPlace(RoundData, h.printOutput, tbl, Start.COLS)
	return ReplaceRedirects.main(tostring(output))
end

function h.castArgs(args)
	args.nores = util_args.castAsBool(args.nores)
end

function h.processRoundData(row)
	row.footnotes = {}
	row.Residency = Region(row.Residency)
	row.rolesData = h.getrolesData(row)
	row.res = row.Residency:image()
	row.country = Country(row.Flag):image()
	row.id = util_esports.playerLinked(row.Player)
	row.name = row.Name
	row.role = Role(row.rolesData[1].role):image()
	if row.footnote then
		row.footnotes = { name = row.footnote }
	end
end

function h.getrolesData(row)
	local rolesData = {}
	if not row.Roles or row.Roles == 1 then
		rolesData[#rolesData+1] = h.getRoleData(row.Role1 or row.Role, row.RoundData1 or row.RoundData)
	else
		for i = 1, tonumber(row.Roles) do
			rolesData[#rolesData+1] = h.getRoleData(row['Role' .. i], row['RoundData' .. i])
		end
	end
	return rolesData
end

function h.getRoleData(rolename, roundData)
	local tbl = roundData and util_text.split(roundData or '') or {}
	
	-- split each individual cell which is one character per game
	util_map.inPlace(tbl, util_text.split, '')
	tbl.role = rolename
	return tbl
end

function h.printOutput(row, tbl, cols)
	ROW_INDEX = ROW_INDEX + 1
	local tr, rowCell = h.printIntro(tbl, row, cols)
	h.printRoles(tbl, tr, cols, row.rolesData)
end

function h.printIntro(tbl, row, cols)
	local tr = tbl:tag('tr')
		:addClass('multirow-highlighter')
		:attr('data-highlight-row', ROW_INDEX)
	for _, v in ipairs(cols) do
		local td = tr:tag('td')
			:wikitext(row[v])
			:addClass(h.getClass(cols[v].class))
		if row.footnotes[v] and row.footnotes[v].FootnoteN then
			util_footnote.tagFootnotePlain(td, row.FootnoteN)
		end
		if cols[v].rowspan then
			td:attr('rowspan', #row.rolesData)
		end
	end
	return tr
end

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

function h.printRoles(tbl, tr, cols, rolesData)
	h.printRoleLine(tr, table.remove(rolesData, 1))
	for _, row in ipairs(rolesData) do
		local tr_next = tbl:tag('tr')
			:addClass('multirow-highlighter')
			:attr('data-highlight-row', ROW_INDEX)
		tr_next:tag('td')
			:addClass(h.getClass('role'))
			:wikitext(Role(row.role):image())
		h.printRoleLine(tr_next, row)
	end
end

function h.printRoleLine(tr, rolesData)
	for _, cellRoundData in ipairs(rolesData) do
		h.printRoleCell(tr, cellRoundData)
	end
end

function h.printRoleCell(tr, cellRoundData)
	local td = tr:tag('td')
		:addClass(h.getClass('round'))
	for _, game in ipairs(cellRoundData) 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
Advertisement