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
Created page with "local p = {} local html = mw.html -- Helper: Check if file exists local function fileExists(filename) return mw.title.new('File:' .. filename).exists end function p.card(frame) local args = frame:getParent().args local team = args.team or "" local seeding = args.seeding or "" -- 1. Build the Container (roster-card style) local root = html.create('div'):addClass('roster-card') -- 2. HEADER SECTION local header = root:tag('div'):..."
 
No edit summary
Line 2: Line 2:
local html = mw.html
local html = mw.html


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


function p.card(frame)
-- INTERNAL: The logic to build ONE card (Pure HTML)
    local args = frame:getParent().args
local function buildCard(data)
     local team = args.team or ""
     local team = data.team or ""
     local seeding = args.seeding or ""
     local seeding = data.seeding or ""
      
      
    -- 1. Build the Container (roster-card style)
     local root = html.create('div'):addClass('roster-card')
     local root = html.create('div'):addClass('roster-card')
      
      
     -- 2. HEADER SECTION
     -- HEADER
     local header = root:tag('div'):addClass('roster-header')
     local header = root:tag('div'):addClass('roster-header')
     local headerContent = header:tag('div'):addClass('header-content')
     local headerContent = header:tag('div'):addClass('header-content')
      
      
     -- Logo Logic (Light/Dark Mode support)
     -- Logo
     local logoDiv = headerContent:tag('div'):addClass('roster-logo')
     local logoDiv = headerContent:tag('div'):addClass('roster-logo')
     local lightFile = team .. '.png'
     local lightFile = team .. '.png'
     local darkFile = team .. '_dark.png'
     local darkFile = team .. '_dark.png'
    local hasLight = fileExists(lightFile)
    local hasDark = fileExists(darkFile)
      
      
    -- Light Mode Logo
     local lDiv = logoDiv:tag('div'):addClass('logo-lightmode')
     local lDiv = logoDiv:tag('div'):addClass('logo-lightmode')
     if hasLight then
     lDiv:wikitext(fileExists(lightFile) and ('[[File:'..lightFile..'|link=]]') or '[[File:Shield_team.png|link=]]')
        lDiv:wikitext('[[File:' .. lightFile .. '|link=]]')
    else
        lDiv:wikitext('[[File:Shield_team.png|link=]]')
    end
      
      
    -- Dark Mode Logo
     local dDiv = logoDiv:tag('div'):addClass('logo-darkmode')
     local dDiv = logoDiv:tag('div'):addClass('logo-darkmode')
     if hasDark then
     if fileExists(darkFile) then
         dDiv:wikitext('[[File:' .. darkFile .. '|link=]]')
         dDiv:wikitext('[[File:'..darkFile..'|link=]]')
     elseif hasLight then
     elseif fileExists(lightFile) then
         dDiv:wikitext('[[File:' .. lightFile .. '|link=]]')
         dDiv:wikitext('[[File:'..lightFile..'|link=]]')
     else
     else
         dDiv:wikitext('[[File:Shield_team_dark.png|link=]]')
         dDiv:wikitext('[[File:Shield_team_dark.png|link=]]')
     end
     end
      
      
     -- Team Name
     -- Name
     headerContent:tag('div'):addClass('roster-name'):wikitext('[[' .. team .. ']]')
     headerContent:tag('div'):addClass('roster-name'):wikitext('[[' .. team .. ']]')
      
      
     -- Seeding (Optional Subheader)
     -- Seeding
     if seeding ~= "" then
     if seeding ~= "" then
         root:tag('div'):addClass('roster-subheader'):wikitext(seeding)
         root:tag('div'):addClass('roster-subheader'):wikitext(seeding)
     end
     end
      
      
     -- 3. CONTENT ROWS (Players & Staff)
     -- PLAYERS
     local contentRows = root:tag('div'):addClass('roster-content-rows')
     local contentRows = root:tag('div'):addClass('roster-content-rows')
   
     local players = {data.p1, data.p2, data.p3, data.p4, data.p5, data.p6}
    -- Count Players (for CSS grid styling)
     local players = {args.p1, args.p2, args.p3, args.p4, args.p5, args.p6}
     local playerCount = 0
     local playerCount = 0
     for _, p in ipairs(players) do
     for _, pl in ipairs(players) do if pl and pl ~= "" then playerCount = playerCount + 1 end end
        if p and p ~= "" then playerCount = playerCount + 1 end
    end
      
      
    -- Player Grid
     local playerInner = contentRows:tag('div'):addClass('roster-players-inner'):addClass('count-' .. playerCount)
     local playerInner = contentRows:tag('div'):addClass('roster-players-inner'):addClass('count-' .. playerCount)
     for _, player in ipairs(players) do
     for _, pl in ipairs(players) do
         if player and player ~= "" then
         if pl and pl ~= "" then
             playerInner:tag('div'):addClass('roster-row player'):wikitext('[[' .. player .. ']]')
             playerInner:tag('div'):addClass('roster-row player'):wikitext('[[' .. pl .. ']]')
         end
         end
     end
     end
      
      
     -- Staff Grid (Coach/Analyst)
     -- STAFF
     if (args.coach and args.coach ~= "") or (args.analyst and args.analyst ~= "") then
     if (data.coach and data.coach ~= "") or (data.analyst and data.analyst ~= "") then
         local staffInner = contentRows:tag('div'):addClass('roster-staff-inner')
         local staffInner = contentRows:tag('div'):addClass('roster-staff-inner')
       
         if data.coach and data.coach ~= "" then
         if args.coach and args.coach ~= "" then
             staffInner:tag('div'):addClass('roster-row staff'):wikitext('C: [[' .. data.coach .. ']]')
             staffInner:tag('div'):addClass('roster-row staff'):wikitext('C: [[' .. args.coach .. ']]')
         end
         end
         if args.analyst and args.analyst ~= "" then
         if data.analyst and data.analyst ~= "" then
             staffInner:tag('div'):addClass('roster-row staff'):wikitext('A: [[' .. args.analyst .. ']]')
             staffInner:tag('div'):addClass('roster-row staff'):wikitext('A: [[' .. data.analyst .. ']]')
         end
         end
     end
     end
      
      
     return tostring(root)
     return tostring(root)
end
-- PUBLIC 1: Single Card (Old usage)
function p.card(frame)
    return buildCard(frame:getParent().args)
end
-- PUBLIC 2: Group (New usage)
function p.group(frame)
    local args = frame:getParent().args
    local count = tonumber(args.count) or 4 -- Default to 4 if not specified
    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
            frame:callParserFunction('#cargo_store', {
                _table = "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'], -- Short code 'c' for coach
                analyst = args[prefix .. 'a'] -- Short code 'a' for analyst
            })
           
            -- 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
end


return p
return p

Revision as of 01:52, 25 January 2026

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

local p = {}
local html = mw.html

-- 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)
function p.card(frame)
    return buildCard(frame:getParent().args)
end

-- PUBLIC 2: Group (New usage)
function p.group(frame)
    local args = frame:getParent().args
    local count = tonumber(args.count) or 4 -- Default to 4 if not specified
    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
            frame:callParserFunction('#cargo_store', {
                _table = "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'], -- Short code 'c' for coach
                analyst = args[prefix .. 'a'] -- Short code 'a' for analyst
            })
            
            -- 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