Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:PrizePool: Difference between revisions

From eSportsAmaze
No edit summary
No edit summary
Line 3: Line 3:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo


-- Helper: Format Money
-- Helper: Format Money (e.g., 500000 -> 5,00,000)
local function formatMoney(amount)
local function formatMoney(amount)
     if not amount then return "0" end
     if not amount then return "0" end
Line 14: Line 14:
end
end


-- Helper: Get Logo
-- Helper: Get Team Logo (Light/Dark aware)
local function getLogo(teamName)
local function getLogo(teamName)
     if not teamName or teamName == "" or teamName == "TBD" then return "" end
     if not teamName or teamName == "" or teamName == "TBD" then return "" end
Line 23: Line 23:
     local container = html.create('span')
     local container = html.create('span')
      
      
    -- Check for logo existence
     if mw.title.new('File:' .. light).exists then
     if mw.title.new('File:' .. light).exists then
         container:wikitext('[[File:' .. light .. '|link=|class=logo-lightmode]]')
         container:wikitext('[[File:' .. light .. '|link=|class=logo-lightmode]]')
Line 49: Line 50:
      
      
     -- ==========================================
     -- ==========================================
     -- COLUMN 1: RANKINGS
     -- COLUMN 1: RANKINGS (TEAMS)
     -- ==========================================
     -- ==========================================
     local colRank = grid:tag('div'):addClass('prize-col-rank')
     local colRank = grid:tag('div'):addClass('prize-col-rank')
Line 58: Line 59:
     local rankCount = 0
     local rankCount = 0
      
      
     -- Count rows that have EITHER a team OR a prize (Fixed Logic)
     -- Count rows that have EITHER a team OR a prize (to determine collapsing)
     for i = 1, 64 do
     for i = 1, 64 do
         if (args['team_'..i] and args['team_'..i] ~= "") or (args['prize_'..i] and args['prize_'..i] ~= "") then  
         if (args['team_'..i] and args['team_'..i] ~= "") or (args['prize_'..i] and args['prize_'..i] ~= "") then  
Line 65: Line 66:
     end
     end
      
      
     local collapseLimit = 10 -- Increased limit slightly for distribution lists
     local collapseLimit = 10 -- Show top 10, hide the rest
     local isCollapsible = (rankCount > collapseLimit)
     local isCollapsible = (rankCount > collapseLimit)
      
      
Line 86: Line 87:
             hasRankData = true
             hasRankData = true
              
              
             -- Cargo: Only store if we actually have a team (Don't store empty TBD rows)
             -- Cargo: Store only if team exists
             if team and team ~= "" and cargo and cargo.store then
             if team and team ~= "" and cargo and cargo.store then
                 cargo.store('PrizeMoney', {
                 cargo.store('PrizeMoney', {
Line 97: Line 98:
             end
             end
              
              
             -- Target Container
             -- Determine where to put this row (Main List or Hidden List)
             local targetContainer = rankList
             local targetContainer = rankList
             if isCollapsible and i > 4 then
             if isCollapsible and i > collapseLimit then
                 targetContainer = hiddenDiv
                 targetContainer = hiddenDiv
             end
             end
Line 116: Line 117:
             row:tag('div'):addClass('pz-rank'):wikitext(rankIcon)
             row:tag('div'):addClass('pz-rank'):wikitext(rankIcon)
              
              
             -- Team Info (Logic updated for TBD)
             -- Team Info
             local teamDiv = row:tag('div'):addClass('pz-team')
             local teamDiv = row:tag('div'):addClass('pz-team')
              
              
Line 139: Line 140:
     end
     end
      
      
     -- Assemble Lists
     -- Assemble Ranking List
     if not hasRankData then
     if not hasRankData then
         rankList:tag('div'):addClass('prize-empty')
         rankList:tag('div'):addClass('prize-empty')
Line 153: Line 154:
      
      
     -- ==========================================
     -- ==========================================
     -- COLUMN 2: SPECIAL AWARDS
     -- COLUMN 2: SPECIAL AWARDS (PLAYERS OR TEAMS)
     -- ==========================================
     -- ==========================================
     local colAward = grid:tag('div'):addClass('prize-col-award')
     local colAward = grid:tag('div'):addClass('prize-col-award')
Line 163: Line 164:
     for i = 1, 10 do
     for i = 1, 10 do
         local awardName = args['award_'..i]
         local awardName = args['award_'..i]
         local winner = args['award_'..i..'_winner']
         local winner = args['award_'..i..'_winner'] -- Player Name
         local team = args['award_'..i..'_team']
         local team = args['award_'..i..'_team']     -- Team Name
         local prize = args['award_'..i..'_prize']
         local prize = args['award_'..i..'_prize']
          
          
Line 171: Line 172:
             hasAwardData = true
             hasAwardData = true
              
              
             if winner and winner ~= "" and cargo and cargo.store then
            -- Cargo Storage Logic
             if (winner or team) and cargo and cargo.store then
                 cargo.store('PrizeMoney', {
                 cargo.store('PrizeMoney', {
                     tournament = tournamentName,
                     tournament = tournamentName,
                     placement = '',
                     placement = '',
                     team = team or '',
                     team = team or '',
                     player = winner,
                     player = winner or '', -- Empty string if it's a team award
                     prize = prize,
                     prize = prize,
                     award = awardName
                     award = awardName
Line 184: Line 186:
             local row = awardList:tag('div'):addClass('award-row')
             local row = awardList:tag('div'):addClass('award-row')
              
              
             -- Info
             -- Info Column
             local info = row:tag('div'):addClass('award-info')
             local info = row:tag('div'):addClass('award-info')
             info:tag('div'):addClass('award-name'):wikitext(awardName)
             info:tag('div'):addClass('award-name'):wikitext(awardName)
              
              
             local winDiv = info:tag('div'):addClass('award-winner')
             local winDiv = info:tag('div'):addClass('award-winner')
           
            -- DISPLAY LOGIC
             if winner and winner ~= "" then
             if winner and winner ~= "" then
                -- CASE 1: Player Won (e.g. MVP)
                -- Show Team Logo + Player Name
                 if team and team ~= "" then winDiv:wikitext(getLogo(team)) end
                 if team and team ~= "" then winDiv:wikitext(getLogo(team)) end
                 winDiv:wikitext(winner)
                 winDiv:wikitext(winner)
               
            elseif team and team ~= "" then
                -- CASE 2: Team Won (e.g. Fan Fav) - No Player Name
                -- Show Team Logo + Team Name
                winDiv:wikitext(getLogo(team))
                winDiv:wikitext('[[' .. team .. ']]')
               
             else
             else
                -- CASE 3: TBD
                 winDiv:wikitext("TBD"):css('color', 'var(--text-muted)'):css('font-weight', 'normal')
                 winDiv:wikitext("TBD"):css('color', 'var(--text-muted)'):css('font-weight', 'normal')
             end
             end
              
              
             -- Prize
             -- Prize Column
             if prize and prize ~= "" then
             if prize and prize ~= "" then
                 row:tag('div'):addClass('award-prize'):wikitext(currency .. formatMoney(prize))
                 row:tag('div'):addClass('award-prize'):wikitext(currency .. formatMoney(prize))

Revision as of 05:44, 27 January 2026

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

local p = {}
local html = mw.html
local cargo = mw.ext.cargo

-- Helper: Format Money (e.g., 500000 -> 5,00,000)
local function formatMoney(amount)
    if not amount then return "0" end
    local formatted = amount
    while true do  
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
        if (k==0) then break end
    end
    return formatted
end

-- Helper: Get Team Logo (Light/Dark aware)
local function getLogo(teamName)
    if not teamName or teamName == "" or teamName == "TBD" then return "" end
    local clean = teamName:gsub("'", "")
    local light = clean .. '.png'
    local dark = clean .. '_dark.png'
    
    local container = html.create('span')
    
    -- Check for logo existence
    if mw.title.new('File:' .. light).exists then
        container:wikitext('[[File:' .. light .. '|link=|class=logo-lightmode]]')
    else
        container:wikitext('[[File:Shield_team.png|link=|class=logo-lightmode]]')
    end
    
    if mw.title.new('File:' .. dark).exists then
        container:wikitext('[[File:' .. dark .. '|link=|class=logo-darkmode]]')
    elseif mw.title.new('File:' .. light).exists then
        container:wikitext('[[File:' .. light .. '|link=|class=logo-darkmode]]')
    else
        container:wikitext('[[File:Shield_team_dark.png|link=|class=logo-darkmode]]')
    end
    
    return tostring(container)
end

function p.main(frame)
    local args = frame:getParent().args
    local currency = args.currency or "₹"
    local tournamentName = args.tournament or mw.title.getCurrentTitle().text
    
    -- Main Grid Wrapper
    local grid = html.create('div'):addClass('prize-section-grid')
    
    -- ==========================================
    -- COLUMN 1: RANKINGS (TEAMS)
    -- ==========================================
    local colRank = grid:tag('div'):addClass('prize-col-rank')
    colRank:tag('div'):addClass('prize-header'):wikitext('Prize Pool Distribution')
    
    local rankList = colRank:tag('div'):addClass('prize-list')
    local hasRankData = false
    local rankCount = 0
    
    -- Count rows that have EITHER a team OR a prize (to determine collapsing)
    for i = 1, 64 do
        if (args['team_'..i] and args['team_'..i] ~= "") or (args['prize_'..i] and args['prize_'..i] ~= "") then 
            rankCount = rankCount + 1 
        end
    end
    
    local collapseLimit = 10 -- Show top 10, hide the rest
    local isCollapsible = (rankCount > collapseLimit)
    
    -- Collapsible Container
    local hiddenDiv = nil
    if isCollapsible then
        hiddenDiv = html.create('div')
            :addClass('mw-collapsible mw-collapsed')
            :attr('id', 'mw-customcollapsible-prizepool')
    end
    
    for i = 1, 64 do
        local place = args['place_'..i] or (i .. '.')
        local team = args['team_'..i]
        local prize = args['prize_'..i]
        local seed = args['seed_'..i]
        
        -- Generate row if we have Team OR Prize
        if (team and team ~= "") or (prize and prize ~= "") then
            hasRankData = true
            
            -- Cargo: Store only if team exists
            if team and team ~= "" and cargo and cargo.store then
                cargo.store('PrizeMoney', {
                    tournament = tournamentName,
                    placement = i,
                    team = team,
                    prize = prize,
                    award = ''
                })
            end
            
            -- Determine where to put this row (Main List or Hidden List)
            local targetContainer = rankList
            if isCollapsible and i > collapseLimit then
                targetContainer = hiddenDiv
            end
            
            -- Create Row
            local row = targetContainer:tag('div'):addClass('prize-row')
            
            -- Rank Badge
            local rankClass = 'rank-other'
            local rankIcon = place
            if i == 1 then rankClass = 'rank-1'; rankIcon = '🥇' end
            if i == 2 then rankClass = 'rank-2'; rankIcon = '🥈' end
            if i == 3 then rankClass = 'rank-3'; rankIcon = '🥉' end
            
            row:addClass(rankClass)
            row:tag('div'):addClass('pz-rank'):wikitext(rankIcon)
            
            -- Team Info
            local teamDiv = row:tag('div'):addClass('pz-team')
            
            if team and team ~= "" then
                -- Normal Team Display
                teamDiv:wikitext(getLogo(team))
                teamDiv:wikitext('[[' .. team .. ']]')
            else
                -- TBD Display (Grey)
                teamDiv:wikitext('TBD'):css('color', 'var(--text-muted)'):css('font-weight', 'normal')
            end
            
            -- Info (Prize + Seed)
            local infoDiv = row:tag('div'):addClass('pz-info')
            if prize and prize ~= "" then
                infoDiv:tag('span'):addClass('pz-prize'):wikitext(currency .. ' ' .. formatMoney(prize))
            end
            if seed and seed ~= "" then
                infoDiv:tag('span'):addClass('pz-seed'):wikitext(seed)
            end
        end
    end
    
    -- Assemble Ranking List
    if not hasRankData then
        rankList:tag('div'):addClass('prize-empty')
            :wikitext('<i class="fa-solid fa-trophy"></i><br>Prize Pool TBD')
    else
        if isCollapsible then
            rankList:wikitext(tostring(hiddenDiv))
            colRank:tag('div')
                :addClass('prize-show-more mw-customtoggle-prizepool')
                :wikitext('View Full Distribution <i class="fa-solid fa-chevron-down"></i>')
        end
    end
    
    -- ==========================================
    -- COLUMN 2: SPECIAL AWARDS (PLAYERS OR TEAMS)
    -- ==========================================
    local colAward = grid:tag('div'):addClass('prize-col-award')
    colAward:tag('div'):addClass('prize-header'):wikitext('Special Awards')
    
    local awardList = colAward:tag('div'):addClass('prize-list')
    local hasAwardData = false
    
    for i = 1, 10 do
        local awardName = args['award_'..i]
        local winner = args['award_'..i..'_winner'] -- Player Name
        local team = args['award_'..i..'_team']     -- Team Name
        local prize = args['award_'..i..'_prize']
        
        -- Show award if Name exists (even if no winner yet)
        if awardName and awardName ~= "" then
            hasAwardData = true
            
            -- Cargo Storage Logic
            if (winner or team) and cargo and cargo.store then
                cargo.store('PrizeMoney', {
                    tournament = tournamentName,
                    placement = '',
                    team = team or '',
                    player = winner or '', -- Empty string if it's a team award
                    prize = prize,
                    award = awardName
                })
            end
            
            local row = awardList:tag('div'):addClass('award-row')
            
            -- Info Column
            local info = row:tag('div'):addClass('award-info')
            info:tag('div'):addClass('award-name'):wikitext(awardName)
            
            local winDiv = info:tag('div'):addClass('award-winner')
            
            -- DISPLAY LOGIC
            if winner and winner ~= "" then
                -- CASE 1: Player Won (e.g. MVP)
                -- Show Team Logo + Player Name
                if team and team ~= "" then winDiv:wikitext(getLogo(team)) end
                winDiv:wikitext(winner)
                
            elseif team and team ~= "" then
                -- CASE 2: Team Won (e.g. Fan Fav) - No Player Name
                -- Show Team Logo + Team Name
                winDiv:wikitext(getLogo(team))
                winDiv:wikitext('[[' .. team .. ']]')
                
            else
                -- CASE 3: TBD
                winDiv:wikitext("TBD"):css('color', 'var(--text-muted)'):css('font-weight', 'normal')
            end
            
            -- Prize Column
            if prize and prize ~= "" then
                row:tag('div'):addClass('award-prize'):wikitext(currency .. formatMoney(prize))
            end
        end
    end
    
    if not hasAwardData then
        awardList:tag('div'):addClass('prize-empty')
            :wikitext('<i class="fa-solid fa-medal"></i><br>Awards TBD')
    end
    
    return tostring(grid)
end

return p