Module:StreetBrawlItems: Difference between revisions

Populate Street Brawl item-weighting helper: joins Data:StreetBrawlData.json with ItemData/HeroData, renders favored/unfavored/common/counter groups for hero and item pages (with help from vergir-bot LLM)
Wrap rendered groups in flex rows so cards and hero icons have consistent spacing (with help from vergir-bot LLM)
Line 40: Line 40:
end
end


-- Wraps a rendered list with an optional bold label / italic note, or a collapsible box.
-- Lays rendered members out in a wrapping flex row with a consistent gap.
-- Returns "" when the list is empty, so nothing (not even the label) shows.
local function flexrow(parts, gap, center)
if #parts == 0 then return "" end
local align = center and "center" or "flex-start"
return '<div style="display:flex; flex-wrap:wrap; gap:' .. gap .. '; align-items:' .. align .. '">'
.. table.concat(parts) .. '</div>'
end
 
-- Wraps a rendered row with an optional bold label / italic note, or a collapsible box.
-- Returns "" when the row is empty, so nothing (not even the label) shows.
local function wrap(inner, label, note, collapse)
local function wrap(inner, label, note, collapse)
if inner == "" then return "" end
if inner == "" then return "" end
Line 105: Line 113:
local parts = {}
local parts = {}
for _, c in ipairs(codes) do local r = render_item(frame, c, style); if r then parts[#parts + 1] = r end end
for _, c in ipairs(codes) do local r = render_item(frame, c, style); if r then parts[#parts + 1] = r end end
return wrap(table.concat(parts), frame.args.label, nil, collapse)
local is_icon = (style == "icon")
local inner = flexrow(parts, is_icon and "4px 10px" or "8px", is_icon)
return wrap(inner, frame.args.label, nil, collapse)
end
end


Line 126: Line 136:
if heading and heading ~= "" then out[#out + 1] = "=== " .. heading .. " ===" end
if heading and heading ~= "" then out[#out + 1] = "=== " .. heading .. " ===" end
local note = frame.args.note
local note = frame.args.note
if note and note ~= "" then out[#out + 1] = "''" .. note .. "''\n" end
if note and note ~= "" then out[#out + 1] = "''" .. note .. "''" end
out[#out + 1] = table.concat(parts)
out[#out + 1] = flexrow(parts, "8px", false)
return table.concat(out, "\n")
return table.concat(out, "\n")
end
end
Line 151: Line 161:
local parts = {}
local parts = {}
for _, k in ipairs(list) do local r = render_hero(frame, k); if r then parts[#parts + 1] = r end end
for _, k in ipairs(list) do local r = render_hero(frame, k); if r then parts[#parts + 1] = r end end
return wrap(table.concat(parts), frame.args.label, frame.args.note, false)
local inner = flexrow(parts, "4px 10px", true)
return wrap(inner, frame.args.label, frame.args.note, false)
end
end