Module:Lists: Difference between revisions
From eSportsAmaze
More actions
No edit summary |
Esportsamaze (talk | contribs) No edit summary |
||
| Line 67: | Line 67: | ||
-- Priority Order: Specific roles first | -- Priority Order: Specific roles first | ||
if r:find("igl") then rClass = "role-igl" | if r:find("igl") then rClass = "role-igl" | ||
elseif r:find("filter") then rClass = "role-filter" | |||
elseif r:find("entry") then rClass = "role-entry" | elseif r:find("entry") then rClass = "role-entry" | ||
elseif r:find("assault") then rClass = "role-assault" | elseif r:find("assault") then rClass = "role-assault" | ||
Revision as of 11:42, 1 February 2026
Documentation for this module may be created at Module:Lists/doc
local p = {}
local cargo = mw.ext.cargo
local html = mw.html
-- ============================================================
-- HELPER: Sanitize
-- ============================================================
local function clean(s)
if not s then return nil end
return s:gsub("[\r\n]", ""):gsub("^%s*(.-)%s*$", "%1")
end
-- ============================================================
-- 1. PLAYERS LIST (Updated with ALL Roles)
-- ============================================================
function p.players(frame)
local args = frame.args
local offset = tonumber(args.offset) or 0
local limit = 50
local results = cargo.query(
"Players",
"_pageName, id, real_name, image, current_team, role, nationality",
{
orderBy = "id ASC",
limit = limit,
offset = offset
}
)
local container = html.create('div'):addClass('db-list-container')
if not results or #results == 0 then
return '<div style="padding:40px; text-align:center; color:#64748b;">No players found.</div>'
end
for _, row in ipairs(results) do
local div = container:tag('div'):addClass('db-row player-row')
-- 1. Image
local imgDiv = div:tag('div'):addClass('db-img')
if row.image and row.image ~= "" then
imgDiv:wikitext('[[File:' .. row.image .. '|50px|link=' .. row._pageName .. ']]')
else
imgDiv:wikitext('[[File:Player_Placeholder.png|50px|link=' .. row._pageName .. ']]')
end
-- 2. Identity
local idDiv = div:tag('div'):addClass('db-info')
idDiv:tag('div'):addClass('db-title'):wikitext('[[' .. row._pageName .. '|' .. row.id .. ']]')
idDiv:tag('div'):addClass('db-subtitle'):wikitext(row.real_name or "")
-- 3. Team
local teamDiv = div:tag('div'):addClass('db-meta')
if row.current_team and row.current_team ~= "" then
teamDiv:wikitext('[[File:' .. row.current_team .. '.png|25px|link=' .. row.current_team .. ']] [[' .. row.current_team .. ']]')
else
teamDiv:css('opacity','0.5'):wikitext("Free Agent")
end
-- 4. Role Pill (UPDATED LOGIC)
local roleDiv = div:tag('div'):addClass('db-status')
if row.role then
local rClass = "role-def"
local r = row.role:lower()
-- Priority Order: Specific roles first
if r:find("igl") then rClass = "role-igl"
elseif r:find("filter") then rClass = "role-filter"
elseif r:find("entry") then rClass = "role-entry"
elseif r:find("assault") then rClass = "role-assault"
elseif r:find("filter") then rClass = "role-filter"
elseif r:find("support") then rClass = "role-support"
elseif r:find("medic") then rClass = "role-support"
elseif r:find("scout") then rClass = "role-scout"
elseif r:find("sniper") then rClass = "role-snip"
elseif r:find("coach") then rClass = "role-coach"
elseif r:find("analyst") then rClass = "role-coach"
elseif r:find("manager") then rClass = "role-manager"
elseif r:find("fragger") then rClass = "role-assault" -- Fallback for generic fragger
end
roleDiv:tag('span'):addClass('role-badge ' .. rClass):wikitext(row.role)
end
end
-- Pagination
local nav = container:tag('div'):addClass('pagination-controls')
if offset > 0 then
nav:tag('span'):addClass('page-btn'):wikitext('[' .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().text, {offset=math.max(0, offset-limit)})) .. ' « Previous]')
end
if #results == limit then
nav:tag('span'):addClass('page-btn'):wikitext('[' .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().text, {offset=offset+limit})) .. ' Next »]')
end
return tostring(container)
end
-- ============================================================
-- 2. TEAMS LIST
-- ============================================================
function p.teams(frame)
local args = frame.args
local offset = tonumber(args.offset) or 0
local limit = 50
local results = cargo.query(
"Teams",
"_pageName, name, image, image_dark, status, country",
{
orderBy = "name ASC",
limit = limit,
offset = offset
}
)
local container = html.create('div'):addClass('db-list-container')
if not results or #results == 0 then
return '<div style="padding:40px; text-align:center; color:var(--text-muted);">No teams found in database.<br><small>Edit and Save a Team page to register it.</small></div>'
end
for _, row in ipairs(results) do
local div = container:tag('div'):addClass('db-row team-row')
local imgFile = row.image
if not imgFile or imgFile == "" then imgFile = "Shield_team.png" end
div:tag('div'):addClass('db-img'):wikitext('[[File:' .. imgFile .. '|50px|link=' .. row._pageName .. ']]')
local info = div:tag('div'):addClass('db-info')
info:tag('div'):addClass('db-title'):wikitext('[[' .. row._pageName .. '|' .. row.name .. ']]')
if row.country then
local flag = "Flag_" .. row.country .. ".png"
info:tag('div'):addClass('db-subtitle'):wikitext('[[File:' .. flag .. '|15px|link=]] ' .. row.country)
end
local statusDiv = div:tag('div'):addClass('db-status')
local sClass = "status-active"
local sText = row.status or "Active"
if sText:lower() ~= "active" then sClass = "status-inactive" end
statusDiv:tag('span'):addClass('status-badge ' .. sClass):wikitext(sText)
end
local nav = container:tag('div'):addClass('pagination-controls')
if offset > 0 then
nav:tag('span'):addClass('page-btn'):wikitext('[' .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().text, {offset=math.max(0, offset-limit)})) .. ' « Previous]')
end
if #results == limit then
nav:tag('span'):addClass('page-btn'):wikitext('[' .. tostring(mw.uri.fullUrl(mw.title.getCurrentTitle().text, {offset=offset+limit})) .. ' Next »]')
end
return tostring(container)
end
return p