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

Module:Participant: Difference between revisions

From eSportsAmaze
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
local p = {}
local html = mw.html
local html = mw.html
local cargo = mw.ext.cargo -- Load Cargo module


-- Helper: Check file existence
-- Helper: Check file existence
Line 70: Line 71:
end
end


-- PUBLIC 1: Single Card (Old usage)
-- PUBLIC 1: Single Card (Old usage - Display Only)
function p.card(frame)
function p.card(frame)
     return buildCard(frame:getParent().args)
     return buildCard(frame:getParent().args)
end
end


-- PUBLIC 2: Group (New usage)
-- PUBLIC 2: Group (New usage - Store + Display)
function p.group(frame)
function p.group(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local count = tonumber(args.count) or 4 -- Default to 4 if not specified
     local count = tonumber(args.count) or 4
     local tournamentName = args.tournament or mw.title.getCurrentTitle().text
     local tournamentName = args.tournament or mw.title.getCurrentTitle().text
      
      
Line 88: Line 89:
          
          
         if team and team ~= "" then
         if team and team ~= "" then
             -- 1. Store in Cargo
             -- 1. Store in Cargo (Using Native Lua function)
             frame:callParserFunction('#cargo_store', {
             if cargo and cargo.store then
                 _table = "Tournament_Teams",
                 cargo.store("Tournament_Teams", {
                tournament = tournamentName,
                    tournament = tournamentName,
                team = team,
                    team = team,
                seeding = args[prefix .. 'seed'],
                    seeding = args[prefix .. 'seed'],
                p1 = args[prefix .. 'p1'],
                    p1 = args[prefix .. 'p1'],
                p2 = args[prefix .. 'p2'],
                    p2 = args[prefix .. 'p2'],
                p3 = args[prefix .. 'p3'],
                    p3 = args[prefix .. 'p3'],
                p4 = args[prefix .. 'p4'],
                    p4 = args[prefix .. 'p4'],
                p5 = args[prefix .. 'p5'],
                    p5 = args[prefix .. 'p5'],
                p6 = args[prefix .. 'p6'],
                    p6 = args[prefix .. 'p6'],
                coach = args[prefix .. 'c'], -- Short code 'c' for coach
                    coach = args[prefix .. 'c'],
                analyst = args[prefix .. 'a'] -- Short code 'a' for analyst
                    analyst = args[prefix .. 'a']
            })
                })
            end
              
              
             -- 2. Build HTML
             -- 2. Build HTML

Revision as of 01:56, 25 January 2026

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

local p = {}
local html = mw.html
local cargo = mw.ext.cargo -- Load Cargo module

-- Helper: Check file existence
local function fileExists(filename)
    return mw.title.new('File:' .. filename).exists
end

-- INTERNAL: The logic to build ONE card (Pure HTML)
local function buildCard(data)
    local team = data.team or ""
    local seeding = data.seeding or ""
    
    local root = html.create('div'):addClass('roster-card')
    
    -- HEADER
    local header = root:tag('div'):addClass('roster-header')
    local headerContent = header:tag('div'):addClass('header-content')
    
    -- Logo
    local logoDiv = headerContent:tag('div'):addClass('roster-logo')
    local lightFile = team .. '.png'
    local darkFile = team .. '_dark.png'
    
    local lDiv = logoDiv:tag('div'):addClass('logo-lightmode')
    lDiv:wikitext(fileExists(lightFile) and ('[[File:'..lightFile..'|link=]]') or '[[File:Shield_team.png|link=]]')
    
    local dDiv = logoDiv:tag('div'):addClass('logo-darkmode')
    if fileExists(darkFile) then
        dDiv:wikitext('[[File:'..darkFile..'|link=]]')
    elseif fileExists(lightFile) then
        dDiv:wikitext('[[File:'..lightFile..'|link=]]')
    else
        dDiv:wikitext('[[File:Shield_team_dark.png|link=]]')
    end
    
    -- Name
    headerContent:tag('div'):addClass('roster-name'):wikitext('[[' .. team .. ']]')
    
    -- Seeding
    if seeding ~= "" then
        root:tag('div'):addClass('roster-subheader'):wikitext(seeding)
    end
    
    -- PLAYERS
    local contentRows = root:tag('div'):addClass('roster-content-rows')
    local players = {data.p1, data.p2, data.p3, data.p4, data.p5, data.p6}
    local playerCount = 0
    for _, pl in ipairs(players) do if pl and pl ~= "" then playerCount = playerCount + 1 end end
    
    local playerInner = contentRows:tag('div'):addClass('roster-players-inner'):addClass('count-' .. playerCount)
    for _, pl in ipairs(players) do
        if pl and pl ~= "" then
            playerInner:tag('div'):addClass('roster-row player'):wikitext('[[' .. pl .. ']]')
        end
    end
    
    -- STAFF
    if (data.coach and data.coach ~= "") or (data.analyst and data.analyst ~= "") then
        local staffInner = contentRows:tag('div'):addClass('roster-staff-inner')
        if data.coach and data.coach ~= "" then
            staffInner:tag('div'):addClass('roster-row staff'):wikitext('C: [[' .. data.coach .. ']]')
        end
        if data.analyst and data.analyst ~= "" then
            staffInner:tag('div'):addClass('roster-row staff'):wikitext('A: [[' .. data.analyst .. ']]')
        end
    end
    
    return tostring(root)
end

-- PUBLIC 1: Single Card (Old usage - Display Only)
function p.card(frame)
    return buildCard(frame:getParent().args)
end

-- PUBLIC 2: Group (New usage - Store + Display)
function p.group(frame)
    local args = frame:getParent().args
    local count = tonumber(args.count) or 4
    local tournamentName = args.tournament or mw.title.getCurrentTitle().text
    
    local output = ""
    
    for i = 1, count do
        local prefix = 't' .. i -- e.g., t1, t2, t3
        local team = args[prefix]
        
        if team and team ~= "" then
            -- 1. Store in Cargo (Using Native Lua function)
            if cargo and cargo.store then
                cargo.store("Tournament_Teams", {
                    tournament = tournamentName,
                    team = team,
                    seeding = args[prefix .. 'seed'],
                    p1 = args[prefix .. 'p1'],
                    p2 = args[prefix .. 'p2'],
                    p3 = args[prefix .. 'p3'],
                    p4 = args[prefix .. 'p4'],
                    p5 = args[prefix .. 'p5'],
                    p6 = args[prefix .. 'p6'],
                    coach = args[prefix .. 'c'],
                    analyst = args[prefix .. 'a']
                })
            end
            
            -- 2. Build HTML
            local cardData = {
                team = team,
                seeding = args[prefix .. 'seed'],
                p1 = args[prefix .. 'p1'],
                p2 = args[prefix .. 'p2'],
                p3 = args[prefix .. 'p3'],
                p4 = args[prefix .. 'p4'],
                p5 = args[prefix .. 'p5'],
                p6 = args[prefix .. 'p6'],
                coach = args[prefix .. 'c'],
                analyst = args[prefix .. 'a']
            }
            output = output .. buildCard(cardData)
        end
    end
    
    return output
end

return p