Jump to content

Module:Build bracket

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pbrks (talk | contribs) at 02:23, 2 August 2022 (Created page with 'local p = {} local legs local function isempty(s) return s == nil or s == '' end local function generateRow(t,c,j,cell,path,RDlegs) if isempty(cell) then table.insert(t,'| colspan="' .. RDlegs+2 .. '" | \n') else table.insert(t,cell..'\n') end if j<c then if isempty(path) then table.insert(t,'| colspan="2" | \n') else table.insert(t,path..' \n') end end end local function generateColumn(t) table.insert(t,'|-\n') table.insert(t,...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}
local legs

local function isempty(s)
	return s == nil or s == ''
end

local function generateRow(t,c,j,cell,path,RDlegs)
	if isempty(cell) then
		table.insert(t,'| colspan="' .. RDlegs+2 .. '" | \n')
		else
		table.insert(t,cell..'\n')
	end
	if j<c then
		if isempty(path) then
			table.insert(t,'| colspan="2" | \n')
			else
			table.insert(t,path..' \n')
		end
	end
end

local function generateColumn(t)
	table.insert(t,'|-\n')	
	table.insert(t,'| &nbsp;\n')
end

function p.main(frame)
	local fargs = frame.args
	local pargs = frame:getParent().args;
	
	local r = tonumber(frame.args.rows) or tonumber(frame.args.maxrows) or 1
	local c = tonumber(frame.args.rounds) or 1
	local legs = tonumber(fargs.legs) or tonumber(pargs.legs) or 1
	local seed_width = fargs["seed-width"] or  pargs["seed-width"] or 25
	local team_width = fargs["team-width"] or pargs["team-width"] or 150
	local score_width = fargs["score-width"] or pargs["score-width"] or 25
	
	t = {}
	
	table.insert(t,'{| border=0 cellpadding=0 cellspacing=0 style="font-size: 90%; margin:1em 2em 1em 1em;\n')
	generateColumn(t)

	for j=1,c do
		local RDlegs = tonumber(fargs['RD'..j..'-legs']) or tonumber(pargs['RD'..j..'-legs']) or legs
		local cell = fargs['0-'..j] or ''
		local path = fargs['0-'..j..'a'] or ''
		generateRow(t,c,j,cell,path,RDlegs)
	end
	
	table.insert(t,'|-\n')
	for j=1,c do
		local RDlegs = tonumber(fargs['RD'..j..'-legs']) or tonumber(pargs['RD'..j..'-legs']) or legs
		table.insert(t,'| width="5" | &nbsp;\n')
		table.insert(t,'| width="'..seed_width..'" | \n')
		table.insert(t,'| width="'..team_width..'" | \n')
		for k=1,RDlegs do
			table.insert(t,'| width="'..score_width..'" | \n')
		end
		if j<c then
			table.insert(t,'| width="5" | \n')
		end
	end
	
	for i=1,r do
		generateColumn(t)
		for j=1,c do
			local RDlegs = tonumber(fargs['RD'..j..'-legs']) or tonumber(pargs['RD'..j..'-legs']) or legs
			local cell = fargs[i..'-'..j] or ''
			local path = fargs[i..'-'..j..'a'] or ''
			generateRow(t,c,j,cell,path,RDlegs)
		end
	end
	table.insert(t,'|} \n')
	return table.concat(t)
end

return p