Module:StreetBrawlItems: Difference between revisionsGive feedback
Jump to navigation
Jump to search
Add p.tier: three-column High/Normal/Low chance layout for a tier (prototype) (with help from vergir-bot LLM) |
p.tier: support style=icon|card, size, theme class, Middle-chance label (with help from vergir-bot LLM) |
||
| Line 54: | Line 54: | ||
end | end | ||
local function render_item(frame, code, style) | local function render_item(frame, code, style, size) | ||
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 | if style == "icon" then return frame:expandTemplate{title = "ItemIcon", args = {name}} end | ||
return frame:expandTemplate{title = "ItemBox", args = {name, showTierTag = "true", size = CARD_SIZE}} | return frame:expandTemplate{title = "ItemBox", args = {name, showTierTag = "true", size = size or CARD_SIZE}} | ||
end | end | ||
local function render_hero(frame, key) | local function render_hero(frame, key) | ||
| Line 140: | Line 140: | ||
end | end | ||
-- {{#invoke:StreetBrawlItems|tier|HERO|TIER|high=..| | -- {{#invoke:StreetBrawlItems|tier|HERO|TIER|style=icon|card|size=..|theme=..|high=..|middle=..|low=..}} | ||
-- Renders one tier as three columns: High chance (favored), | -- Renders one tier as three columns: High chance (favored), Middle chance | ||
-- (the leftover pool), Low chance (unfavored). Empty columns still render. | -- (the leftover pool), Low chance (unfavored). Empty columns still render. | ||
function p.tier(frame) | function p.tier(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 tier = tonumber(frame.args[2]) | 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 favored, unfavored = hero_sets(hkey) | local favored, unfavored = hero_sets(hkey) | ||
| Line 159: | Line 162: | ||
table.sort(normal, item_less) | table.sort(normal, item_less) | ||
table.sort(low, item_less) | table.sort(low, item_less) | ||
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, | for _, c in ipairs(codes) do local r = render_item(frame, c, style, size); 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=" | .. '<div class="' .. body_class .. '">' .. table.concat(parts, sep) .. '</div>' | ||
.. '</div>' | .. '</div>' | ||
end | end | ||
local hi = frame.args.high or "High chance" | local hi = frame.args.high or "High chance" | ||
local | local mid = frame.args.middle or "Middle chance" | ||
local lo = frame.args.low or "Low chance" | local lo = frame.args.low or "Low chance" | ||
return '<div class=" | local cls = "sb-tier" | ||
if theme ~= "" then cls = cls .. " " .. theme end | |||
return '<div class="' .. cls .. '">' | |||
.. col(high, "sb-col-high", hi) | .. col(high, "sb-col-high", hi) | ||
.. col(normal, "sb-col-normal", | .. col(normal, "sb-col-normal", mid) | ||
.. col(low, "sb-col-low", lo) | .. col(low, "sb-col-low", lo) | ||
.. '</div>' | .. '</div>' | ||