Module:Format: Difference between revisions
From eSportsAmaze
More actions
Esportsamaze (talk | contribs) Created page with "local p = {} local html = mw.html -- ============================================================ -- 1. STAGE TIMELINE (Vertical Flow) -- ============================================================ function p.timeline(frame) local args = frame:getParent().args local container = html.create('div'):addClass('fmt-timeline') for i = 1, 10 do local name = args['stage' .. i] local date = args['date' .. i] local desc = args['desc' .. i]..." |
Esportsamaze (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local html = mw.html | local html = mw.html | ||
-- Helper: Add ordinal suffix (1st, 2nd, 3rd) | |||
local function getOrdinal(n) | |||
local last = n % 10 | |||
local lastTwo = n % 100 | |||
if lastTwo >= 11 and lastTwo <= 13 then return n .. "th" end | |||
if last == 1 then return n .. "st" end | |||
if last == 2 then return n .. "nd" end | |||
if last == 3 then return n .. "rd" end | |||
return n .. "th" | |||
end | |||
-- ============================================================ | -- ============================================================ | ||
-- 1. STAGE TIMELINE ( | -- 1. STAGE TIMELINE (Fixed Layout & Bullet Points) | ||
-- ============================================================ | -- ============================================================ | ||
function p.timeline(frame) | function p.timeline(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
-- Added 'overflow-hidden' to CSS class to prevent Infobox overlap | |||
local container = html.create('div'):addClass('fmt-timeline') | local container = html.create('div'):addClass('fmt-timeline') | ||
| Line 17: | Line 29: | ||
local node = container:tag('div'):addClass('fmt-node') | local node = container:tag('div'):addClass('fmt-node') | ||
-- Left Marker | -- Left Marker | ||
node:tag('div'):addClass('fmt-marker') | node:tag('div'):addClass('fmt-marker') | ||
-- Content Box | -- Content Box | ||
local content = node:tag('div'):addClass('fmt-content') | local content = node:tag('div'):addClass('fmt-content') | ||
content:tag('div'):addClass('fmt-stage-title'):wikitext(name) | |||
-- Header (Flexbox for Inline Date) | |||
local header = content:tag('div'):addClass('fmt-header-row') | |||
header:tag('div'):addClass('fmt-stage-title'):wikitext(name) | |||
if date and date ~= "" then | if date and date ~= "" then | ||
header:tag('div'):addClass('fmt-date'):wikitext(date) | |||
end | end | ||
-- Description (Pre-processed for bullet points) | |||
if desc and desc ~= "" then | if desc and desc ~= "" then | ||
content:tag('div'):addClass('fmt-desc'):wikitext(desc) | -- frame:preprocess allows wikitext like * bullets to work if passed correctly | ||
-- wrapping in a div ensures new lines are respected | |||
content:tag('div'):addClass('fmt-desc'):wikitext(frame:preprocess(desc)) | |||
end | end | ||
end | end | ||
| Line 38: | Line 56: | ||
-- ============================================================ | -- ============================================================ | ||
-- 2. POINTS | -- 2. POINTS DISTRIBUTION (Vertical, Grouped, 2-Column) | ||
-- ============================================================ | -- ============================================================ | ||
function p.points(frame) | function p.points(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local system = args.type or "10" | local system = args.type or "10" | ||
-- | -- 1. Define Distribution | ||
local dist = {} | local dist = {} | ||
local killPts = args.kill_pts or 1 | local killPts = args.kill_pts or 1 | ||
| Line 53: | Line 71: | ||
dist = {10, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0} | dist = {10, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0} | ||
else | else | ||
for i = 1, 20 do | |||
for i = 1, | if args['p' .. i] then table.insert(dist, tonumber(args['p' .. i])) end | ||
table.insert(dist, args['p' .. i] | |||
end | end | ||
end | end | ||
| Line 62: | Line 79: | ||
-- Header | -- Header | ||
container:tag('div'):addClass('fmt-points-header'):wikitext(' | container:tag('div'):addClass('fmt-points-header'):wikitext('Points Distribution') | ||
-- | -- 2. Logic: Group Ranks with same points | ||
local | local groups = {} | ||
local currentPts = -1 | |||
local rangeStart = 1 | |||
for i, | -- Loop through dist + 1 to handle the last item closure | ||
local | for i = 1, #dist + 1 do | ||
local pts = dist[i] | |||
-- | if pts ~= currentPts then | ||
-- Close previous group if exists | |||
if i > 1 then | |||
local rangeEnd = i - 1 | |||
local rankLabel = "" | |||
if rangeStart == rangeEnd then | |||
rankLabel = getOrdinal(rangeStart) | |||
else | |||
rankLabel = getOrdinal(rangeStart) .. " – " .. getOrdinal(rangeEnd) | |||
end | |||
table.insert(groups, { | |||
label = rankLabel, | |||
val = currentPts, | |||
isTop3 = (rangeStart <= 3) | |||
}) | |||
end | |||
-- Start new group | |||
rangeStart = i | |||
currentPts = pts | |||
end | end | ||
end | |||
-- 3. Render: 2-Column Grid | |||
local grid = container:tag('div'):addClass('fmt-points-grid-vertical') | |||
for _, grp in ipairs(groups) do | |||
local row = grid:tag('div'):addClass('fmt-pt-row') | |||
-- Rank Label | |||
local labelDiv = row:tag('div'):addClass('fmt-pt-rank-v') | |||
labelDiv:wikitext(grp.label) | |||
-- Points Value | |||
local valDiv = row:tag('div'):addClass('fmt-pt-val-v') | |||
valDiv:wikitext(grp.val) | |||
-- Add color classes for Top 3 | |||
if grp.isTop3 and grp.val > 0 then | |||
row:addClass('row-top3') | |||
end | |||
if grp.val == 0 then | |||
row:addClass('row-zero') | |||
end | |||
end | end | ||
-- Kill Points | -- Kill Points Footer | ||
local killBox = container:tag('div'):addClass('fmt-kill-box') | local killBox = container:tag('div'):addClass('fmt-kill-box') | ||
killBox:wikitext('Each Finish: <b>' .. killPts .. ' Point</b>') | killBox:wikitext('Each Finish: <b>' .. killPts .. ' Point</b>') | ||
| Line 90: | Line 145: | ||
-- ============================================================ | -- ============================================================ | ||
-- 3. MAP ROTATION ( | -- 3. MAP ROTATION (Unchanged) | ||
-- ============================================================ | -- ============================================================ | ||
function p.maps(frame) | function p.maps(frame) | ||
| Line 101: | Line 156: | ||
local list = container:tag('div'):addClass('fmt-maps-list') | local list = container:tag('div'):addClass('fmt-maps-list') | ||
local mapDict = { | local mapDict = { | ||
e = {name="Erangel", class="map-erangel"}, | e = {name="Erangel", class="map-erangel"}, | ||
| Line 115: | Line 168: | ||
local m = args[i] or args['m' .. i] | local m = args[i] or args['m' .. i] | ||
if m and m ~= "" then | if m and m ~= "" then | ||
local key = m:lower():sub(1,1) | local key = m:lower():sub(1,1) | ||
local data = mapDict[key] or {name=m, class="map-tbd"} | local data = mapDict[key] or {name=m, class="map-tbd"} | ||
-- Full word fallbacks | |||
-- | |||
if m:lower() == "rondo" then data = mapDict['r'] end | if m:lower() == "rondo" then data = mapDict['r'] end | ||
if m:lower() == "erangel" then data = mapDict['e'] end | if m:lower() == "erangel" then data = mapDict['e'] end | ||
| Line 125: | Line 177: | ||
if m:lower() == "vikendi" then data = mapDict['v'] end | if m:lower() == "vikendi" then data = mapDict['v'] end | ||
list:tag('div'):addClass('fmt-map-item'):tag('span'):addClass('fmt-map-badge ' .. data.class):wikitext(data.name) | |||
end | end | ||
end | end | ||
return tostring(container) | return tostring(container) | ||
end | end | ||
return p | return p | ||
Revision as of 05:35, 6 February 2026
Documentation for this module may be created at Module:Format/doc
local p = {}
local html = mw.html
-- Helper: Add ordinal suffix (1st, 2nd, 3rd)
local function getOrdinal(n)
local last = n % 10
local lastTwo = n % 100
if lastTwo >= 11 and lastTwo <= 13 then return n .. "th" end
if last == 1 then return n .. "st" end
if last == 2 then return n .. "nd" end
if last == 3 then return n .. "rd" end
return n .. "th"
end
-- ============================================================
-- 1. STAGE TIMELINE (Fixed Layout & Bullet Points)
-- ============================================================
function p.timeline(frame)
local args = frame:getParent().args
-- Added 'overflow-hidden' to CSS class to prevent Infobox overlap
local container = html.create('div'):addClass('fmt-timeline')
for i = 1, 10 do
local name = args['stage' .. i]
local date = args['date' .. i]
local desc = args['desc' .. i]
if name and name ~= "" then
local node = container:tag('div'):addClass('fmt-node')
-- Left Marker
node:tag('div'):addClass('fmt-marker')
-- Content Box
local content = node:tag('div'):addClass('fmt-content')
-- Header (Flexbox for Inline Date)
local header = content:tag('div'):addClass('fmt-header-row')
header:tag('div'):addClass('fmt-stage-title'):wikitext(name)
if date and date ~= "" then
header:tag('div'):addClass('fmt-date'):wikitext(date)
end
-- Description (Pre-processed for bullet points)
if desc and desc ~= "" then
-- frame:preprocess allows wikitext like * bullets to work if passed correctly
-- wrapping in a div ensures new lines are respected
content:tag('div'):addClass('fmt-desc'):wikitext(frame:preprocess(desc))
end
end
end
return tostring(container)
end
-- ============================================================
-- 2. POINTS DISTRIBUTION (Vertical, Grouped, 2-Column)
-- ============================================================
function p.points(frame)
local args = frame:getParent().args
local system = args.type or "10"
-- 1. Define Distribution
local dist = {}
local killPts = args.kill_pts or 1
if system == "15" then
dist = {15, 12, 10, 8, 6, 4, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0}
elseif system == "10" then
dist = {10, 6, 5, 4, 3, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}
else
for i = 1, 20 do
if args['p' .. i] then table.insert(dist, tonumber(args['p' .. i])) end
end
end
local container = html.create('div'):addClass('fmt-points-container')
-- Header
container:tag('div'):addClass('fmt-points-header'):wikitext('Points Distribution')
-- 2. Logic: Group Ranks with same points
local groups = {}
local currentPts = -1
local rangeStart = 1
-- Loop through dist + 1 to handle the last item closure
for i = 1, #dist + 1 do
local pts = dist[i]
if pts ~= currentPts then
-- Close previous group if exists
if i > 1 then
local rangeEnd = i - 1
local rankLabel = ""
if rangeStart == rangeEnd then
rankLabel = getOrdinal(rangeStart)
else
rankLabel = getOrdinal(rangeStart) .. " – " .. getOrdinal(rangeEnd)
end
table.insert(groups, {
label = rankLabel,
val = currentPts,
isTop3 = (rangeStart <= 3)
})
end
-- Start new group
rangeStart = i
currentPts = pts
end
end
-- 3. Render: 2-Column Grid
local grid = container:tag('div'):addClass('fmt-points-grid-vertical')
for _, grp in ipairs(groups) do
local row = grid:tag('div'):addClass('fmt-pt-row')
-- Rank Label
local labelDiv = row:tag('div'):addClass('fmt-pt-rank-v')
labelDiv:wikitext(grp.label)
-- Points Value
local valDiv = row:tag('div'):addClass('fmt-pt-val-v')
valDiv:wikitext(grp.val)
-- Add color classes for Top 3
if grp.isTop3 and grp.val > 0 then
row:addClass('row-top3')
end
if grp.val == 0 then
row:addClass('row-zero')
end
end
-- Kill Points Footer
local killBox = container:tag('div'):addClass('fmt-kill-box')
killBox:wikitext('Each Finish: <b>' .. killPts .. ' Point</b>')
return tostring(container)
end
-- ============================================================
-- 3. MAP ROTATION (Unchanged)
-- ============================================================
function p.maps(frame)
local args = frame:getParent().args
local container = html.create('div'):addClass('fmt-maps-container')
if args.title then
container:tag('div'):addClass('fmt-maps-header'):wikitext(args.title)
end
local list = container:tag('div'):addClass('fmt-maps-list')
local mapDict = {
e = {name="Erangel", class="map-erangel"},
m = {name="Miramar", class="map-miramar"},
s = {name="Sanhok", class="map-sanhok"},
v = {name="Vikendi", class="map-vikendi"},
r = {name="Rondo", class="map-rondo"},
tbd = {name="TBD", class="map-tbd"}
}
for i = 1, 10 do
local m = args[i] or args['m' .. i]
if m and m ~= "" then
local key = m:lower():sub(1,1)
local data = mapDict[key] or {name=m, class="map-tbd"}
-- Full word fallbacks
if m:lower() == "rondo" then data = mapDict['r'] end
if m:lower() == "erangel" then data = mapDict['e'] end
if m:lower() == "miramar" then data = mapDict['m'] end
if m:lower() == "sanhok" then data = mapDict['s'] end
if m:lower() == "vikendi" then data = mapDict['v'] end
list:tag('div'):addClass('fmt-map-item'):tag('span'):addClass('fmt-map-badge ' .. data.class):wikitext(data.name)
end
end
return tostring(container)
end
return p