Module:PrizePool: Difference between revisions
From eSportsAmaze
More actions
Esportsamaze (talk | contribs) No edit summary |
Esportsamaze (talk | contribs) No edit summary |
||
| Line 3: | Line 3: | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
-- Helper: Format Money | -- Helper: Format Money | ||
local function formatMoney(amount) | local function formatMoney(amount) | ||
if not amount then return "0" end | if not amount then return "0" end | ||
| Line 14: | Line 14: | ||
end | end | ||
-- Helper: Get | -- Helper: Get Logo | ||
local function getLogo(teamName) | local function getLogo(teamName) | ||
if not teamName or teamName == "" or teamName == "TBD" then return "" end | if not teamName or teamName == "" or teamName == "TBD" then return "" end | ||
| Line 44: | Line 44: | ||
local currency = args.currency or "₹" | local currency = args.currency or "₹" | ||
local tournamentName = args.tournament or mw.title.getCurrentTitle().text | local tournamentName = args.tournament or mw.title.getCurrentTitle().text | ||
-- Generate Unique ID for this specific table instance | |||
-- This prevents conflicts if you have multiple tables on one page | |||
local uniqueID = tostring(os.time()) .. tostring(math.random(100, 999)) | |||
local idContent = 'content-' .. uniqueID | |||
local idBtnShow = 'btn-show-' .. uniqueID | |||
local idBtnHide = 'btn-hide-' .. uniqueID | |||
-- Main Grid Wrapper | -- Main Grid Wrapper | ||
| Line 72: | Line 79: | ||
hiddenDiv = html.create('div') | hiddenDiv = html.create('div') | ||
:addClass('mw-collapsible mw-collapsed') | :addClass('mw-collapsible mw-collapsed') | ||
:attr('id', 'mw-customcollapsible- | :attr('id', 'mw-customcollapsible-' .. idContent) | ||
end | end | ||
| Line 137: | Line 144: | ||
rankList:wikitext(tostring(hiddenDiv)) | rankList:wikitext(tostring(hiddenDiv)) | ||
-- DUAL BUTTON SYSTEM (Swaps on click) | -- DUAL BUTTON SYSTEM (Swaps on click using Unique IDs) | ||
local toggleIds = 'mw-customtoggle- | -- We toggle ALL THREE IDs at once: Content (Toggle), Button Show (Toggle), Button Hide (Toggle) | ||
local toggleIds = 'mw-customtoggle-' .. idContent .. ' mw-customtoggle-' .. idBtnShow .. ' mw-customtoggle-' .. idBtnHide | |||
-- Button 1: "View Full Distribution" (Visible initially) | -- Button 1: "View Full Distribution" (Visible initially) | ||
-- Starts Visible. Toggling adds 'mw-collapsed' -> Hidden. | |||
colRank:tag('div') | colRank:tag('div') | ||
:attr('id', 'mw-customcollapsible- | :attr('id', 'mw-customcollapsible-' .. idBtnShow) | ||
:addClass('prize-show-more ' .. toggleIds) | :addClass('prize-show-more ' .. toggleIds) | ||
:wikitext('View Full Distribution <i class="fa-solid fa-chevron-down"></i>') | :wikitext('View Full Distribution <i class="fa-solid fa-chevron-down"></i>') | ||
-- Button 2: "Show Less" (Hidden initially) | -- Button 2: "Show Less" (Hidden initially) | ||
-- Starts Hidden (mw-collapsed). Toggling removes 'mw-collapsed' -> Visible. | |||
colRank:tag('div') | colRank:tag('div') | ||
:attr('id', 'mw-customcollapsible- | :attr('id', 'mw-customcollapsible-' .. idBtnHide) | ||
:addClass('prize-show-more mw-collapsible mw-collapsed ' .. toggleIds) | :addClass('prize-show-more mw-collapsible mw-collapsed ' .. toggleIds) | ||
:wikitext('Show Less <i class="fa-solid fa-chevron-up"></i>') | :wikitext('Show Less <i class="fa-solid fa-chevron-up"></i>') | ||
| Line 155: | Line 165: | ||
-- ========================================== | -- ========================================== | ||
-- COLUMN 2: SPECIAL AWARDS | -- COLUMN 2: SPECIAL AWARDS | ||
-- ========================================== | -- ========================================== | ||
local colAward = grid:tag('div'):addClass('prize-col-award') | local colAward = grid:tag('div'):addClass('prize-col-award') | ||
| Line 193: | Line 203: | ||
-- CASE 1: Player Won (LINKED) | -- CASE 1: Player Won (LINKED) | ||
if team and team ~= "" then winDiv:wikitext(getLogo(team)) end | if team and team ~= "" then winDiv:wikitext(getLogo(team)) end | ||
winDiv:wikitext('[[' .. winner .. ']]') | winDiv:wikitext('[[' .. winner .. ']]') | ||
elseif team and team ~= "" then | elseif team and team ~= "" then | ||
Revision as of 06:04, 27 January 2026
Documentation for this module may be created at Module:PrizePool/doc
local p = {}
local html = mw.html
local cargo = mw.ext.cargo
-- Helper: Format Money
local function formatMoney(amount)
if not amount then return "0" end
local formatted = amount
while true do
formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then break end
end
return formatted
end
-- Helper: Get Logo
local function getLogo(teamName)
if not teamName or teamName == "" or teamName == "TBD" then return "" end
local clean = teamName:gsub("'", "")
local light = clean .. '.png'
local dark = clean .. '_dark.png'
local container = html.create('span')
if mw.title.new('File:' .. light).exists then
container:wikitext('[[File:' .. light .. '|link=|class=logo-lightmode]]')
else
container:wikitext('[[File:Shield_team.png|link=|class=logo-lightmode]]')
end
if mw.title.new('File:' .. dark).exists then
container:wikitext('[[File:' .. dark .. '|link=|class=logo-darkmode]]')
elseif mw.title.new('File:' .. light).exists then
container:wikitext('[[File:' .. light .. '|link=|class=logo-darkmode]]')
else
container:wikitext('[[File:Shield_team_dark.png|link=|class=logo-darkmode]]')
end
return tostring(container)
end
function p.main(frame)
local args = frame:getParent().args
local currency = args.currency or "₹"
local tournamentName = args.tournament or mw.title.getCurrentTitle().text
-- Generate Unique ID for this specific table instance
-- This prevents conflicts if you have multiple tables on one page
local uniqueID = tostring(os.time()) .. tostring(math.random(100, 999))
local idContent = 'content-' .. uniqueID
local idBtnShow = 'btn-show-' .. uniqueID
local idBtnHide = 'btn-hide-' .. uniqueID
-- Main Grid Wrapper
local grid = html.create('div'):addClass('prize-section-grid')
-- ==========================================
-- COLUMN 1: RANKINGS (TEAMS)
-- ==========================================
local colRank = grid:tag('div'):addClass('prize-col-rank')
colRank:tag('div'):addClass('prize-header'):wikitext('Prize Pool Distribution')
local rankList = colRank:tag('div'):addClass('prize-list')
local hasRankData = false
local rankCount = 0
for i = 1, 64 do
if (args['team_'..i] and args['team_'..i] ~= "") or (args['prize_'..i] and args['prize_'..i] ~= "") then
rankCount = rankCount + 1
end
end
local collapseLimit = 10
local isCollapsible = (rankCount > collapseLimit)
-- Collapsible Container
local hiddenDiv = nil
if isCollapsible then
hiddenDiv = html.create('div')
:addClass('mw-collapsible mw-collapsed')
:attr('id', 'mw-customcollapsible-' .. idContent)
end
for i = 1, 64 do
local place = args['place_'..i] or (i .. '.')
local team = args['team_'..i]
local prize = args['prize_'..i]
local seed = args['seed_'..i]
if (team and team ~= "") or (prize and prize ~= "") then
hasRankData = true
if team and team ~= "" and cargo and cargo.store then
cargo.store('PrizeMoney', {
tournament = tournamentName,
placement = i,
team = team,
prize = prize,
award = ''
})
end
local targetContainer = rankList
if isCollapsible and i > collapseLimit then
targetContainer = hiddenDiv
end
local row = targetContainer:tag('div'):addClass('prize-row')
local rankClass = 'rank-other'
local rankIcon = place
if i == 1 then rankClass = 'rank-1'; rankIcon = '🥇' end
if i == 2 then rankClass = 'rank-2'; rankIcon = '🥈' end
if i == 3 then rankClass = 'rank-3'; rankIcon = '🥉' end
row:addClass(rankClass)
row:tag('div'):addClass('pz-rank'):wikitext(rankIcon)
local teamDiv = row:tag('div'):addClass('pz-team')
if team and team ~= "" then
teamDiv:wikitext(getLogo(team))
teamDiv:wikitext('[[' .. team .. ']]')
else
teamDiv:wikitext('TBD'):css('color', 'var(--text-muted)'):css('font-weight', 'normal')
end
local infoDiv = row:tag('div'):addClass('pz-info')
if prize and prize ~= "" then
infoDiv:tag('span'):addClass('pz-prize'):wikitext(currency .. ' ' .. formatMoney(prize))
end
if seed and seed ~= "" then
infoDiv:tag('span'):addClass('pz-seed'):wikitext(seed)
end
end
end
-- Assemble Ranking List
if not hasRankData then
rankList:tag('div'):addClass('prize-empty')
:wikitext('<i class="fa-solid fa-trophy"></i><br>Prize Pool TBD')
else
if isCollapsible then
rankList:wikitext(tostring(hiddenDiv))
-- DUAL BUTTON SYSTEM (Swaps on click using Unique IDs)
-- We toggle ALL THREE IDs at once: Content (Toggle), Button Show (Toggle), Button Hide (Toggle)
local toggleIds = 'mw-customtoggle-' .. idContent .. ' mw-customtoggle-' .. idBtnShow .. ' mw-customtoggle-' .. idBtnHide
-- Button 1: "View Full Distribution" (Visible initially)
-- Starts Visible. Toggling adds 'mw-collapsed' -> Hidden.
colRank:tag('div')
:attr('id', 'mw-customcollapsible-' .. idBtnShow)
:addClass('prize-show-more ' .. toggleIds)
:wikitext('View Full Distribution <i class="fa-solid fa-chevron-down"></i>')
-- Button 2: "Show Less" (Hidden initially)
-- Starts Hidden (mw-collapsed). Toggling removes 'mw-collapsed' -> Visible.
colRank:tag('div')
:attr('id', 'mw-customcollapsible-' .. idBtnHide)
:addClass('prize-show-more mw-collapsible mw-collapsed ' .. toggleIds)
:wikitext('Show Less <i class="fa-solid fa-chevron-up"></i>')
end
end
-- ==========================================
-- COLUMN 2: SPECIAL AWARDS
-- ==========================================
local colAward = grid:tag('div'):addClass('prize-col-award')
colAward:tag('div'):addClass('prize-header'):wikitext('Special Awards')
local awardList = colAward:tag('div'):addClass('prize-list')
local hasAwardData = false
for i = 1, 10 do
local awardName = args['award_'..i]
local winner = args['award_'..i..'_winner']
local team = args['award_'..i..'_team']
local prize = args['award_'..i..'_prize']
if awardName and awardName ~= "" then
hasAwardData = true
if (winner or team) and cargo and cargo.store then
cargo.store('PrizeMoney', {
tournament = tournamentName,
placement = '',
team = team or '',
player = winner or '',
prize = prize,
award = awardName
})
end
local row = awardList:tag('div'):addClass('award-row')
local info = row:tag('div'):addClass('award-info')
info:tag('div'):addClass('award-name'):wikitext(awardName)
local winDiv = info:tag('div'):addClass('award-winner')
if winner and winner ~= "" then
-- CASE 1: Player Won (LINKED)
if team and team ~= "" then winDiv:wikitext(getLogo(team)) end
winDiv:wikitext('[[' .. winner .. ']]')
elseif team and team ~= "" then
-- CASE 2: Team Won
winDiv:wikitext(getLogo(team))
winDiv:wikitext('[[' .. team .. ']]')
else
-- CASE 3: TBD
winDiv:wikitext("TBD"):css('color', 'var(--text-muted)'):css('font-weight', 'normal')
end
if prize and prize ~= "" then
row:tag('div'):addClass('award-prize'):wikitext(currency .. formatMoney(prize))
end
end
end
if not hasAwardData then
awardList:tag('div'):addClass('prize-empty')
:wikitext('<i class="fa-solid fa-medal"></i><br>Awards TBD')
end
return tostring(grid)
end
return p