Module:StreetBrawlItems: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
mNo edit summary
Vergir (talk | contribs)
Finalize: keep only the Fill card layout; drop legacy hero renderer, grid mode, theme/style/size options (with help from vergir-bot LLM)
Line 7: Line 7:
-- Slot display order: Weapon -> Vitality (Armor) -> Spirit (Tech)
-- Slot display order: Weapon -> Vitality (Armor) -> Spirit (Tech)
local SLOT_RANK = { Weapon = 1, Armor = 2, Tech = 3 }
local SLOT_RANK = { Weapon = 1, Armor = 2, Tech = 3 }
-- Default card scale passed to ItemBox (tier columns and counter cards).
-- Card scale passed to ItemBox.
local CARD_SIZE = "0.667"
local CARD_SIZE = "0.667"


Line 54: Line 54:
end
end


local function render_item(frame, code, style, size)
local function render_item(frame, code)
local name = iname(code); if not name then return nil end
local name = iname(code); if not name then return nil end
if style == "icon" then return frame:expandTemplate{title = "ItemIcon", args = {name}} end
local args = { name, size = CARD_SIZE }
local args = { name, size = size or CARD_SIZE }
-- Legendary (tier 5) cards omit the tier badge; it is redundant in the Legendary tier.
-- Legendary (tier 5) cards omit the tier badge; it is redundant in the Legendary tier.
if itier(code) ~= 5 then args.showTierTag = "true" end
if itier(code) ~= 5 then args.showTierTag = "true" end
Line 74: Line 73:


local function hero_sets(hkey)
local function hero_sets(hkey)
local favored, unfavored, special, counter = {}, {}, {}, {}
local favored, unfavored, counter = {}, {}, {}
for _, o in ipairs(sb.Outliers) do
for _, o in ipairs(sb.Outliers) do
if o.Hero == hkey then
if o.Hero == hkey then
if o.Bucket == "Good" then favored[o.Item] = true; special[o.Item] = true
if o.Bucket == "Good" then favored[o.Item] = true
elseif type(o.Weight) == "number" and o.Weight < 1 then unfavored[o.Item] = true; special[o.Item] = true end
elseif type(o.Weight) == "number" and o.Weight < 1 then unfavored[o.Item] = true end
if o.Counter ~= nil then counter[#counter + 1] = o.Item end
if o.Counter ~= nil then counter[#counter + 1] = o.Item end
end
end
end
end
return favored, unfavored, special, counter
return favored, unfavored, counter
end
end


Line 116: Line 115:


-- Builds one tier as conditional columns:
-- Builds one tier as conditional columns:
--  High chance (favored) 35% and Middle chance (pool) fill the rest.
--  High chance (favored) takes 35%, the middle column fills the rest.
--  Low chance (unfavored) is dropped when empty; a narrow one-card column on the right
--  Low chance (unfavored) is dropped when empty; a narrow column on the right when
--  when High is present; a fit-content column on the right when High is absent.
--  High is present; a fit-content column on the right when High is absent.
local function tier_columns(frame, hkey, tier, style, size, theme, hi, mid, lo)
local function tier_columns(frame, hkey, tier, hi, mid, lo)
local high, normal, low = collect(hkey, tier)
local high, normal, low = collect(hkey, tier)
local body_class = (style == "card") and "sb-col-body sb-col-cards" or "sb-col-body"
local sep = (style == "card") and "" or "<br>"


local function col(codes, cls, head)
local function col(codes, cls, head)
local parts = {}
local parts = {}
for _, c in ipairs(codes) do local r = render_item(frame, c, style, size); if r then parts[#parts + 1] = r end end
for _, c in ipairs(codes) do local r = render_item(frame, c); if r then parts[#parts + 1] = r end end
return '<div class="sb-col ' .. cls .. '">'
return '<div class="sb-col ' .. cls .. '">'
.. '<div class="sb-col-head">' .. head .. '</div>'
.. '<div class="sb-col-head">' .. head .. '</div>'
.. '<div class="' .. body_class .. '">' .. table.concat(parts, sep) .. '</div>'
.. '<div class="sb-col-body sb-col-cards">' .. table.concat(parts) .. '</div>'
.. '</div>'
.. '</div>'
end
end
local cls = "sb-tier"
if theme ~= "" then cls = cls .. " " .. theme end


local out = {}
local out = {}
Line 145: Line 139:
out[#out + 1] = col(low, "sb-col-low " .. low_w, lo)
out[#out + 1] = col(low, "sb-col-low " .. low_w, lo)
end
end
return '<div class="' .. cls .. '">' .. table.concat(out) .. '</div>'
return '<div class="sb-tier">' .. table.concat(out) .. '</div>'
end
 
-- {{#invoke:StreetBrawlItems|hero|HERO|GROUP|TIER|label=..|collapse=yes|style=card|icon}}
-- Legacy: superseded by p.tier, kept for reference.
function p.hero(frame)
local hkey = hero_key(frame.args[1]); if not hkey then return "" end
local group = mw.text.trim(frame.args[2] or "")
local tier = tonumber(frame.args[3])
local style = frame.args.style
if not style or style == "" then style = (group == "common") and "icon" or "card" end
local label = frame.args.label or ""
 
local favored, unfavored, special = hero_sets(hkey)
local pred
if group == "favored" then pred = function(c) return favored[c] end
elseif group == "unfavored" then pred = function(c) return unfavored[c] end
elseif group == "common" then pred = function(c) return not special[c] end
else return "" end
 
local codes = {}
for _, c in ipairs(sb.AvailableItems) do
if iok(c) and (tier == nil or itier(c) == tier) and pred(c) then codes[#codes + 1] = c end
end
table.sort(codes, item_less)
 
local parts = {}
for _, c in ipairs(codes) do local r = render_item(frame, c, style); if r then parts[#parts + 1] = r end end
if #parts == 0 then return "" end
 
local row_class = (style == "icon") and "sb-icons" or "sb-cards"
local out = '<div class="sb-group">'
if label ~= "" then out = out .. '<div class="sb-label">' .. label .. '</div>' end
return out .. classdiv(parts, row_class) .. '</div>'
end
 
-- {{#invoke:StreetBrawlItems|tier|HERO|TIER|style=icon|card|size=..|theme=..|layout=grid|high=..|middle=..|low=..}}
function p.tier(frame)
local hkey = hero_key(frame.args[1]); if not hkey then return "" end
local tier = tonumber(frame.args[2])
local style = (frame.args.style == "card") and "card" or "icon"
local size = frame.args.size
local theme = frame.args.theme or ""
local hi = frame.args.high or "High chance"
local mid = frame.args.middle or "Average chance"
local lo = frame.args.low or "Low chance"
 
if frame.args.layout == "grid" then
local high, normal, low = collect(hkey, tier)
local function chips(codes, chance)
local out = {}
for _, c in ipairs(codes) do
local r = render_item(frame, c, "card", size)
if r then out[#out + 1] = '<span class="sb-chip ' .. chance .. '">' .. r .. '</span>' end
end
return table.concat(out)
end
return '<div class="sb-grid">'
.. chips(high, "sb-chip-high")
.. chips(normal, "sb-chip-normal")
.. chips(low, "sb-chip-low")
.. '</div>'
end
 
return tier_columns(frame, hkey, tier, style, size, theme, hi, mid, lo)
end
end


-- {{#invoke:StreetBrawlItems|tiers|HERO|style=..|size=..|theme=..}} -> all five tiers, each with a heading.
-- {{#invoke:StreetBrawlItems|tiers|HERO|high=..|middle=..|low=..}}
-- All five tiers, each under its own heading.
function p.tiers(frame)
function p.tiers(frame)
local hkey = hero_key(frame.args[1]); if not hkey then return "" end
local hkey = hero_key(frame.args[1]); if not hkey then return "" end
local style = (frame.args.style == "card") and "card" or "icon"
local size = frame.args.size
local theme = frame.args.theme or ""
local hi = frame.args.high or "High chance"
local hi = frame.args.high or "High chance"
local mid = frame.args.middle or "Average chance"
local mid = frame.args.middle or "Average chance"
Line 225: Line 153:
local out = {}
local out = {}
for t = 1, 5 do
for t = 1, 5 do
out[#out + 1] = "=== " .. labels[t] .. " ===\n" .. tier_columns(frame, hkey, t, style, size, theme, hi, mid, lo)
out[#out + 1] = "=== " .. labels[t] .. " ===\n" .. tier_columns(frame, hkey, t, hi, mid, lo)
end
end
return table.concat(out, "\n\n")
return table.concat(out, "\n\n")
Line 231: Line 159:


-- {{#invoke:StreetBrawlItems|hero_counter|HERO|heading=..|note=..}}
-- {{#invoke:StreetBrawlItems|hero_counter|HERO|heading=..|note=..}}
-- The whole counter block (heading + note + cards), or "" when the hero has none.
function p.hero_counter(frame)
function p.hero_counter(frame)
local hkey = hero_key(frame.args[1]); if not hkey then return "" end
local hkey = hero_key(frame.args[1]); if not hkey then return "" end
local _, _, _, counter = hero_sets(hkey)
local _, _, counter = hero_sets(hkey)


local codes = {}
local codes = {}
Line 241: Line 170:


local parts = {}
local parts = {}
for _, c in ipairs(codes) do local r = render_item(frame, c, "card"); if r then parts[#parts + 1] = r end end
for _, c in ipairs(codes) do local r = render_item(frame, c); if r then parts[#parts + 1] = r end end


local out = {}
local out = {}
Line 253: Line 182:


-- {{#invoke:StreetBrawlItems|item|ITEM|GROUP|label=..|note=..}}
-- {{#invoke:StreetBrawlItems|item|ITEM|GROUP|label=..|note=..}}
-- GROUP = favored | unfavored | counter
function p.item(frame)
function p.item(frame)
local code = item_code(frame.args[1]); if not code then return "" end
local code = item_code(frame.args[1]); if not code then return "" end