Module:Participant: Difference between revisions
From eSportsAmaze
More actions
Esportsamaze (talk | contribs) 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'):..." |
Esportsamaze (talk | contribs) No edit summary |
||
| Line 2: | Line 2: | ||
local html = mw.html | local html = mw.html | ||
-- Helper: Check | -- 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 | ||
-- INTERNAL: The logic to build ONE card (Pure HTML) | |||
local function buildCard(data) | |||
local team = | local team = data.team or "" | ||
local seeding = | local seeding = data.seeding or "" | ||
local root = html.create('div'):addClass('roster-card') | local root = html.create('div'):addClass('roster-card') | ||
-- | -- 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 | -- 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 lDiv = logoDiv:tag('div'):addClass('logo-lightmode') | 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') | local dDiv = logoDiv:tag('div'):addClass('logo-darkmode') | ||
if | if fileExists(darkFile) then | ||
dDiv:wikitext('[[File:' .. darkFile .. '|link=]]') | dDiv:wikitext('[[File:'..darkFile..'|link=]]') | ||
elseif | 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 | ||
-- | -- Name | ||
headerContent:tag('div'):addClass('roster-name'):wikitext('[[' .. team .. ']]') | headerContent:tag('div'):addClass('roster-name'):wikitext('[[' .. team .. ']]') | ||
-- Seeding | -- 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 | ||
-- | -- 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} | |||
local players = { | |||
local playerCount = 0 | local playerCount = 0 | ||
for _, | 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) | local playerInner = contentRows:tag('div'):addClass('roster-players-inner'):addClass('count-' .. playerCount) | ||
for _, | for _, pl in ipairs(players) do | ||
if | if pl and pl ~= "" then | ||
playerInner:tag('div'):addClass('roster-row player'):wikitext('[[' .. | playerInner:tag('div'):addClass('roster-row player'):wikitext('[[' .. pl .. ']]') | ||
end | end | ||
end | end | ||
-- | -- STAFF | ||
if ( | 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 | staffInner:tag('div'):addClass('roster-row staff'):wikitext('C: [[' .. data.coach .. ']]') | ||
staffInner:tag('div'):addClass('roster-row staff'):wikitext('C: [[' .. | |||
end | end | ||
if | if data.analyst and data.analyst ~= "" then | ||
staffInner:tag('div'):addClass('roster-row staff'):wikitext('A: [[' .. | 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