Module:ExtendedRosterStart

From Leaguepedia | League of Legends Esports Wiki
Jump to: navigation, search
To edit the documentation or categories for this module, click here.

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


local m_team = require('Module:Team')
local util_args = require('Module:ArgsUtil')
local util_table = require('Module:TableUtil')
local util_vars = require('Module:VarsUtil')

local COLS = {
	'res', 'country', 'role', 'id', 'name',
	res = { text = '', class = 'res' },
	country = { text = '', class = 'country' },
	role = { text = '', class = 'role' },
	id = { text = 'ID', width = '100px', class = 'id' },
	name = { text = 'Name', width = '170px', class = 'name' },
}

local h = {}

function h.setCols(args)
	local cols = mw.clone(COLS)
	h.setWidths(cols, args)
	if util_args.castAsBool(args.nores) then
		table.remove(cols,1)
	end
	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 m_team.onlyimagelinked(args['team' .. i], { 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 sortable extended-rosters %s">'):format(resclass)
end

function h.makeOutput(cols)
	local tr = mw.html.create('tr')
	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)
	end
	return tr
end

function h.getClasses(str)
	if not str then
		return nil
	end
	return util_args.splitMapConcat(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

local p = {}
function p.main(frame)
	local args = util_args.merge(true)
	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

return p