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

Module:Tournament: Difference between revisions

From eSportsAmaze
No edit summary
No edit summary
Line 7: Line 7:
-- ============================================================
-- ============================================================


-- Helper: Currency Formatter (Indian Format)
-- Helper: Currency Formatter
local function formatCurrency(amount)
local function formatCurrency(amount)
     if not amount or amount == "" or amount == "0" then return "TBD" end
     if not amount or amount == "" or amount == "0" then return "TBD" end
   
    -- Check for currency symbol ($ or ₹)
     local currency = "₹"  
     local currency = "₹"  
     if string.find(amount, "%$") then currency = "$" end
     if string.find(amount, "%$") then currency = "$" end
   
    -- Clean string
     local n = tostring(amount):gsub(",", ""):gsub("₹", ""):gsub("%$", "")
     local n = tostring(amount):gsub(",", ""):gsub("₹", ""):gsub("%$", "")
      
      
    -- Format Logic
     if #n <= 3 then return currency .. " " .. n end
     if #n <= 3 then return currency .. " " .. n end
      
      
Line 29: Line 24:
end
end


-- Helper: Get Clean Title (Removes "BGMI/Tournaments/" path)
-- Helper: Clean Title
local function getCleanTitle(pageLink)
local function getCleanTitle(pageLink)
     if not pageLink then return "" end
     if not pageLink then return "" end
     local title = mw.title.new(pageLink)
     local title = mw.title.new(pageLink)
     if title then  
     if title then return title.subpageText end
        return title.subpageText -- Returns only text after the last "/"
    return pageLink
end
 
-- Helper: Tournament Logo (Small for Lists)
local function getTourneyLogo(imageFile)
    local container = html.create('div'):addClass('tr-event-logo')
   
    if imageFile and imageFile ~= "" then
        -- We explicitly size it to 40px for list views
        container:wikitext('[[File:' .. imageFile .. '|40px|link=]]')
    else
        -- Fallback icon if no image
        container:wikitext('<i class="fa-solid fa-trophy" style="color:var(--text-muted); opacity:0.3;"></i>')
     end
     end
     return pageLink
   
     return tostring(container)
end
end


-- Helper: Logo Logic (Light/Dark/Shield)
-- Helper: Team Logo Logic (For Infobox/Winner)
local function getLogo(pageName, image, imageDark)
local function getLogo(pageName, image, imageDark)
     local lightFile = (image ~= "" and image) or (pageName .. '.png')
     local lightFile = (image ~= "" and image) or (pageName .. '.png')
Line 49: Line 57:
     local container = html.create('div'):addClass('infobox-image')
     local container = html.create('div'):addClass('infobox-image')
      
      
    -- Light Mode
     local lDiv = container:tag('div'):addClass('logo-lightmode')
     local lDiv = container:tag('div'):addClass('logo-lightmode')
     if hasLight then
     if hasLight then lDiv:wikitext('[[File:' .. lightFile .. '|200px]]') else lDiv:wikitext('[[File:Shield_team.png|200px]]') end
        lDiv:wikitext('[[File:' .. lightFile .. '|200px]]')
    else
        lDiv:wikitext('[[File:Shield_team.png|200px]]')
    end
      
      
    -- Dark Mode
     local dDiv = container:tag('div'):addClass('logo-darkmode')
     local dDiv = container:tag('div'):addClass('logo-darkmode')
     if hasDark then
     if hasDark then dDiv:wikitext('[[File:' .. darkFile .. '|200px]]') elseif hasLight then dDiv:wikitext('[[File:' .. lightFile .. '|200px]]') else dDiv:wikitext('[[File:Shield_team_dark.png|200px]]') end
        dDiv:wikitext('[[File:' .. darkFile .. '|200px]]')
    elseif hasLight then
        dDiv:wikitext('[[File:' .. lightFile .. '|200px]]')
    else
        dDiv:wikitext('[[File:Shield_team_dark.png|200px]]')
    end
      
      
     return container
     return container
end
end


-- Helper: Small Logo for Lists
-- Helper: Small Team Logo
local function getSmallLogo(teamName)
local function getSmallLogo(teamName)
     if not teamName or teamName == "" then return "" end
     if not teamName or teamName == "" then return "" end
Line 78: Line 74:
      
      
     local container = html.create('span'):addClass('tr-logo')
     local container = html.create('span'):addClass('tr-logo')
   
     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:' .. light).exists then
     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
        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)
     return tostring(container)
end
end


-- Helper: Date Ranger (Jan 20 – Jan 25, 2026)
-- Helper: Date Ranger
local function formatDateRange(startStr, endStr)
local function formatDateRange(startStr, endStr)
     if not startStr or startStr == "" then return "TBA" end
     if not startStr or startStr == "" then return "TBA" end
   
    -- If there is an end date
     if endStr and endStr ~= "" and endStr ~= startStr then
     if endStr and endStr ~= "" and endStr ~= startStr then
         local s = lang:formatDate('d M', startStr)
         local s = lang:formatDate('d M', startStr)
         local e = lang:formatDate('d M, Y', endStr)
         local e = lang:formatDate('d M, Y', endStr)
         return s .. " –<br>" .. e -- <br> helps mobile layout
         return s .. " –<br>" .. e  
     else
     else
        -- Single date only
         return lang:formatDate('d M, Y', startStr)
         return lang:formatDate('d M, Y', startStr)
     end
     end
Line 120: Line 101:


-- ============================================================
-- ============================================================
-- MAIN 1: TOURNAMENT INFOBOX (Now Stores to Database!)
-- MAIN 1: TOURNAMENT INFOBOX
-- ============================================================
-- ============================================================
function p.infobox(frame)
function p.infobox(frame)
Line 127: Line 108:
     local cleanName = mw.title.getCurrentTitle().subpageText
     local cleanName = mw.title.getCurrentTitle().subpageText
      
      
     -- 1. STORE DATA TO CARGO
     -- STORE TO CARGO
    -- This saves the info so we can query it later
     if mw.ext.cargo and mw.ext.cargo.store then
     if mw.ext.cargo and mw.ext.cargo.store then
         mw.ext.cargo.store('Tournaments', {
         mw.ext.cargo.store('Tournaments', {
             _pageName = mw.title.getCurrentTitle().prefixedText, -- Stores full path
             _pageName = mw.title.getCurrentTitle().prefixedText,
             name = args.name or cleanName,
             name = args.name or cleanName,
             start_date = args.start_date,
             start_date = args.start_date,
             end_date = args.end_date,
             end_date = args.end_date,
             organizer = args.organizer,
             organizer = args.organizer,
             prize_pool = args.prizepool, -- Note: Input arg is 'prizepool', DB field is 'prize_pool'
             prize_pool = args.prizepool,
             winner = args.winner,
             winner = args.winner,
             type = args.type,
             type = args.type,
Line 143: Line 123:
     end
     end


    -- 2. GENERATE VISUAL INFOBOX
     local root = html.create('div'):addClass('infobox')
     local root = html.create('div'):addClass('infobox')
   
     root:tag('div'):addClass('infobox-header'):wikitext(args.name or cleanName)
     root:tag('div'):addClass('infobox-header'):wikitext(args.name or cleanName)
     root:node(getLogo(page, args.image, args.image_dark))
     root:node(getLogo(page, args.image, args.image_dark))
      
      
     local data = root:tag('div'):addClass('infobox-data-container')
     local data = root:tag('div'):addClass('infobox-data-container')
   
     if args.series then addRow(data, "Series", '[[' .. args.series .. ']]') end
     if args.series then addRow(data, "Series", '[[' .. args.series .. ']]') end
   
     addRow(data, "Organizer", args.organizer)
     addRow(data, "Organizer", args.organizer)
     addRow(data, "Type", args.type)
     addRow(data, "Type", args.type)
     addRow(data, "Location", args.location)
     addRow(data, "Location", args.location)
   
     if args.prizepool then addRow(data, "Prize Pool", formatCurrency(args.prizepool)) end
     if args.prizepool then addRow(data, "Prize Pool", formatCurrency(args.prizepool)) end
   
     addRow(data, "Start Date", args.start_date)
     addRow(data, "Start Date", args.start_date)
     addRow(data, "End Date", args.end_date)
     addRow(data, "End Date", args.end_date)
   
     if args.winner then addRow(data, "Winner", "'''[[" .. args.winner .. "]]'''") end
     if args.winner then addRow(data, "Winner", "'''[[" .. args.winner .. "]]'''") end


Line 168: Line 141:


-- ============================================================
-- ============================================================
-- MAIN 2: LIST ROW (Tournaments Page) - NEW CARD DESIGN
-- MAIN 2: LIST ROW (Tournaments Page)
-- ============================================================
-- ============================================================
function p.listRow(frame)
function p.listRow(frame)
     local args = frame.args -- Arguments passed via #invoke
     local args = frame.args
     local page = args.Page or ""
     local page = args.Page or ""
     local name = getCleanTitle(page)
     local name = getCleanTitle(page)
Line 177: Line 150:
     local endDate = args.end_date or ""
     local endDate = args.end_date or ""
      
      
    -- Container (Div instead of Tr)
     local row = html.create('div'):addClass('tourney-row')
     local row = html.create('div'):addClass('tourney-row')
      
      
    -- 1. Date Column
     row:tag('div'):addClass('tr-date'):wikitext(formatDateRange(startDate, endDate))
     row:tag('div'):addClass('tr-date')
      
      :wikitext(formatDateRange(startDate, endDate))
       
     -- 2. Info Column (Name + Organizer)
     local info = row:tag('div'):addClass('tr-info')
     local info = row:tag('div'):addClass('tr-info')
     info:tag('div'):addClass('tr-name'):wikitext('[[' .. page .. '|' .. name .. ']]')
     info:tag('div'):addClass('tr-name'):wikitext('[[' .. page .. '|' .. name .. ']]')
   
     if args.organizer then info:tag('div'):addClass('tr-org'):wikitext(args.organizer) end
     if args.organizer then
        info:tag('div'):addClass('tr-org'):wikitext(args.organizer)
    end
          
          
    -- 3. Winner Column
     local winDiv = row:tag('div'):addClass('tr-winner mobile-hide')
     local winDiv = row:tag('div'):addClass('tr-winner mobile-hide')
     if args.winner and args.winner ~= "" then
     if args.winner and args.winner ~= "" then
Line 201: Line 166:
     end
     end
          
          
    -- 4. Prize Pool Column
     local prizeDiv = row:tag('div'):addClass('tr-prize')
     local prizeDiv = row:tag('div'):addClass('tr-prize')
     prizeDiv:wikitext(formatCurrency(args.prize_pool))
     prizeDiv:wikitext(formatCurrency(args.prize_pool))
Line 209: Line 173:


-- ============================================================
-- ============================================================
-- MAIN 3: LIST ROW MAIN (Homepage) - COMPACT CARD
-- MAIN 3: LIST ROW MAIN (Homepage - WITH LOGO)
-- ============================================================
-- ============================================================
function p.listRowMain(frame)
function p.listRowMain(frame)
Line 217: Line 181:
     local startDate = args.start_date or ""
     local startDate = args.start_date or ""
     local endDate = args.end_date or ""
     local endDate = args.end_date or ""
    local image = args.image or ""
      
      
     local row = html.create('div'):addClass('tourney-row tr-compact')
     local row = html.create('div'):addClass('tourney-row tr-compact')
      
      
     -- 1. Date Column (Simplified)
     -- 1. Date
     row:tag('div'):addClass('tr-date')
     row:tag('div'):addClass('tr-date'):wikitext(formatDateRange(startDate, endDate))
      :wikitext(formatDateRange(startDate, endDate))
   
       
     -- 2. Logo (New Column)
     -- 2. Info Column
    row:tag('div'):addClass('tr-event-logo-col')
      :wikitext(getTourneyLogo(image))
 
    -- 3. Info
     local info = row:tag('div'):addClass('tr-info')
     local info = row:tag('div'):addClass('tr-info')
     info:tag('div'):addClass('tr-name'):wikitext('[[' .. page .. '|' .. name .. ']]')
     info:tag('div'):addClass('tr-name'):wikitext('[[' .. page .. '|' .. name .. ']]')
     if args.organizer then
     if args.organizer then info:tag('div'):addClass('tr-org'):wikitext(args.organizer) end
        info:tag('div'):addClass('tr-org'):wikitext(args.organizer)
    end
          
          
     -- 3. Prize Pool Column
     -- 4. Prize
     local prizeDiv = row:tag('div'):addClass('tr-prize')
     local prizeDiv = row:tag('div'):addClass('tr-prize')
     prizeDiv:wikitext(formatCurrency(args.prize_pool))
     prizeDiv:wikitext(formatCurrency(args.prize_pool))

Revision as of 12:50, 27 January 2026

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

local p = {}
local html = mw.html
local lang = mw.getContentLanguage()

-- ============================================================
-- HELPER FUNCTIONS
-- ============================================================

-- Helper: Currency Formatter
local function formatCurrency(amount)
    if not amount or amount == "" or amount == "0" then return "TBD" end
    local currency = "₹" 
    if string.find(amount, "%$") then currency = "$" end
    local n = tostring(amount):gsub(",", ""):gsub("₹", ""):gsub("%$", "")
    
    if #n <= 3 then return currency .. " " .. n end
    
    local last3 = n:sub(-3)
    local rest = n:sub(1, -4)
    local formattedRest = rest:reverse():gsub("(%d%d)", "%1,"):reverse()
    if formattedRest:sub(1, 1) == "," then formattedRest = formattedRest:sub(2) end
    
    return '<span class="pz-prize">' .. currency .. " " .. formattedRest .. "," .. last3 .. '</span>'
end

-- Helper: Clean Title
local function getCleanTitle(pageLink)
    if not pageLink then return "" end
    local title = mw.title.new(pageLink)
    if title then return title.subpageText end
    return pageLink
end

-- Helper: Tournament Logo (Small for Lists)
local function getTourneyLogo(imageFile)
    local container = html.create('div'):addClass('tr-event-logo')
    
    if imageFile and imageFile ~= "" then
        -- We explicitly size it to 40px for list views
        container:wikitext('[[File:' .. imageFile .. '|40px|link=]]')
    else
        -- Fallback icon if no image
        container:wikitext('<i class="fa-solid fa-trophy" style="color:var(--text-muted); opacity:0.3;"></i>')
    end
    
    return tostring(container)
end

-- Helper: Team Logo Logic (For Infobox/Winner)
local function getLogo(pageName, image, imageDark)
    local lightFile = (image ~= "" and image) or (pageName .. '.png')
    local darkFile = (imageDark ~= "" and imageDark) or (pageName .. '_dark.png')
    
    local hasLight = mw.title.new('File:' .. lightFile).exists
    local hasDark = mw.title.new('File:' .. darkFile).exists
    
    local container = html.create('div'):addClass('infobox-image')
    
    local lDiv = container:tag('div'):addClass('logo-lightmode')
    if hasLight then lDiv:wikitext('[[File:' .. lightFile .. '|200px]]') else lDiv:wikitext('[[File:Shield_team.png|200px]]') end
    
    local dDiv = container:tag('div'):addClass('logo-darkmode')
    if hasDark then dDiv:wikitext('[[File:' .. darkFile .. '|200px]]') elseif hasLight then dDiv:wikitext('[[File:' .. lightFile .. '|200px]]') else dDiv:wikitext('[[File:Shield_team_dark.png|200px]]') end
    
    return container
end

-- Helper: Small Team Logo
local function getSmallLogo(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'):addClass('tr-logo')
    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

-- Helper: Date Ranger
local function formatDateRange(startStr, endStr)
    if not startStr or startStr == "" then return "TBA" end
    if endStr and endStr ~= "" and endStr ~= startStr then
        local s = lang:formatDate('d M', startStr)
        local e = lang:formatDate('d M, Y', endStr)
        return s .. " –<br>" .. e 
    else
        return lang:formatDate('d M, Y', startStr)
    end
end

-- Helper: Add Infobox Row
local function addRow(container, label, value)
    if value and value ~= "" then
        container:tag('div'):addClass('infobox-row')
            :tag('div'):addClass('infobox-label'):wikitext(label):done()
            :tag('div'):addClass('infobox-data'):wikitext(value):done()
    end
end

-- ============================================================
-- MAIN 1: TOURNAMENT INFOBOX
-- ============================================================
function p.infobox(frame)
    local args = frame:getParent().args
    local page = args.name or mw.title.getCurrentTitle().text
    local cleanName = mw.title.getCurrentTitle().subpageText
    
    -- STORE TO CARGO
    if mw.ext.cargo and mw.ext.cargo.store then
        mw.ext.cargo.store('Tournaments', {
            _pageName = mw.title.getCurrentTitle().prefixedText,
            name = args.name or cleanName,
            start_date = args.start_date,
            end_date = args.end_date,
            organizer = args.organizer,
            prize_pool = args.prizepool,
            winner = args.winner,
            type = args.type,
            image = args.image
        })
    end

    local root = html.create('div'):addClass('infobox')
    root:tag('div'):addClass('infobox-header'):wikitext(args.name or cleanName)
    root:node(getLogo(page, args.image, args.image_dark))
    
    local data = root:tag('div'):addClass('infobox-data-container')
    if args.series then addRow(data, "Series", '[[' .. args.series .. ']]') end
    addRow(data, "Organizer", args.organizer)
    addRow(data, "Type", args.type)
    addRow(data, "Location", args.location)
    if args.prizepool then addRow(data, "Prize Pool", formatCurrency(args.prizepool)) end
    addRow(data, "Start Date", args.start_date)
    addRow(data, "End Date", args.end_date)
    if args.winner then addRow(data, "Winner", "'''[[" .. args.winner .. "]]'''") end

    return tostring(root)
end

-- ============================================================
-- MAIN 2: LIST ROW (Tournaments Page)
-- ============================================================
function p.listRow(frame)
    local args = frame.args
    local page = args.Page or ""
    local name = getCleanTitle(page)
    local startDate = args.start_date or ""
    local endDate = args.end_date or ""
    
    local row = html.create('div'):addClass('tourney-row')
    
    row:tag('div'):addClass('tr-date'):wikitext(formatDateRange(startDate, endDate))
    
    local info = row:tag('div'):addClass('tr-info')
    info:tag('div'):addClass('tr-name'):wikitext('[[' .. page .. '|' .. name .. ']]')
    if args.organizer then info:tag('div'):addClass('tr-org'):wikitext(args.organizer) end
        
    local winDiv = row:tag('div'):addClass('tr-winner mobile-hide')
    if args.winner and args.winner ~= "" then
        winDiv:wikitext(getSmallLogo(args.winner))
        winDiv:tag('span'):wikitext(args.winner)
    else
        winDiv:tag('span'):addClass('dim-text'):wikitext('-')
    end
        
    local prizeDiv = row:tag('div'):addClass('tr-prize')
    prizeDiv:wikitext(formatCurrency(args.prize_pool))
        
    return tostring(row)
end

-- ============================================================
-- MAIN 3: LIST ROW MAIN (Homepage - WITH LOGO)
-- ============================================================
function p.listRowMain(frame)
    local args = frame.args
    local page = args.Page or ""
    local name = getCleanTitle(page)
    local startDate = args.start_date or ""
    local endDate = args.end_date or ""
    local image = args.image or ""
    
    local row = html.create('div'):addClass('tourney-row tr-compact')
    
    -- 1. Date
    row:tag('div'):addClass('tr-date'):wikitext(formatDateRange(startDate, endDate))
    
    -- 2. Logo (New Column)
    row:tag('div'):addClass('tr-event-logo-col')
       :wikitext(getTourneyLogo(image))

    -- 3. Info
    local info = row:tag('div'):addClass('tr-info')
    info:tag('div'):addClass('tr-name'):wikitext('[[' .. page .. '|' .. name .. ']]')
    if args.organizer then info:tag('div'):addClass('tr-org'):wikitext(args.organizer) end
        
    -- 4. Prize
    local prizeDiv = row:tag('div'):addClass('tr-prize')
    prizeDiv:wikitext(formatCurrency(args.prize_pool))
        
    return tostring(row)
end

return p