Module:Player
From eSportsAmaze
More actions
Documentation for this module may be created at Module:Player/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
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'}
}
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
-- Get Rank
local function getKraftonRank(playerName)
local results = cargo.query("Krafton_Rankings", "rank", { where = "name = '" .. playerName:gsub("'", "\\'") .. "' AND type='Player'", limit = 1 })
if #results > 0 then return "#" .. results[1].rank else return "Unranked" end
end
-- ============================================================
-- MAIN 1: PLAYER INFOBOX (FLAT DESIGN)
-- ============================================================
function p.infobox(frame)
local args = frame:getParent().args
-- Clean Name (e.g. "Jonathan" instead of "Players/Jonathan")
local id = args.id or mw.title.getCurrentTitle().subpageText
local image = args.image or ""
local root = html.create('div'):addClass('flat-infobox')
-- 1. Header
root:tag('div'):addClass('fib-header')
:tag('div'):addClass('fib-title'):wikitext(id)
-- 2. Image
local imgContainer = root:tag('div'):addClass('fib-image')
if image ~= "" then
imgContainer:wikitext('[[File:' .. image .. '|250px]]')
else
-- Placeholder if no image
imgContainer:wikitext('[[File:Player_Placeholder.png|200px|link=]]')
end
-- 3. Calculations (Earnings)
-- We sum prizes where player = "Jonathan"
local earnings = "0"
if cargo and cargo.query then
local results = cargo.query("PrizeMoney", "SUM(prize)=total", { where = "player = '" .. id:gsub("'", "\\'") .. "'" })
if results and #results > 0 and results[1].total then
earnings = results[1].total
end
end
-- 4. Status & Rank Grid
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 == "banned" or s == "retired" then statusColor = "#dc2626"
end
end
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(getKraftonRank(id)):done()
-- 5. Role & Nation Grid
local grid2 = root:tag('div'):addClass('fib-grid')
grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Nationality'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.nationality or 'India'):done()
grid2:tag('div'):addClass('fib-cell'):tag('div'):addClass('fib-label-sm'):wikitext('Role'):done():tag('div'):addClass('fib-value-sm'):wikitext(args.role or 'Player'):done()
-- 6. Earnings (Highlight)
if earnings and tonumber(earnings) and tonumber(earnings) > 0 then
root:tag('div'):addClass('fib-prize')
:tag('div'):addClass('fib-label-sm'):wikitext('Approx. Earnings'):done()
:tag('div'):addClass('fib-prize-val'):wikitext(formatCurrency(earnings)):done()
end
-- 7. Info 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('Real Name', args.real_name)
addRow('Born', args.birth_date)
if args.current_team then
-- Add team logo if possible, otherwise just text
addRow('Current Team', '[[' .. args.current_team .. ']]')
end
addRow('Game', args.game or "BGMI")
-- 8. Team History (Mini Table)
-- We query Player_Former_Teams for a timeline
local history = cargo.query("Player_Former_Teams", "team, join_date, leave_date", {
where = "player_id = '" .. id:gsub("'", "\\'") .. "'",
orderBy = "join_date DESC",
limit = 10
})
if #history > 0 then
list:tag('div'):addClass('fib-header'):css('font-size','0.9em'):css('padding','8px'):css('margin-top','10px'):wikitext('Team History')
local histTable = list:tag('table'):css('width','100%'):css('font-size','0.85em'):css('border-collapse','collapse')
for _, hRow in ipairs(history) do
local tr = histTable:tag('tr'):css('border-bottom','1px solid #eee')
-- Team Name
tr:tag('td'):css('padding','4px 0'):css('font-weight','600'):wikitext('[[' .. hRow.team .. ']]')
-- Dates (Right Aligned)
local dates = (hRow.join_date and mw.getContentLanguage():formatDate('M y', hRow.join_date) or '?') .. ' – ' .. (hRow.leave_date and mw.getContentLanguage():formatDate('M y', hRow.leave_date) or 'Now')
tr:tag('td'):css('text-align','right'):css('color','#64748b'):wikitext(dates)
end
end
-- 9. Socials
root:wikitext(getSocials(args))
return tostring(root)
end
-- ============================================================
-- MAIN 2: FORMER PLAYERS TABLE (For Team Pages)
-- ============================================================
function p.formerPlayers(frame)
local args = frame:getParent().args
local team = args.team or mw.title.getCurrentTitle().text
local results = cargo.query("Player_Former_Teams, Players", "Player_Former_Teams.player_id=id, Players.real_name=Name, Player_Former_Teams.role=role, Player_Former_Teams.join_date=join_date, Player_Former_Teams.leave_date=leave_date", {
joinOn = "Player_Former_Teams.player_id = Players._pageName",
where = "Player_Former_Teams.team = '" .. team:gsub("'", "\\'") .. "' AND Player_Former_Teams.leave_date != ''",
orderBy = "Player_Former_Teams.leave_date DESC"
})
-- Updated to 'flat-table' class for consistent look
local root = html.create('table'):addClass('wikitable flat-table sortable'):css('width','100%')
local header = root:tag('tr')
header:tag('th'):wikitext('ID'); header:tag('th'):wikitext('Name'); header:tag('th'):wikitext('Role'); header:tag('th'):wikitext('Duration')
if #results > 0 then
for _, row in ipairs(results) do
local tr = root:tag('tr')
tr:tag('td'):css('font-weight','bold'):wikitext('[[' .. row.id .. ']]')
tr:tag('td'):wikitext(row.Name)
tr:tag('td'):wikitext(row.role)
local range = (row.join_date and mw.getContentLanguage():formatDate('M Y', row.join_date) or '?') .. ' – ' .. (row.leave_date and mw.getContentLanguage():formatDate('M Y', row.leave_date) or '?')
tr:tag('td'):attr('data-sort-value', row.leave_date):wikitext(range)
end
else
return '<div style="font-style:italic; color:#64748b; padding:10px;">No former players found for this team.</div>'
end
return tostring(root)
end
return p