Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 17:31, 6 February 2026 by Esportsamaze (talk | contribs) (Created page with "local p = {} local html = mw.html function p.main(frame) local args = frame:getParent().args local teamCount = tonumber(args.teams) or 8 -- Default to 8 teams local rounds = math.log(teamCount) / math.log(2) -- Calculate rounds (8 -> 3, 16 -> 4) local container = html.create('div'):addClass('bracket-scroll-wrapper') local wrapper = container:tag('div'):addClass('bracket-wrapper') -- Iterate Rounds (1 to Total Rounds) for r = 1, rounds d...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}
local html = mw.html

function p.main(frame)
    local args = frame:getParent().args
    local teamCount = tonumber(args.teams) or 8 -- Default to 8 teams
    local rounds = math.log(teamCount) / math.log(2) -- Calculate rounds (8 -> 3, 16 -> 4)
    
    local container = html.create('div'):addClass('bracket-scroll-wrapper')
    local wrapper = container:tag('div'):addClass('bracket-wrapper')

    -- Iterate Rounds (1 to Total Rounds)
    for r = 1, rounds do
        local col = wrapper:tag('div'):addClass('bracket-col bracket-col-' .. r)
        local matchesInRound = teamCount / (2^r)
        
        -- Header (e.g., Quarterfinals)
        local headerTxt = "Round " .. r
        if r == rounds then headerTxt = "Grand Finals" 
        elseif r == rounds - 1 then headerTxt = "Semifinals"
        elseif r == rounds - 2 then headerTxt = "Quarterfinals" 
        end
        col:tag('div'):addClass('bracket-header'):wikitext(headerTxt)

        -- Iterate Matches in this Round
        for m = 1, matchesInRound do
            local matchID = "R" .. r .. "M" .. m
            
            -- Calculate Spacing (The Magic Math)
            -- This aligns the matches vertically relative to previous round
            local spacer = col:tag('div'):addClass('bracket-spacer')
            
            -- DATA INPUTS
            local t1 = args[matchID .. 'team1'] or 'TBD'
            local s1 = args[matchID .. 'score1'] or ''
            local t2 = args[matchID .. 'team2'] or 'TBD'
            local s2 = args[matchID .. 'score2'] or ''
            local win = args[matchID .. 'win'] -- '1' or '2' to highlight winner

            -- MATCH CARD
            local matchBox = col:tag('div'):addClass('bracket-match')
            
            -- Team 1 Row
            local row1 = matchBox:tag('div'):addClass('bracket-team')
            if win == '1' then row1:addClass('bracket-win') end
            row1:tag('div'):addClass('bracket-name'):wikitext(t1)
            row1:tag('div'):addClass('bracket-score'):wikitext(s1)

            -- Team 2 Row
            local row2 = matchBox:tag('div'):addClass('bracket-team')
            if win == '2' then row2:addClass('bracket-win') end
            row2:tag('div'):addClass('bracket-name'):wikitext(t2)
            row2:tag('div'):addClass('bracket-score'):wikitext(s2)
            
            -- Add Connector Lines (except for last round)
            if r < rounds then
                matchBox:addClass('has-connector')
            end
        end
    end

    return tostring(container)
end

return p