Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki
To edit the documentation or categories for this module, click here.

For use with {{ExtendedRosterLine}}m. See {{ExtendedRoster}} for usage documentation.


local util_args = require('Module:ArgsUtil')
local util_html = require("Module:HtmlUtil")
local util_map = require('Module:MapUtil')
local util_table = require('Module:TableUtil')
local util_vars = require('Module:VarsUtil')
local Team = require('Module:TeamClass')

local h = {}
local p = {}

p.COLS = {
	'res', 'country', 'role', 'id', 'name',
	res = { text = '', width = "26px", class = 'res', rowspan = true },
	country = { text = '', width = "28px", class = 'country', rowspan = true },
	role = { text = '', width = "27px", class = 'role' },
	id = { text = 'ID', width = '100px', class = 'id', rowspan = true },
	name = { text = 'Name', width = '170px', class = 'name', rowspan = true },
}

function p.main(frame)
	local args = util_args.merge()
	util_vars.setBool('nores',args.nores)
	local cols = h.setCols(args)
	local output = {
		'<div class="wide-content-scroll">',
		h.tableInit(util_args.castAsBool(args.nores)),
		h.makeOutput(cols)
	}
	return util_table.concat(output, '', tostring)
end

function p.wrap(args)
	local cols = h.setCols(args)
	local output = mw.html.create('div')
		:addClass('wide-content-scroll')
	local tbl = output:tag('table')
		:addClass('wikitable hoverable-multirows sortable extended-rosters')
		:addClass(h.getClass(args.nores and 'nores' or 'hasres'))
	h.makeOutput(cols, tbl)
	return cols, output, tbl
end

function h.setCols(args)
	if args.nores then
		table.remove(p.COLS, 1)
	end
	local cols = mw.clone(p.COLS)
	h.setWidths(cols, args)
	h.addTeamCols(cols, args)
	return cols
end

function h.addTeamCols(cols, args)
	local teamsize = h.getTeamsize(args)
	local rounds = tonumber(args.rounds or 0) or 0
	local i = 1
	while args['team' .. i] or args['round' .. i] or i <= rounds do
		cols[#cols+1] = 'team' .. i
		cols['team' .. i] = {
			text = h.getColTitle(args, i, teamsize),
			class = 'unsortable round'
		}
		i = i + 1
	end
end

function h.getTeamsize(args)
	if args.teamsize then
		return args.teamsize
	elseif args.team15 or args.round15 then
		return 45
	else
		return 40
	end
end

function h.getColTitle(args, i, teamsize)
	if args['team' .. i] then
		return Team(args['team' .. i]):imagelink{ size = teamsize }
	elseif args['round' .. i] then
		return args['round' .. i]
	else
		return 'R' .. i
	end
end

function h.setWidths(cols, args)
	if args['id-width'] then
		cols[4].width = args['id-width']
		cols[5].width = args['name-width']
	end
end

function h.tableInit(nores)
	local resclass = nores and h.getClass('nores') or h.getClass('hasres')
	return ('<table class="wikitable hoverable-multirows sortable extended-rosters %s">'):format(resclass)
end

function h.makeOutput(cols, tbl)
	local tr
	if tbl then
		tr = tbl:tag('tr')
	else
		tr = mw.html.create('tr')
	end
	for _, v in ipairs(cols) do
		local col = cols[v]
		tr:tag('th')
			:wikitext(col.text)
			:addClass(h.getClasses(col.class))
			:css('width', col.width)
			:css('min-width', col.width)
	end
	return tr
end

function h.getClasses(str)
	if not str then
		return nil
	end
	return util_map.splitAndConcat(str, ' ', h.getClass, ' ')
end

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

return p
Advertisement