Editing Module:StreetBrawlItemsGive feedback
Jump to navigation
Jump to search
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 8: | Line 8: | ||
local SLOT_RANK = { Weapon = 1, Armor = 2, Tech = 3 } | local SLOT_RANK = { Weapon = 1, Armor = 2, Tech = 3 } | ||
-- Card scale passed to ItemBox. | -- Card scale passed to ItemBox. | ||
local CARD_SIZE = "0. | local CARD_SIZE = "0.667" | ||
local NAME_TO_KEY = {} | local NAME_TO_KEY, KEY_TO_NAME, RELEASED = {}, {}, {} | ||
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 | ||
KEY_TO_NAME[key] = h.Name | |||
NAME_TO_KEY[mw.ustring.lower(h.Name)] = key | NAME_TO_KEY[mw.ustring.lower(h.Name)] = key | ||
if not h.InDevelopment and not h.IsDisabled then RELEASED[key] = true end | |||
end | end | ||
end | end | ||
| Line 54: | Line 56: | ||
local function render_item(frame, code) | 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 | ||
local args = { name, size = CARD_SIZE } | |||
local args = { name, size = 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 | ||
return frame:expandTemplate{title = "ItemBox", args = args} | return frame:expandTemplate{title = "ItemBox", args = args} | ||
end | |||
local function render_hero(frame, key) | |||
local name = KEY_TO_NAME[key]; if not name then return nil end | |||
return frame:expandTemplate{title = "HeroIcon", args = {name}} | |||
end | end | ||
| Line 69: | Line 72: | ||
end | end | ||
-- A tier/section heading | -- A tier/section heading styled to look like a heading but rendered as a plain | ||
-- | -- div, so it stays out of the table of contents (and can be hidden inside the gate). | ||
local function heading_div(label) | local function heading_div(label) | ||
return '<div class=" | return '<div class="sb-tier-head">' .. label .. '</div>' | ||
end | end | ||
| Line 88: | Line 90: | ||
end | end | ||
-- Returns sorted high (favored), | -- Returns sorted high (favored), normal (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, normal, 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 normal[#normal + 1] = c end | ||
end | end | ||
end | end | ||
table.sort(high, item_less) | table.sort(high, item_less) | ||
table.sort( | table.sort(normal, item_less) | ||
table.sort(low, item_less) | table.sort(low, item_less) | ||
return high, | return high, normal, low | ||
end | |||
local function item_code(input) | |||
input = mw.text.trim(input or "") | |||
if input == "" then return nil end | |||
if items[input] then return input end | |||
for k, v in pairs(items) do | |||
if type(v) == "table" and v.Name == input and v.IsDisabled ~= true then return k end | |||
end | |||
for k, v in pairs(items) do | |||
if type(v) == "table" and v.Name == input then return k end | |||
end | |||
return nil | |||
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 middle 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, mid, lo) | ||
local high, | local high, normal, low = collect(hkey, tier) | ||
local function col(codes, cls, head) | local function col(codes, cls, head) | ||
| Line 125: | Line 140: | ||
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(normal, "sb-col-normal sb-w-fill", mid) | ||
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 133: | Line 148: | ||
end | end | ||
-- {{#invoke:StreetBrawlItems|tiers|HERO | -- {{#invoke:StreetBrawlItems|tiers|HERO|high=..|middle=..|low=..|gate=ID}} | ||
-- All five tiers under styled (non-TOC) headings | -- All five tiers under styled (non-TOC) headings. With gate=ID, everything from | ||
-- the Tier 1 columns onward is wrapped in an open <div id=ID class="sb-gate"> | |||
-- <div class="sb-gate-body"> that the caller must close after any trailing content. | |||
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 "High chance" | ||
local | local mid = frame.args.middle or "Average chance" | ||
local lo = frame.args.low or "" | local lo = frame.args.low or "Low chance" | ||
local gate = frame.args.gate | local gate = frame.args.gate | ||
if gate == "" then gate = nil end | if gate == "" then gate = nil end | ||
local labels = { "Tier 1", "Tier 2", "Tier 3", "Tier 4", "Legendary" } | |||
local out = {} | local out = {} | ||
for t = 1, 5 do | for t = 1, 5 do | ||
local head = heading_div( | local head = heading_div(labels[t]) | ||
local cols = tier_columns(frame, hkey, t, hi, | local cols = tier_columns(frame, hkey, t, hi, mid, lo) | ||
if t == 1 and gate then | if t == 1 and gate then | ||
out[#out + 1] = '<div id="' .. gate .. '" class="sb-gate"> | out[#out + 1] = head .. "\n" | ||
.. '<div id="' .. gate .. '" class="sb-gate"><div class="sb-gate-body">\n' | |||
.. cols | .. cols | ||
else | else | ||
| Line 186: | Line 199: | ||
end | end | ||
-- {{#invoke:StreetBrawlItems| | -- {{#invoke:StreetBrawlItems|item|ITEM|GROUP|label=..|note=..}} | ||
-- | -- GROUP = favored | unfavored | counter | ||
function p.item(frame) | |||
local code = item_code(frame.args[1]); if not code then return "" end | |||
local group = mw.text.trim(frame.args[2] or "") | |||
local | |||
local fav, unf, ctr = {}, {}, {} | |||
for _, o in ipairs(sb.Outliers) do | for _, o in ipairs(sb.Outliers) do | ||
if o. | if o.Item == code and RELEASED[o.Hero] then | ||
if o.Bucket == "Good" then fav[#fav + 1] = o.Hero | |||
if | elseif type(o.Weight) == "number" and o.Weight < 1 then unf[#unf + 1] = o.Hero end | ||
if o.Counter ~= nil then ctr[#ctr + 1] = o.Hero end | |||
end | end | ||
end | end | ||
local list = (group == "favored" and fav) or (group == "unfavored" and unf) or (group == "counter" and ctr) | |||
table.sort( | if not list then return "" end | ||
table.sort(list, function(a, b) return (KEY_TO_NAME[a] or a) < (KEY_TO_NAME[b] or b) end) | |||
local | local parts = {} | ||
for _, k in ipairs(list) do local r = render_hero(frame, k); if r then parts[#parts + 1] = r end end | |||
if #parts == 0 then return "" end | |||
local pre = "" | |||
local label = frame.args.label | |||
if label and label ~= "" then pre = pre .. "'''" .. label .. "'''<br>" end | |||
local note = frame.args.note | |||
if note and note ~= "" then pre = pre .. "''" .. note .. "''<br>" end | |||
return pre .. classdiv(parts, "sb-icons") | |||
end | |||
-- {{#invoke:StreetBrawlItems|item_in_pool|ITEM}} -> "1" if in the Street Brawl pool, else "" | |||
function p.item_in_pool(frame) | |||
return | local code = item_code(frame.args[1]); if not code then return "" end | ||
for _, c in ipairs(sb.AvailableItems) do if c == code then return "1" end end | |||
return "" | |||
end | end | ||
return p | return p | ||