Module:StreetBrawlItems: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
Render Street Brawl item cards in lowGraphics mode; these hero pages place hundreds of cards, so they use the cacheable overlay texture for smooth scrolling (with help from vergir-bot LLM)
Add counters_table: two-column table of heroes and their Street Brawl counter items (with help from vergir-bot LLM)
Line 184: Line 184:
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
-- {{#invoke:StreetBrawlItems|counters_table}}
-- Every hero that has counter items, one row each, sorted by hero name. Items
-- within a row are listed alphabetically. Built as HTML rather than pipe-table
-- markup so the invoke does not have to sit at the start of a line.
function p.counters_table(frame)
local by_hero, rows = {}, {}
for _, o in ipairs(sb.Outliers) do
if o.Counter ~= nil and iok(o.Item) then
local hero = heroes[o.Hero]
if hero and hero.Name then
local row = by_hero[o.Hero]
if not row then
row = { name = hero.Name, items = {}, seen = {} }
by_hero[o.Hero] = row
rows[#rows + 1] = row
end
-- Guard against a hero/item pair being listed twice.
if not row.seen[o.Item] then
row.seen[o.Item] = true
row.items[#row.items + 1] = iname(o.Item)
end
end
end
end
if #rows == 0 then return "" end
table.sort(rows, function(a, b) return a.name < b.name end)
local tbl = mw.html.create("table"):addClass("wikitable")
local head = tbl:tag("tr")
head:tag("th"):wikitext("Hero")
head:tag("th"):wikitext("Items")
for _, row in ipairs(rows) do
table.sort(row.items)
local icons = {}
for _, n in ipairs(row.items) do
icons[#icons + 1] = frame:expandTemplate{title = "ItemIcon", args = {n}}
end
local tr = tbl:tag("tr")
tr:tag("td"):wikitext(frame:expandTemplate{title = "HeroIcon", args = {row.name}})
tr:tag("td"):wikitext(table.concat(icons, ", "))
end
return tostring(tbl)
end
end


return p
return p