Module:Team: Difference between revisions
From eSportsAmaze
More actions
Esportsamaze (talk | contribs) No edit summary Tag: Reverted |
Esportsamaze (talk | contribs) Undo revision 2839 by Esportsamaze (talk) Tag: Undo |
||
| Line 2: | Line 2: | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local html = mw.html | local html = mw.html | ||
-- ============================================================ | -- ============================================================ | ||
| Line 8: | Line 7: | ||
-- ============================================================ | -- ============================================================ | ||
-- Currency Formatter | |||
local function formatCurrency(amount) | local function formatCurrency(amount) | ||
if not amount then return "0" end | if not amount then return "0" end | ||
| Line 15: | Line 15: | ||
end | end | ||
-- Social Icons Helper | |||
local function getSocials(args) | local function getSocials(args) | ||
local container = html.create('div'):addClass('fib-socials') | local container = html.create('div'):addClass('fib-socials') | ||
local hasSocials = false | local hasSocials = false | ||
local platforms = { | local platforms = { | ||
{arg='instagram', file='Icon_instagram.png'}, | {arg='instagram', file='Icon_instagram.png'}, | ||
| Line 26: | Line 28: | ||
{arg='website', file='Icon_website.png'} | {arg='website', file='Icon_website.png'} | ||
} | } | ||
for _, p in ipairs(platforms) do | for _, p in ipairs(platforms) do | ||
if args[p.arg] and args[p.arg] ~= "" then | if args[p.arg] and args[p.arg] ~= "" then | ||
| Line 32: | Line 35: | ||
end | end | ||
end | end | ||
if hasSocials then return tostring(container) else return "" end | if hasSocials then return tostring(container) else return "" end | ||
end | end | ||
-- Infobox Logo Helper | |||
local function getInfoboxLogo(teamName, image, imageDark) | local function getInfoboxLogo(teamName, image, imageDark) | ||
local lightFile = (image ~= "" and image) or (teamName .. '.png') | local lightFile = (image ~= "" and image) or (teamName .. '.png') | ||
local darkFile = (imageDark ~= "" and imageDark) or (teamName .. '_dark.png') | local darkFile = (imageDark ~= "" and imageDark) or (teamName .. '_dark.png') | ||
local hasLight = mw.title.new('File:' .. lightFile).exists | local hasLight = mw.title.new('File:' .. lightFile).exists | ||
local hasDark = mw.title.new('File:' .. darkFile).exists | local hasDark = mw.title.new('File:' .. darkFile).exists | ||
local container = html.create('div'):addClass('fib-image') | local container = html.create('div'):addClass('fib-image') | ||
local lSpan = container:tag('span'):addClass('logo-lightmode') | local lSpan = container:tag('span'):addClass('logo-lightmode') | ||
if hasLight then lSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else lSpan:wikitext('[[File:Shield_team.png|180px]]') end | if hasLight then lSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else lSpan:wikitext('[[File:Shield_team.png|180px]]') end | ||
local dSpan = container:tag('span'):addClass('logo-darkmode') | local dSpan = container:tag('span'):addClass('logo-darkmode') | ||
if hasDark then dSpan:wikitext('[[File:' .. darkFile .. '|220px]]') elseif hasLight then dSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else dSpan:wikitext('[[File:Shield_team_dark.png|180px]]') end | if hasDark then dSpan:wikitext('[[File:' .. darkFile .. '|220px]]') elseif hasLight then dSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else dSpan:wikitext('[[File:Shield_team_dark.png|180px]]') end | ||
return tostring(container) | return tostring(container) | ||
end | end | ||
-- ============================================================ | -- ============================================================ | ||
-- MAIN 1: TEAM INFOBOX | -- MAIN 1: TEAM INFOBOX (STABLE VERSION) | ||
-- ============================================================ | -- ============================================================ | ||
function p.infobox(frame) | function p.infobox(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local team = args.name or | -- Get clean name (GodLike Esports) instead of path | ||
local team = args.name or mw.title.getCurrentTitle().subpageText | |||
local root = html.create('div'):addClass('flat-infobox') | local root = html.create('div'):addClass('flat-infobox') | ||
root:tag('div'):addClass('fib-header'):tag('div'):addClass('fib-title'):wikitext(team) | |||
-- Header (Just like the old {{name|{{PAGENAME}}}}) | |||
root:tag('div'):addClass('fib-header') | |||
:tag('div'):addClass('fib-title'):wikitext(team) | |||
-- Logo | |||
root:wikitext(getInfoboxLogo(team, args.image, args.image_dark)) | root:wikitext(getInfoboxLogo(team, args.image, args.image_dark)) | ||
-- | -- Calculations | ||
local earnings = "0" | local earnings = "0" | ||
if cargo and cargo.query then | if cargo and cargo.query then | ||
local | local tables = "PrizeMoney" | ||
if results and #results > 0 and results[1].total then earnings = results[1].total end | local fields = "SUM(prize)=total" | ||
local queryArgs = { | |||
where = "team = '" .. team:gsub("'", "\\'") .. "' AND (player='' OR player IS NULL)" | |||
} | |||
local results = cargo.query(tables, fields, queryArgs) | |||
if results and #results > 0 and results[1].total then | |||
earnings = results[1].total | |||
end | |||
end | end | ||
| Line 77: | Line 100: | ||
if args.status then | if args.status then | ||
local s = args.status:lower() | local s = args.status:lower() | ||
if s == "active" then statusColor = "#16a34a" elseif s == "inactive" or s == "disbanded" then statusColor = "#dc2626" end | if s == "active" then statusColor = "#16a34a" | ||
elseif s == "inactive" or s == "disbanded" then statusColor = "#dc2626" | |||
end | |||
end | end | ||
-- Grids | |||
local grid1 = root:tag('div'):addClass('fib-grid') | local grid1 = root:tag('div'):addClass('fib-grid') | ||
grid1:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Status'):done():tag('div'):addClass('fib-value-sm'):css('color', statusColor):wikitext(statusText):done() | grid1:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Status'):done():tag('div'):addClass('fib-value-sm'):css('color', statusColor):wikitext(statusText):done() | ||
| Line 88: | Line 114: | ||
grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Tag'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.short_code or '-'):done() | grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Tag'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.short_code or '-'):done() | ||
-- Earnings | |||
if earnings and tonumber(earnings) and tonumber(earnings) > 0 then | if earnings and tonumber(earnings) and tonumber(earnings) > 0 then | ||
root:tag('div'):addClass('fib-prize'):tag('div'):addClass('fib-label-sm'):wikitext('Total Earnings'):done():tag('div'):addClass('fib-prize-val'):wikitext(formatCurrency(earnings)):done() | root:tag('div'):addClass('fib-prize') | ||
:tag('div'):addClass('fib-label-sm'):wikitext('Total Earnings'):done() | |||
:tag('div'):addClass('fib-prize-val'):wikitext(formatCurrency(earnings)):done() | |||
end | end | ||
-- List | |||
local list = root:tag('div'):addClass('fib-list') | local list = root:tag('div'):addClass('fib-list') | ||
local function addRow(label, value) | local function addRow(label, value) | ||
if value and value ~= "" then list:tag('div'):addClass('fib-row'):tag('div'):addClass('fib-label'):wikitext(label):done():tag('div'):addClass('fib-data'):wikitext(value):done() end | if value and value ~= "" then | ||
list:tag('div'):addClass('fib-row'):tag('div'):addClass('fib-label'):wikitext(label):done():tag('div'):addClass('fib-data'):wikitext(value):done() | |||
end | |||
end | end | ||
addRow('Full Name', args.other_team) | addRow('Full Name', args.other_team) | ||
if args.sponsors then addRow('Sponsors', args.sponsors:gsub(",", "<br>")) end | if args.sponsors then addRow('Sponsors', args.sponsors:gsub(",", "<br>")) end | ||
-- Socials | |||
root:wikitext(getSocials(args)) | root:wikitext(getSocials(args)) | ||
-- JUST RETURN THE INFOBOX (No Page Title Tricks) | |||
return tostring(root) | return tostring(root) | ||
end | end | ||
-- ============================================================ | -- ============================================================ | ||
-- MAIN 2: | -- MAIN 2: HISTORY (Preserved) | ||
-- ============================================================ | -- ============================================================ | ||
function p. | function p.history(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local team = args.team or | local team = args.team or mw.title.getCurrentTitle().subpageText | ||
local results = cargo.query("StageStandings", "tournament, stage, totalpts, matchesplayed, wwcd, elimpts, lastmatchrank, result", { | |||
where = "team = '" .. team:gsub("'", "\\'") .. "'", | |||
orderBy = "tournament DESC", | |||
limit = 50 | |||
}) | |||
local root = html.create('div') | |||
root:wikitext('== Tournament Statistics ==') | |||
if #results > 0 then | |||
local tbl = root:tag('table'):addClass('modern-history-table') | |||
if | local thead = tbl:tag('thead'):tag('tr') | ||
local | thead:tag('th'):wikitext('Tournament'); thead:tag('th'):wikitext('Stage'); thead:tag('th'):wikitext('Rank') | ||
local | thead:tag('th'):wikitext('MP'); thead:tag('th'):wikitext('WWCD'); thead:tag('th'):wikitext('Elims'); thead:tag('th'):wikitext('Pts') | ||
for _, row in ipairs(results) do | for _, row in ipairs(results) do | ||
local tr = tbl:tag('tr') | |||
local res = (row.result or ""):lower() | |||
if res == "q" or res == "qualified" then tr:css('background-color', '#E9FFF0') | |||
elseif res == "e" or res == "eliminated" then tr:css('background-color', '#FFE9E9') end | |||
if | |||
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 | end | ||
else root:wikitext("''No tournament data found for this team.''") end | |||
return tostring(root) | |||
return tostring( | |||
end | end | ||
-- ============================================================ | -- ============================================================ | ||
-- MAIN 3: | -- MAIN 3: ACTIVE ROSTER (Preserved) | ||
-- ============================================================ | -- ============================================================ | ||
function p. | function p.activeRoster(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local team = args.team or | local team = args.team or mw.title.getCurrentTitle().subpageText | ||
local results = cargo.query("Players", "id, real_name, role, nationality, image", { where = "current_team = '" .. team:gsub("'", "\\'") .. "'", orderBy = "role ASC, id ASC" }) | |||
local root = html.create('table'):addClass('wikitable flat-table sortable'):css('width', '100%'):css('text-align', 'center') | |||
local | 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 | if #results > 0 then | ||
for _, row in ipairs(results) do | |||
local tr = root:tag('tr') | |||
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 .. ']]') | |||
tr:tag('td'):wikitext(row.real_name); tr:tag('td'):wikitext(row.role); tr:tag('td'):wikitext(row.nationality) | |||
end | |||
else root:tag('tr'):tag('td'):attr('colspan', '4'):wikitext('No players currently listed for this team.') end | |||
return tostring(root) | |||
return tostring( | |||
end | end | ||
return p | return p | ||
Revision as of 20:16, 29 January 2026
Documentation for this module may be created at Module:Team/doc
local p = {}
local cargo = mw.ext.cargo
local html = mw.html
-- ============================================================
-- HELPER FUNCTIONS
-- ============================================================
-- Currency Formatter
local function formatCurrency(amount)
if not amount then return "0" end
local n = tonumber(amount) or 0
local formatted = tostring(n):reverse():gsub("(%d%d%d)(%d%d%d)","%1,%2"):reverse()
return '<span class="indian-currency">₹ ' .. formatted .. '</span>'
end
-- Social Icons Helper
local function getSocials(args)
local container = html.create('div'):addClass('fib-socials')
local hasSocials = false
local platforms = {
{arg='instagram', file='Icon_instagram.png'},
{arg='twitter', file='Icon_twitter.png'},
{arg='youtube', file='Icon_youtube.png'},
{arg='discord', file='Icon_discord.png'},
{arg='facebook', file='Icon_facebook.png'},
{arg='website', file='Icon_website.png'}
}
for _, p in ipairs(platforms) do
if args[p.arg] and args[p.arg] ~= "" then
hasSocials = true
container:wikitext('[[File:' .. p.file .. '|24px|link=' .. args[p.arg] .. '|class=social-img]]')
end
end
if hasSocials then return tostring(container) else return "" end
end
-- Infobox Logo Helper
local function getInfoboxLogo(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('fib-image')
local lSpan = container:tag('span'):addClass('logo-lightmode')
if hasLight then lSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else lSpan:wikitext('[[File:Shield_team.png|180px]]') end
local dSpan = container:tag('span'):addClass('logo-darkmode')
if hasDark then dSpan:wikitext('[[File:' .. darkFile .. '|220px]]') elseif hasLight then dSpan:wikitext('[[File:' .. lightFile .. '|220px]]') else dSpan:wikitext('[[File:Shield_team_dark.png|180px]]') end
return tostring(container)
end
-- ============================================================
-- MAIN 1: TEAM INFOBOX (STABLE VERSION)
-- ============================================================
function p.infobox(frame)
local args = frame:getParent().args
-- Get clean name (GodLike Esports) instead of path
local team = args.name or mw.title.getCurrentTitle().subpageText
local root = html.create('div'):addClass('flat-infobox')
-- Header (Just like the old {{name|{{PAGENAME}}}})
root:tag('div'):addClass('fib-header')
:tag('div'):addClass('fib-title'):wikitext(team)
-- Logo
root:wikitext(getInfoboxLogo(team, args.image, args.image_dark))
-- Calculations
local earnings = "0"
if cargo and cargo.query then
local tables = "PrizeMoney"
local fields = "SUM(prize)=total"
local queryArgs = {
where = "team = '" .. team:gsub("'", "\\'") .. "' AND (player='' OR player IS NULL)"
}
local results = cargo.query(tables, fields, queryArgs)
if results and #results > 0 and results[1].total then
earnings = results[1].total
end
end
local rankVal = "Unranked"
if cargo and cargo.query then
local rResults = cargo.query("Krafton_Rankings", "rank", { where = "name = '" .. team:gsub("'", "\\'") .. "' AND type='Team'", limit = 1 })
if rResults and #rResults > 0 then rankVal = "#" .. rResults[1].rank end
end
-- Status
local statusColor = "#333"
local statusText = args.status or "Active"
if args.status then
local s = args.status:lower()
if s == "active" then statusColor = "#16a34a"
elseif s == "inactive" or s == "disbanded" then statusColor = "#dc2626"
end
end
-- Grids
local grid1 = root:tag('div'):addClass('fib-grid')
grid1:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Status'):done():tag('div'):addClass('fib-value-sm'):css('color', statusColor):wikitext(statusText):done()
grid1:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Krafton Rank'):done():tag('div'):addClass('fib-value-sm'):wikitext(rankVal):done()
local grid2 = root:tag('div'):addClass('fib-grid')
grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Country'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.country or 'TBD'):done()
grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Tag'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.short_code or '-'):done()
-- Earnings
if earnings and tonumber(earnings) and tonumber(earnings) > 0 then
root:tag('div'):addClass('fib-prize')
:tag('div'):addClass('fib-label-sm'):wikitext('Total Earnings'):done()
:tag('div'):addClass('fib-prize-val'):wikitext(formatCurrency(earnings)):done()
end
-- List
local list = root:tag('div'):addClass('fib-list')
local function addRow(label, value)
if value and value ~= "" then
list:tag('div'):addClass('fib-row'):tag('div'):addClass('fib-label'):wikitext(label):done():tag('div'):addClass('fib-data'):wikitext(value):done()
end
end
addRow('Full Name', args.other_team)
if args.sponsors then addRow('Sponsors', args.sponsors:gsub(",", "<br>")) end
-- Socials
root:wikitext(getSocials(args))
-- JUST RETURN THE INFOBOX (No Page Title Tricks)
return tostring(root)
end
-- ============================================================
-- MAIN 2: HISTORY (Preserved)
-- ============================================================
function p.history(frame)
local args = frame:getParent().args
local team = args.team or mw.title.getCurrentTitle().subpageText
local results = cargo.query("StageStandings", "tournament, stage, totalpts, matchesplayed, wwcd, elimpts, lastmatchrank, result", {
where = "team = '" .. team:gsub("'", "\\'") .. "'",
orderBy = "tournament DESC",
limit = 50
})
local root = html.create('div')
root:wikitext('== Tournament Statistics ==')
if #results > 0 then
local tbl = root:tag('table'):addClass('modern-history-table')
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')
for _, row in ipairs(results) do
local tr = tbl:tag('tr')
local res = (row.result or ""):lower()
if res == "q" or res == "qualified" then tr:css('background-color', '#E9FFF0')
elseif res == "e" or res == "eliminated" then tr:css('background-color', '#FFE9E9') 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 (Preserved)
-- ============================================================
function p.activeRoster(frame)
local args = frame:getParent().args
local team = args.team or mw.title.getCurrentTitle().subpageText
local results = cargo.query("Players", "id, real_name, role, nationality, image", { where = "current_team = '" .. team:gsub("'", "\\'") .. "'", orderBy = "role ASC, id ASC" })
local root = html.create('table'):addClass('wikitable flat-table sortable'):css('width', '100%'):css('text-align', 'center')
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')
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 .. ']]')
tr:tag('td'):wikitext(row.real_name); tr:tag('td'):wikitext(row.role); tr:tag('td'):wikitext(row.nationality)
end
else root:tag('tr'):tag('td'):attr('colspan', '4'):wikitext('No players currently listed for this team.') end
return tostring(root)
end
return p