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

Module:GroupDraw: Difference between revisions

From eSportsAmaze
Created page with "local p = {} local html = mw.html local cargo = mw.ext.cargo local function buildLogo(teamName, tourneyData, masterData) local lightLogo = "Shield_team.png" local darkLogo = "Shield_team_dark.png" if tourneyData and tourneyData.image and tourneyData.image ~= "" then lightLogo = tourneyData.image darkLogo = (tourneyData.image_dark and tourneyData.image_dark ~= "") and tourneyData.image_dark or lightLogo elseif masterData then if masterData.image and masterData.image ~=..."
 
No edit summary
Line 32: Line 32:
local args = frame:getParent().args
local args = frame:getParent().args
local tournamentName = args.tournament or mw.title.getCurrentTitle().text
local tournamentName = args.tournament or mw.title.getCurrentTitle().text
local mainTitle = args.title


local groupsInfo = {}
local groupsInfo = {}
Line 76: Line 77:
local mainContainer = html.create('div'):addClass('group-draw-wrapper')
local mainContainer = html.create('div'):addClass('group-draw-wrapper')
local drawTable = mainContainer:tag('table'):addClass('wikitable group-draw-table'):css('width', '100%'):css('border-collapse', 'collapse')
local drawTable = mainContainer:tag('table'):addClass('wikitable group-draw-table'):css('width', '100%'):css('border-collapse', 'collapse')
if mainTitle and mainTitle ~= "" then
local titleRow = drawTable:tag('tr')
titleRow:tag('th'):attr('colspan', tostring(#groupsInfo)):wikitext(mainTitle):css('text-align', 'center'):css('background-color', '#e6edf4'):css('font-size', '1.1em'):css('padding', '8px')
end


local topHeader = drawTable:tag('tr')
local topHeader = drawTable:tag('tr')

Revision as of 20:15, 1 March 2026

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

local p = {}
local html = mw.html
local cargo = mw.ext.cargo

local function buildLogo(teamName, tourneyData, masterData)
local lightLogo = "Shield_team.png"
local darkLogo = "Shield_team_dark.png"

if tourneyData and tourneyData.image and tourneyData.image ~= "" then
lightLogo = tourneyData.image
darkLogo = (tourneyData.image_dark and tourneyData.image_dark ~= "") and tourneyData.image_dark or lightLogo
elseif masterData then
if masterData.image and masterData.image ~= "" then
lightLogo = masterData.image
else
lightLogo = teamName .. ".png"
end
if masterData.image_dark and masterData.image_dark ~= "" then
darkLogo = masterData.image_dark
else
darkLogo = lightLogo
end
end

local container = html.create('span'):addClass('team-logo-wrapper')
container:tag('span'):addClass('logo-lightmode'):wikitext('[[File:' .. lightLogo .. '|30px|link=|class=team-logo]]')
container:tag('span'):addClass('logo-darkmode'):wikitext('[[File:' .. darkLogo .. '|30px|link=|class=team-logo]]')
return tostring(container)
end

function p.main(frame)
local args = frame:getParent().args
local tournamentName = args.tournament or mw.title.getCurrentTitle().text
local mainTitle = args.title

local groupsInfo = {}
local allTeams = {}
local maxRows = 0

for i = 1, 20 do
local gName = args['g' .. i]
local gTeamsStr = args['g' .. i .. 'teams']

if gName and gTeamsStr then
local teamList = mw.text.split(gTeamsStr, ",")
local cleanedTeams = {}

for _, tName in ipairs(teamList) do
local trimmedTeam = mw.text.trim(tName)
if trimmedTeam ~= "" then
table.insert(cleanedTeams, trimmedTeam)
table.insert(allTeams, "'" .. trimmedTeam:gsub("'", "\\'") .. "'")
end
end

table.insert(groupsInfo, { title = gName, squad = cleanedTeams })
if #cleanedTeams > maxRows then maxRows = #cleanedTeams end
end
end

if #groupsInfo == 0 then return "" end

local teamSql = table.concat(allTeams, ",")

local tourneyDb = {}
if cargo and cargo.query and teamSql ~= "" then
local tResults = cargo.query("Tournament_Teams", "team, display_name, image, image_dark", { where = "tournament='" .. tournamentName:gsub("'", "\\'") .. "' AND team IN (" .. teamSql .. ")", limit = 500 })
for _, rowData in ipairs(tResults) do tourneyDb[rowData.team] = rowData end
end

local masterDb = {}
if cargo and cargo.query and teamSql ~= "" then
local mResults = cargo.query("Teams", "name, image, image_dark", { where = "name IN (" .. teamSql .. ")", limit = 500 })
for _, rowData in ipairs(mResults) do masterDb[rowData.name] = rowData end
end

local mainContainer = html.create('div'):addClass('group-draw-wrapper')
local drawTable = mainContainer:tag('table'):addClass('wikitable group-draw-table'):css('width', '100%'):css('border-collapse', 'collapse')

if mainTitle and mainTitle ~= "" then
local titleRow = drawTable:tag('tr')
titleRow:tag('th'):attr('colspan', tostring(#groupsInfo)):wikitext(mainTitle):css('text-align', 'center'):css('background-color', '#e6edf4'):css('font-size', '1.1em'):css('padding', '8px')
end

local topHeader = drawTable:tag('tr')
for _, grp in ipairs(groupsInfo) do
topHeader:tag('th'):wikitext(grp.title):css('text-align', 'center'):css('background-color', '#f2f6fa')
end

for rIndex = 1, maxRows do
local tableRow = drawTable:tag('tr')
for _, grp in ipairs(groupsInfo) do
local cellContent = tableRow:tag('td')
local targetTeam = grp.squad[rIndex]

if targetTeam then
local tData = tourneyDb[targetTeam]
local mData = masterDb[targetTeam]
local displayName = targetTeam

if tData and tData.display_name and tData.display_name ~= "" then
displayName = tData.display_name
end

local generatedLogo = buildLogo(targetTeam, tData, mData)
local cellDiv = cellContent:tag('div'):css('display', 'flex'):css('align-items', 'center'):css('gap', '10px')
cellDiv:wikitext(generatedLogo .. ' [[' .. targetTeam .. '|' .. displayName .. ']]')
end
end
end

return tostring(mainContainer)
end

return p