Module:StreetBrawlItems: Difference between revisionsGive feedback
mNo edit summary |
Remove unused item/item_in_pool functions and now-dead helpers; rename normal to average; move all display text to the caller; anchor the gate above the Tier 1 heading so the reveal link lands on it (with help from vergir-bot LLM) |
||
| Line 10: | Line 10: | ||
local CARD_SIZE = "0.667" | local CARD_SIZE = "0.667" | ||
local NAME_TO_KEY | local NAME_TO_KEY = {} | ||
for key, h in pairs(heroes) do | for key, h in pairs(heroes) do | ||
if type(h) == "table" and h.Name then | if type(h) == "table" and h.Name then | ||
NAME_TO_KEY[mw.ustring.lower(h.Name)] = key | NAME_TO_KEY[mw.ustring.lower(h.Name)] = key | ||
end | end | ||
end | end | ||
| Line 60: | Line 58: | ||
if itier(code) ~= 5 then args.showTierTag = "true" end | if itier(code) ~= 5 then args.showTierTag = "true" end | ||
return frame:expandTemplate{title = "ItemBox", args = args} | return frame:expandTemplate{title = "ItemBox", args = args} | ||
end | end | ||
| Line 91: | Line 85: | ||
end | end | ||
-- Returns sorted high (favored), | -- Returns sorted high (favored), average (pool), low (unfavored) item-code lists for a tier. | ||
local function collect(hkey, tier) | local function collect(hkey, tier) | ||
local favored, unfavored = hero_sets(hkey) | local favored, unfavored = hero_sets(hkey) | ||
local high, | local high, average, low = {}, {}, {} | ||
for _, c in ipairs(sb.AvailableItems) do | for _, c in ipairs(sb.AvailableItems) do | ||
if iok(c) and (tier == nil or itier(c) == tier) then | if iok(c) and (tier == nil or itier(c) == tier) then | ||
if favored[c] then high[#high + 1] = c | if favored[c] then high[#high + 1] = c | ||
elseif unfavored[c] then low[#low + 1] = c | elseif unfavored[c] then low[#low + 1] = c | ||
else | else average[#average + 1] = c end | ||
end | end | ||
end | end | ||
table.sort(high, item_less) | table.sort(high, item_less) | ||
table.sort( | table.sort(average, item_less) | ||
table.sort(low, item_less) | table.sort(low, item_less) | ||
return high, | return high, average, low | ||
end | end | ||
-- Builds one tier as conditional columns: | -- Builds one tier as conditional columns: | ||
-- High chance (favored) takes 35%, the | -- High chance (favored) takes 35%, the average column fills the rest. | ||
-- Low chance (unfavored) is dropped when empty; a narrow column on the right when | -- Low chance (unfavored) is dropped when empty; a narrow column on the right 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, hi, | local function tier_columns(frame, hkey, tier, hi, avg, lo) | ||
local high, | local high, average, low = collect(hkey, tier) | ||
local function col(codes, cls, head) | local function col(codes, cls, head) | ||
| Line 141: | Line 122: | ||
out[#out + 1] = col(high, "sb-col-high sb-w-high", hi) | out[#out + 1] = col(high, "sb-col-high sb-w-high", hi) | ||
end | end | ||
out[#out + 1] = col( | out[#out + 1] = col(average, "sb-col-average sb-w-fill", avg) | ||
if #low > 0 then | if #low > 0 then | ||
local low_w = (#high > 0) and "sb-low-narrow" or "sb-low-wide" | local low_w = (#high > 0) and "sb-low-narrow" or "sb-low-wide" | ||
| Line 149: | Line 130: | ||
end | end | ||
-- {{#invoke:StreetBrawlItems|tiers|HERO|high=..| | -- {{#invoke:StreetBrawlItems|tiers|HERO|gate=ID|high=..|average=..|low=..|tier1=..|...|tier5=..}} | ||
-- All five tiers under styled (non-TOC) headings. With gate=ID, | -- All five tiers under styled (non-TOC) headings. All display text is supplied by the | ||
-- caller. With gate=ID, the Tier 1 heading and everything after it is wrapped in an open | |||
-- <div id=ID class="sb-gate">, whose inner <div class="sb-gate-body"> the caller must | |||
-- close after any trailing content. The id sits on the outer wrapper so following the | |||
-- anchor lands on the Tier 1 heading rather than the columns below it. | |||
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 hi = frame.args.high or " | local hi = frame.args.high or "" | ||
local | local avg = frame.args.average or "" | ||
local lo = frame.args.low or " | local lo = frame.args.low or "" | ||
local gate = frame.args.gate | local gate = frame.args.gate | ||
if gate == "" then gate = nil end | if gate == "" then gate = nil end | ||
local out = {} | local out = {} | ||
for t = 1, 5 do | for t = 1, 5 do | ||
local head = heading_div( | local head = heading_div(frame.args["tier" .. t] or "") | ||
local cols = tier_columns(frame, hkey, t, hi, | local cols = tier_columns(frame, hkey, t, hi, avg, lo) | ||
if t == 1 and gate then | if t == 1 and gate then | ||
out[#out + 1] = | out[#out + 1] = '<div id="' .. gate .. '" class="sb-gate">\n' | ||
.. head .. "\n" | |||
.. '<div class="sb-gate-body">\n' | |||
.. cols | .. cols | ||
else | else | ||
| Line 198: | Line 181: | ||
out[#out + 1] = classdiv(parts, "sb-cards") | out[#out + 1] = classdiv(parts, "sb-cards") | ||
return table.concat(out, "\n") | return table.concat(out, "\n") | ||
end | end | ||
return p | return p | ||