Fix mediaCue count on loadData tables
Center award labels under matching ribbon images in one rack table
Line 1,463: Line 1,463:
end
end


local function formatAwardsRibbons(raw, rowRaw)
local function awardRibbonRows(raw, rowRaw)
-- Prefer explicit Wikipedia row layout when present
-- Prefer explicit Wikipedia row layout when present
local rows = splitAwardRows(rowRaw or '')
local rows = splitAwardRows(rowRaw or '')
if #rows == 0 then
if #rows > 0 then
raw = trim(raw)
return rows
if raw == '' then
end
return ''
raw = trim(raw)
if raw == '' then
return {}
end
local files = {}
for part in mw.text.gsplit(raw, ';', true) do
part = trim(part)
part = mw.ustring.gsub(part, '^[Ff]ile:', '')
if part ~= '' then
table.insert(files, part)
end
end
local files = {}
end
for part in mw.text.gsplit(raw, ';', true) do
if #files == 0 then
part = trim(part)
return {}
part = mw.ustring.gsub(part, '^[Ff]ile:', '')
end
if part ~= '' then
-- Fallback: pack ~4 across
table.insert(files, part)
local perRow = 4
end
rows = {}
local cur = {}
for _, file in ipairs(files) do
table.insert(cur, file)
if #cur == perRow then
table.insert(rows, cur)
cur = {}
end
end
if #files == 0 then
end
return ''
if #cur > 0 then
end
table.insert(rows, cur)
-- Fallback: pack ~4 across
end
local perRow = 4
return rows
rows = {}
end
local cur = {}
 
for _, file in ipairs(files) do
local function awardRowsMatch(ribbonRows, labelRows)
table.insert(cur, file)
if #ribbonRows == 0 or #ribbonRows ~= #labelRows then
if #cur == perRow then
return false
table.insert(rows, cur)
end
cur = {}
for i, cells in ipairs(ribbonRows) do
end
if #cells ~= #(labelRows[i] or {}) then
end
return false
if #cur > 0 then
table.insert(rows, cur)
end
end
end
end
-- One table per row so short rows (e.g. 2 ribbons) center like full rows
return true
end
 
local function formatAwardsRibbons(raw, rowRaw, labelRaw)
local rows = awardRibbonRows(raw, rowRaw)
if #rows == 0 then
return '', false
end
local labelRows = splitAwardRows(labelRaw or '')
local labeled = awardRowsMatch(rows, labelRows)
-- One table per row so short rows (e.g. 2 ribbons) center like full rows.
-- When labels match ribbon cells, put captions in the same table so each
-- name sits centered under its ribbon (equal column widths).
local out = {}
local out = {}
for _, cells in ipairs(rows) do
for i, cells in ipairs(rows) do
table.insert(out, '{| class="soldier-ribbon-rack"')
if labeled then
table.insert(out, '{| class="soldier-ribbon-rack soldier-awards-labeled"')
else
table.insert(out, '{| class="soldier-ribbon-rack"')
end
table.insert(out, '|-')
table.insert(out, '|-')
for _, file in ipairs(cells) do
for _, file in ipairs(cells) do
file = mw.ustring.gsub(file, '^[Ff]ile:', '')
file = mw.ustring.gsub(file, '^[Ff]ile:', '')
table.insert(out, '| [[File:' .. file .. '|106px|link=]]')
table.insert(out, '| [[File:' .. file .. '|106px|link=]]')
end
if labeled then
table.insert(out, '|-')
for _, label in ipairs(labelRows[i]) do
table.insert(out, '| class="soldier-award-caption" | ' .. label)
end
end
end
table.insert(out, '|}')
table.insert(out, '|}')
end
end
return table.concat(out, '\n')
return table.concat(out, '\n'), labeled
end
end


Line 1,929: Line 1,964:


function p.awardsSection(frame)
function p.awardsSection(frame)
local ribbons = formatAwardsRibbons(
local gridRaw = parentArg(frame, 'awards_grid')
local ribbons, labelsInRack = formatAwardsRibbons(
parentArg(frame, 'awards_ribbons'),
parentArg(frame, 'awards_ribbons'),
parentArg(frame, 'awards_ribbon_rows')
parentArg(frame, 'awards_ribbon_rows'),
gridRaw
)
)
local grid = formatAwardsGrid(parentArg(frame, 'awards_grid'))
-- Skip the separate label table when captions already sit under ribbons
local grid = ''
if not labelsInRack then
grid = formatAwardsGrid(gridRaw)
end
local extras = formatAwardsLegend(parentArg(frame, 'awards_extra'))
local extras = formatAwardsLegend(parentArg(frame, 'awards_extra'))
-- Fallback: flat awards list when no grid was extracted
-- Fallback: flat awards list when no grid was extracted
if grid == '' and extras == '' then
if grid == '' and extras == '' and not labelsInRack then
extras = formatAwardsLegend(parentArg(frame, 'awards'))
extras = formatAwardsLegend(parentArg(frame, 'awards'))
end
end