Module:Team: Difference between revisions
From eSportsAmaze
More actions
Esportsamaze (talk | contribs) No edit summary |
Esportsamaze (talk | contribs) No edit summary |
||
| Line 120: | Line 120: | ||
function p.history(frame) | function p.history(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local team = args.team or mw.title.getCurrentTitle(). | local team = args.team or mw.title.getCurrentTitle().subpageText | ||
-- Query StageStandings to see where this team played | -- Query StageStandings to see where this team played | ||
| Line 177: | Line 177: | ||
function p.activeRoster(frame) | function p.activeRoster(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local team = args.team or mw.title.getCurrentTitle(). | local team = args.team or mw.title.getCurrentTitle().subpageText | ||
-- Query the Players table | -- Query the Players table | ||
Revision as of 01:31, 25 January 2026
Documentation for this module may be created at Module:Team/doc
local p = {} -- THIS LINE IS CRITICAL. DO NOT DELETE.
local cargo = mw.ext.cargo
local html = mw.html
-- Helper: Currency Formatter
local function formatCurrency(amount)
if not amount then return "0" end
return '<span class="indian-currency">' .. amount .. '</span>'
end
-- Helper: Logo Logic (Light/Dark/Shield)
local function getLogo(teamName, image, imageDark)
local lightFile = (image ~= "" and image) or (teamName .. '.png')
local darkFile = (imageDark ~= "" and imageDark) or (teamName .. '_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')
-- Light Mode
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
-- Dark Mode
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: Add 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: Team Infobox
function p.infobox(frame)
local args = frame:getParent().args
local team = args.name or mw.title.getCurrentTitle().text
local root = html.create('div'):addClass('infobox')
-- Header
root:tag('div'):addClass('infobox-header'):wikitext(team)
-- Logo
root:node(getLogo(team, args.image, args.image_dark))
-- Data Container
local data = root:tag('div'):addClass('infobox-data-container')
addRow(data, "Name", args.other_team)
addRow(data, "Short Code", args.short_code)
addRow(data, "Country", args.country)
-- Status
if args.status then
local color = "#333"
local s = args.status:lower()
if s == "active" then color = "green"
elseif s == "inactive" or s == "disbanded" then color = "red" end
data:tag('div'):addClass('infobox-row')
:tag('div'):addClass('infobox-label'):wikitext("Status"):done()
:tag('div'):addClass('infobox-data'):css('font-weight','bold'):css('color', color):wikitext(args.status)
end
-- Auto-Rank (Krafton Rankings)
local rankTables = "Krafton_Rankings"
local rankFields = "rank"
local rankArgs = { where = "name = '" .. team .. "' AND type='Team'", limit = 1 }
local rankResult = cargo.query(rankTables, rankFields, rankArgs)
local rankVal = (#rankResult > 0) and ("#" .. rankResult[1].rank) or "Unranked"
addRow(data, "Krafton Rank", rankVal)
-- Sponsors (Convert commas to newlines)
if args.sponsors then
local sponsorList = args.sponsors:gsub(",", "<br>")
data:tag('div'):addClass('infobox-row')
:tag('div'):addClass('infobox-label'):wikitext("Sponsors"):done()
:tag('div'):addClass('infobox-data'):css('text-align','right'):css('line-height','1.4em'):wikitext(sponsorList)
end
-- Total Earnings (Auto-Sum)
local prizeTables = "Tournament_Prizes"
local prizeFields = "SUM(money)=total"
local prizeArgs = { where = "recipient = '" .. team .. "'" }
local prizeResult = cargo.query(prizeTables, prizeFields, prizeArgs)
local earnings = (#prizeResult > 0 and prizeResult[1].total) or "0"
addRow(data, "Total Earnings", formatCurrency(earnings))
-- Socials
if args.instagram or args.twitter or args.youtube then
data:tag('div'):addClass('infobox-header'):css('font-size','1em'):css('margin-top','10px'):css('border-radius','6px'):wikitext('Social Media')
local socialRow = data:tag('div'):addClass('infobox-row'):css('justify-content','center'):css('gap','10px')
if args.instagram then socialRow:wikitext('• [' .. args.instagram .. ' Instagram]') end
if args.twitter then socialRow:wikitext('• [' .. args.twitter .. ' X]') end
if args.youtube then socialRow:wikitext('• [' .. args.youtube .. ' YouTube]') end
end
return tostring(root)
end
-- MAIN 2: Automatic Tournament History
function p.history(frame)
local args = frame:getParent().args
local team = args.team or mw.title.getCurrentTitle().subpageText
-- Query StageStandings to see where this team played
local tables = "StageStandings"
local fields = "tournament, stage, totalpts, matchesplayed, wwcd, elimpts, lastmatchrank, result"
local queryArgs = {
where = "team = '" .. team .. "'",
orderBy = "tournament DESC", -- Most recent first
limit = 50
}
local results = cargo.query(tables, fields, queryArgs)
local root = html.create('div')
root:wikitext('== Tournament Statistics ==')
if #results > 0 then
local tbl = root:tag('table'):addClass('modern-history-table')
-- Header
local thead = tbl:tag('thead'):tag('tr')
thead:tag('th'):wikitext('Tournament')
thead:tag('th'):wikitext('Stage')
thead:tag('th'):wikitext('Rank')
thead:tag('th'):wikitext('MP')
thead:tag('th'):wikitext('WWCD')
thead:tag('th'):wikitext('Elims')
thead:tag('th'):wikitext('Pts')
-- Rows
for _, row in ipairs(results) do
local tr = tbl:tag('tr')
-- Color code result (Qualified/Eliminated)
local res = (row.result or ""):lower()
if res == "q" or res == "qualified" then tr:css('background-color', '#E9FFF0') -- Greenish
elseif res == "e" or res == "eliminated" then tr:css('background-color', '#FFE9E9') -- Reddish
end
tr:tag('td'):css('font-weight','bold'):wikitext('[[' .. row.tournament .. ']]')
tr:tag('td'):wikitext(row.stage)
tr:tag('td'):css('font-weight','bold'):css('text-align','center'):wikitext('#' .. (row.lastmatchrank or '?'))
tr:tag('td'):css('text-align','center'):wikitext(row.matchesplayed)
tr:tag('td'):css('text-align','center'):wikitext(row.wwcd)
tr:tag('td'):css('text-align','center'):wikitext(row.elimpts)
tr:tag('td'):css('text-align','center'):css('font-weight','800'):wikitext(row.totalpts)
end
else
root:wikitext("''No tournament data found for this team.''")
end
return tostring(root)
end
-- MAIN 3: Active Roster Table
function p.activeRoster(frame)
local args = frame:getParent().args
local team = args.team or mw.title.getCurrentTitle().subpageText
-- Query the Players table
local tables = "Players"
local fields = "id, real_name, role, nationality, image"
local queryArgs = {
where = "current_team = '" .. team .. "'",
orderBy = "role ASC, id ASC"
}
local results = cargo.query(tables, fields, queryArgs)
local root = html.create('table')
root:addClass('wikitable flat-table sortable')
:css('width', '100%')
:css('text-align', 'center')
:css('margin-top', '0px')
-- Table Header
local header = root:tag('tr')
header:tag('th'):wikitext('ID')
header:tag('th'):wikitext('Name')
header:tag('th'):wikitext('Role')
header:tag('th'):wikitext('Nationality')
if #results > 0 then
for _, row in ipairs(results) do
local tr = root:tag('tr')
-- Cell 1: ID with Image
local idCell = tr:tag('td')
:css('text-align', 'left')
:css('font-weight', 'bold')
if row.image and row.image ~= "" then
idCell:wikitext('[[File:' .. row.image .. '|30px|link=' .. row.id .. ']] ')
end
idCell:wikitext('[[' .. row.id .. ']]')
-- Cell 2: Real Name
tr:tag('td'):wikitext(row.real_name)
-- Cell 3: Role
tr:tag('td'):wikitext(row.role)
-- Cell 4: Nationality
tr:tag('td'):wikitext(row.nationality)
end
else
local tr = root:tag('tr')
tr:tag('td'):attr('colspan', '4'):wikitext('No players currently listed for this team.')
end
return tostring(root)
end
return p