Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/AB-me/Team bracket
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} local getArgs = require('Module:Arguments').getArgs local function drawMatchTable(roundNo, matchNo, args) function getMatchArg(text, team, num) num = num or 0 if num <= 1 then return args['RD' .. roundNo .. '-' .. text .. matchNo * 2 - 2 + team] or args['RD' .. roundNo .. '-' .. text .. '0' .. matchNo * 2 - 2 + team] or args['RD' .. roundNo .. '-' .. text .. '00' .. matchNo * 2 - 2 + team] or args['RD' .. roundNo .. '-' .. text .. matchNo * 2 - 2 + team .. '-' .. num] or args['RD' .. roundNo .. '-' .. text .. '0' .. matchNo * 2 - 2 + team .. '-' .. num] or args['RD' .. roundNo .. '-' .. text .. '00' .. matchNo * 2 - 2 + team .. '-' .. num] or ' ' else return args['RD' .. roundNo .. '-' .. text .. matchNo * 2 - 2 + team .. '-' .. num] or args['RD' .. roundNo .. '-' .. text .. '0' .. matchNo * 2 - 2 + team .. '-' .. num] or args['RD' .. roundNo .. '-' .. text .. '00' .. matchNo * 2 - 2 + team .. '-' .. num] or ' ' end end local output = {} local rowStart = 2 ^ (roundNo - 1) * (matchNo - 1) + 1 local rowEnd = rowStart + 2 ^ (roundNo - 1) - 1 local scoreCells = args['RD' .. roundNo .. '-scoreCells'] or args['RD' .. roundNo .. '-sets'] or args['scoreCells'] or args['sets'] or 1 local scoreWidth = args['score-width'] or '1.5em' table.insert(output, '{|class="wikitable" style="grid-column:start-col ' .. roundNo .. '; grid-row:start-row ' .. rowStart .. ' / end-row ' .. rowEnd .. '; margin:0;"' .. '\n') table.insert(output, '|-' .. '\n') table.insert(output, '|style="text-align:left;"|' .. getMatchArg('team', 1)) if (getMatchArg('seed', 1) ~= ' ') then table.insert(output, ' <small>(' .. getMatchArg('seed', 1) .. ')</small>') end table.insert(output, '\n') for i=1, scoreCells do table.insert(output, '|style="width:' .. scoreWidth .. ';padding:0;"|' .. getMatchArg('score', 1, i) .. '\n') end table.insert(output, '|-' .. '\n') table.insert(output, '|style="text-align:left;"|' .. getMatchArg('team', 2)) if (getMatchArg('seed', 2) ~= ' ') then table.insert(output, ' <small>(' .. getMatchArg('seed', 2) .. ')</small>') end table.insert(output, '\n') for i=1, scoreCells do table.insert(output, '|style="width:' .. scoreWidth .. ';padding:0;"|' .. getMatchArg('score', 2, i) .. '\n') end table.insert(output, '|}' .. '\n') return table.concat(output) end local function drawLines(roundNo, matchNo, args) local output = {} if roundNo >= 2 then local leftRowStart = 2 ^ (roundNo - 2) + (matchNo - 1) * 2 * 2 ^ (roundNo - 1) local leftRowEnd = leftRowStart + 2 ^ (roundNo - 1) local rightRowStart = 2 ^ (roundNo - 1) * (matchNo - 1) + 1 local rightRowEnd = rightRowStart + 2 ^ (roundNo - 1) - 1 table.insert(output, '<div style="grid-column:start-gap ' .. roundNo - 1 .. '; grid-row:gap ' .. leftRowStart .. ' / gap ' .. leftRowEnd .. '; border:3px solid #202122; border-left: 0; justify-self:stretch; height:calc(100% - 3px);"></div>' .. '\n') table.insert(output, '<div style="grid-column:mid-gap ' .. roundNo - 1 .. '; grid-row:start-row ' .. rightRowStart .. ' / end-row ' .. rightRowEnd .. '; background-color:#202122; height:3px;"></div>' .. '\n') end return table.concat(output) end local function getRoundName(round, totalRounds, args) if args['RD' .. round] then return args['RD' .. round] end local finalRounds = totalRounds - round if finalRounds == 0 then return "Final" elseif finalRounds == 1 then return "Semi-finals" elseif finalRounds == 2 then return "Quarter-finals" else --return 'Round of ' ..(2 ^ (totalRounds - round)) * 2 return 'Round of ' ..(2 ^ (totalRounds - round + 1)) end end function p.main(frame) local output = {} local args = getArgs(frame) local rounds = args.rounds local teams = 2 ^ rounds local matchWidth = args['match-width'] or '18em'; table.insert(output, '<div style="display:grid; grid-template-columns: [start-col]' .. ' ' .. matchWidth .. ' ' .. '[end-col] repeat(' .. (rounds - 1) .. ', [start-gap] 1.5em [mid-gap] 1.5em [end-gap start-col]' .. ' ' .. matchWidth .. ' ' .. '[end-col]); grid-template-rows:auto repeat(' .. (2 ^ rounds) / 2 - 1 .. ', [start-row] 0.5fr [gap] 0.5fr [end-row] 0.5em [gap] 0.5em) [start-row] 0.5fr [gap] 0.5fr [end-row]; justify-items:auto; align-items:center; text-align:center">' .. '\n') --table.insert(output, '<div style="display:grid; grid-template-columns: [start-col] 18em [end-col] repeat(' .. (rounds - 1) .. ', [start-gap] 1.5em [mid-gap] 1.5em [end-gap start-col] 18em [end-col]); grid-template-rows:auto repeat(' .. (2 ^ rounds) / 2 - 1 .. ', [start-row] auto [gap] auto [end-row] auto [gap] auto) [start-row] auto [gap] auto [end-row]; justify-items:auto; align-items:center; text-align:center">' .. '\n') for i=1, rounds do table.insert(output, '<div class="wikitable" style="grid-column: start-col ' .. i .. '; grid-row:1; justify-self:stretch; padding: 0.2em 0.4em;">' .. getRoundName(i, rounds, args) .. '</div>' .. '\n') for j=1, teams / (2^i) do table.insert(output, drawMatchTable(i, j, args)) table.insert(output, drawLines(i, j, args)) end end table.insert(output, '</div>' .. '\n') return table.concat(output) end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/AB-me/Team bracket/doc
(
edit
)