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
Created page with "local p = {} local cargo = mw.ext.cargo local html = mw.html local lang = mw.getLanguage('en') -- Helper: Format Number with Commas (Indian Locale is handled by your JS, we just output raw number wrapped in span) local function formatCurrency(amount) if not amount then return "0" end -- We output the raw number inside the span. Your MediaWiki:Common.js 'indian-currency' script -- picks this up and adds the ₹ symbol and correct commas automatically. re..."
 
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local html = mw.html
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local html = mw.html
local lang = mw.getLanguage('en')


-- Helper: Format Number with Commas (Indian Locale is handled by your JS, we just output raw number wrapped in span)
-- Helper: Format Money (10000 -> 10,000)
local function formatCurrency(amount)
local function formatMoney(amount)
     if not amount then return "0" end
     if not amount then return "0" end
     -- We output the raw number inside the span. Your MediaWiki:Common.js 'indian-currency' script
     local formatted = amount
     -- picks this up and adds the ₹ symbol and correct commas automatically.
     while true do 
    return '<span class="indian-currency">' .. amount .. '</span>'
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
        if (k==0) then break end
    end
    return formatted
end
end


-- Function 1: Display a Prize Row (for Tournament Pages)
-- Helper: Get Logo
function p.row(frame)
local function getLogo(teamName)
     local args = frame:getParent().args
     if not teamName or teamName == "" then return "" end
    local place = args.place or "0"
     local clean = teamName:gsub("'", "")
    local money = args.money or "0"
     local light = clean .. '.png'
     local recipient = args.recipient or ""
     local dark = clean .. '_dark.png'
    local team = args.recipient_team or args.team or ""
   
     local root = html.create('tr')
   
    -- 1. Rank Cell
     local rankCell = root:tag('td'):addClass('col-rank')
    if place == '1' then rankCell:wikitext('🏆')
    elseif place == '2' then rankCell:wikitext('🥈')
    elseif place == '3' then rankCell:wikitext('🥉')
    else rankCell:tag('span'):addClass('prize-rank-number'):wikitext('#' .. place)
    end
   
    -- 2. Money Cell
    root:tag('td'):addClass('col-money'):wikitext(formatCurrency(money))
   
    -- 3. Team/Recipient Cell
    local teamCell = root:tag('td'):addClass('col-team')
    local flexDiv = teamCell:tag('div'):addClass('prize-team-flex')
      
      
    -- Logo Logic
     local container = html.create('span')
     local logoName = (team ~= "" and team) or recipient
    local logoFile = logoName .. '.png'
    local logoBox = flexDiv:tag('span'):addClass('prize-logo-box')
      
      
     if mw.title.new('File:' .. logoFile).exists then
     if mw.title.new('File:' .. light).exists then
         logoBox:wikitext('[[File:' .. logoFile .. '|30px|link=' .. logoName .. ']]')
         container:wikitext('[[File:' .. light .. '|link=|class=logo-lightmode]]')
     else
     else
         logoBox:wikitext('[[File:Shield_team.png|30px|link=' .. logoName .. ']]')
         container:wikitext('[[File:Shield_team.png|link=|class=logo-lightmode]]')
     end
     end
      
      
    -- Name Logic
     if mw.title.new('File:' .. dark).exists then
     if recipient ~= "" then
         container:wikitext('[[File:' .. dark .. '|link=|class=logo-darkmode]]')
         flexDiv:tag('span'):addClass('prize-team-name'):wikitext('[[' .. recipient .. ']]')
    elseif mw.title.new('File:' .. light).exists then
        container:wikitext('[[File:' .. light .. '|link=|class=logo-darkmode]]')
     else
     else
         flexDiv:tag('span'):addClass('prize-team-name'):css('color','#888'):css('font-style','italic'):css('padding-left','5px'):wikitext('TBD')
         container:wikitext('[[File:Shield_team_dark.png|link=|class=logo-darkmode]]')
     end
     end
      
      
     return tostring(root)
     return tostring(container)
end
end


-- Function 2: Team History Table (For Team Pages)
function p.main(frame)
function p.history(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local teamName = args.team or mw.title.getCurrentTitle().text
     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
    -- ==========================================
    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 Total Entries first to decide on collapsing
    for i = 1, 64 do
        if args['team_'..i] and args['team_'..i] ~= "" then rankCount = rankCount + 1 end
    end
      
      
    -- Query Cargo
     local collapseLimit = 7
    local tables = "Tournament_Prizes"
     local isCollapsible = (rankCount > collapseLimit)
     local fields = "tournament, place, money"
     local queryArgs = {
        where = "recipient = '" .. teamName .. "' OR recipient_team = '" .. teamName .. "'",
        orderBy = "money DESC",
        limit = 50
    }
      
      
     local results = cargo.query(tables, fields, queryArgs)
    -- Collapsible Container (for ranks 5+)
     local hiddenDiv = nil
    if isCollapsible then
        hiddenDiv = html.create('div')
            :addClass('mw-collapsible mw-collapsed')
            :attr('id', 'mw-customcollapsible-prizepool')
    end
      
      
     local container = html.create('div')
     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]
       
        if team and team ~= "" then
            hasRankData = true
           
            -- Store in Cargo
            if cargo and cargo.store then
                cargo.store('PrizeMoney', {
                    tournament = tournamentName,
                    placement = i,
                    team = team,
                    prize = prize,
                    award = ''
                })
            end
           
            -- Determine if this row goes in the main list or the hidden list
            local targetContainer = rankList
            if isCollapsible and i > 4 then
                targetContainer = hiddenDiv
            end
           
            -- Create Row
            local row = targetContainer:tag('div'):addClass('prize-row')
           
            -- Rank Badge (1=Gold, 2=Silver, 3=Bronze)
            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')
            teamDiv:wikitext(getLogo(team))
            teamDiv:wikitext('[[' .. team .. ']]')
           
            -- 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
      
      
     -- A. Calculate Total Earnings
     -- Assemble the lists
     local totalMoney = 0
     if not hasRankData then
     if #results > 0 then
        rankList:tag('div'):addClass('prize-empty')
        for _, row in ipairs(results) do
            :wikitext('<i class="fa-solid fa-trophy"></i><br>Prize Pool TBD')
             totalMoney = totalMoney + (tonumber(row.money) or 0)
     else
        if isCollapsible then
            -- Append the hidden div to the main list
            rankList:wikitext(tostring(hiddenDiv))
            -- Add the Toggle Button OUTSIDE the list (visually connected via CSS)
             colRank:tag('div')
                :addClass('prize-show-more mw-customtoggle-prizepool')
                :wikitext('View Full Standings <i class="fa-solid fa-chevron-down"></i>')
         end
         end
     end
     end
      
      
     -- B. Display Summary Box
     -- ==========================================
     container:tag('div')
    -- COLUMN 2: SPECIAL AWARDS
        :css('background', 'var(--bg-header)')
    -- ==========================================
        :css('padding', '10px')
     local colAward = grid:tag('div'):addClass('prize-col-award')
        :css('border', '1px solid var(--border-main)')
    colAward:tag('div'):addClass('prize-header'):wikitext('Special Awards')
        :css('border-radius', '6px')
   
        :css('margin-bottom', '10px')
    local awardList = colAward:tag('div'):addClass('prize-list')
        :css('width', '100%')
    local hasAwardData = false
        :css('max-width', '500px')
   
         :css('font-weight', 'bold')
    for i = 1, 10 do
         :css('text-align', 'center')
         local awardName = args['award_'..i]
         :css('font-size', '1.1em')
         local winner = args['award_'..i..'_winner']
         :wikitext('Total Estimated Earnings: ' .. formatCurrency(totalMoney))
         local team = args['award_'..i..'_team']
         local prize = args['award_'..i..'_prize']
          
          
    -- C. Display History Table
        if awardName and awardName ~= "" then
    local tbl = container:tag('table')
            hasAwardData = true
        :addClass('wikitable flat-table sortable')
           
        :css('width', '100%')
            -- Store in Cargo
        :css('max-width', '600px')
            if cargo and cargo.store then
        :css('text-align', 'center')
                cargo.store('PrizeMoney', {
       
                    tournament = tournamentName,
    local header = tbl:tag('tr')
                    placement = '',
    header:tag('th'):css('text-align', 'left'):wikitext('Tournament')
                    team = team or '',
    header:tag('th'):wikitext('Ranked')
                    player = winner,
    header:tag('th'):css('text-align', 'right'):wikitext('Prize Money')
                    prize = prize,
                    award = awardName
                })
            end
           
            local row = awardList:tag('div'):addClass('award-row')
           
            -- Left Side: Name
            local info = row:tag('div'):addClass('award-info')
            info:tag('div'):addClass('award-name'):wikitext(awardName)
           
            local winDiv = info:tag('div'):addClass('award-winner')
            if team and team ~= "" then
                winDiv:wikitext(getLogo(team))
            end
            winDiv:wikitext(winner or "TBD")
           
            -- Right Side: Prize
            if prize and prize ~= "" then
                row:tag('div'):addClass('award-prize'):wikitext(currency .. formatMoney(prize))
            end
        end
    end
      
      
     if #results > 0 then
     if not hasAwardData then
         for _, row in ipairs(results) do
         awardList:tag('div'):addClass('prize-empty')
            local tr = tbl:tag('tr')
             :wikitext('<i class="fa-solid fa-medal"></i><br>Awards TBD')
            tr:tag('td'):css('text-align', 'left'):css('font-weight', 'bold'):wikitext('[[' .. row.tournament .. ']]')
             tr:tag('td'):wikitext("'''" .. row.place .. "'''")
            tr:tag('td'):css('text-align', 'right'):wikitext(formatCurrency(row.money))
        end
    else
        container:tag('div'):css('padding','15px'):css('color','#666'):wikitext('No prize data recorded yet.')
     end
     end
      
      
     return tostring(container)
     return tostring(grid)
end
end


return p
return p

Revision as of 05:20, 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 (10000 -> 10,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 Logo
local function getLogo(teamName)
    if not teamName or teamName == "" then return "" end
    local clean = teamName:gsub("'", "")
    local light = clean .. '.png'
    local dark = clean .. '_dark.png'
    
    local container = html.create('span')
    
    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
    -- ==========================================
    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 Total Entries first to decide on collapsing
    for i = 1, 64 do
        if args['team_'..i] and args['team_'..i] ~= "" then rankCount = rankCount + 1 end
    end
    
    local collapseLimit = 7
    local isCollapsible = (rankCount > collapseLimit)
    
    -- Collapsible Container (for ranks 5+)
    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]
        
        if team and team ~= "" then
            hasRankData = true
            
            -- Store in Cargo
            if cargo and cargo.store then
                cargo.store('PrizeMoney', {
                    tournament = tournamentName,
                    placement = i,
                    team = team,
                    prize = prize,
                    award = ''
                })
            end
            
            -- Determine if this row goes in the main list or the hidden list
            local targetContainer = rankList
            if isCollapsible and i > 4 then
                targetContainer = hiddenDiv
            end
            
            -- Create Row
            local row = targetContainer:tag('div'):addClass('prize-row')
            
            -- Rank Badge (1=Gold, 2=Silver, 3=Bronze)
            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')
            teamDiv:wikitext(getLogo(team))
            teamDiv:wikitext('[[' .. team .. ']]')
            
            -- 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 the lists
    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
            -- Append the hidden div to the main list
            rankList:wikitext(tostring(hiddenDiv))
            -- Add the Toggle Button OUTSIDE the list (visually connected via CSS)
            colRank:tag('div')
                :addClass('prize-show-more mw-customtoggle-prizepool')
                :wikitext('View Full Standings <i class="fa-solid fa-chevron-down"></i>')
        end
    end
    
    -- ==========================================
    -- COLUMN 2: SPECIAL AWARDS
    -- ==========================================
    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']
        local team = args['award_'..i..'_team']
        local prize = args['award_'..i..'_prize']
        
        if awardName and awardName ~= "" then
            hasAwardData = true
            
            -- Store in Cargo
            if cargo and cargo.store then
                cargo.store('PrizeMoney', {
                    tournament = tournamentName,
                    placement = '',
                    team = team or '',
                    player = winner,
                    prize = prize,
                    award = awardName
                })
            end
            
            local row = awardList:tag('div'):addClass('award-row')
            
            -- Left Side: Name
            local info = row:tag('div'):addClass('award-info')
            info:tag('div'):addClass('award-name'):wikitext(awardName)
            
            local winDiv = info:tag('div'):addClass('award-winner')
            if team and team ~= "" then
                winDiv:wikitext(getLogo(team))
            end
            winDiv:wikitext(winner or "TBD")
            
            -- Right Side: Prize
            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