Module:AbilityTable: Difference between revisionsGive feedback
m formatting |
Add compact parameter: one row per hero, abilities comma-separated, no extra columns (with help from vergir-bot LLM) |
||
| Line 376: | Line 376: | ||
end | end | ||
local key_lookup, | local compact = mw.text.trim(frame.args["compact"] or "") ~= "" | ||
local key_lookup, _ = build_lookup() | |||
local spec = extra_columns[stat] | local spec = extra_columns[stat] | ||
local headers = spec and spec.headers or {} | local headers = spec and spec.headers or {} | ||
| Line 415: | Line 417: | ||
return ia.abilityNum < ib.abilityNum | return ia.abilityNum < ib.abilityNum | ||
end) | end) | ||
-- Disclaimer | -- Disclaimer | ||
| Line 443: | Line 432: | ||
table.insert(out, '{| class="wikitable sortable ability-table"') | table.insert(out, '{| class="wikitable sortable ability-table"') | ||
if compact then | |||
-- Compact mode: one row per hero, abilities comma-separated in a single column. | |||
table.insert(out, '! class="ability-table-col-hero" | Hero' | |||
.. ' !! class="ability-table-col-abilities" | Abilities') | |||
-- Group abilities by hero, preserving sort order. | |||
local hero_order = {} -- ordered list of hero names | |||
local hero_abilities = {} -- heroName -> list of ability names | |||
for _, ability in ipairs(filtered) do | |||
local info = key_lookup[ability["Key"]] | |||
local hero = info and info.heroName or "—" | |||
if not hero_abilities[hero] then | |||
table.insert(hero_order, hero) | |||
hero_abilities[hero] = {} | |||
end | |||
table.insert(hero_abilities[hero], ability["Name"]) | |||
end | |||
for _, hero in ipairs(hero_order) do | |||
local hero_cell = frame:expandTemplate{ title = "HeroIcon", args = { hero } } | |||
hero_cell = frame:expandTemplate{ title = "HeroIcon", args = { | local ability_parts = {} | ||
for _, name in ipairs(hero_abilities[hero]) do | |||
hero_cell = " | table.insert(ability_parts, | ||
frame:expandTemplate{ title = "AbilityIcon", args = { name } }) | |||
end | |||
table.insert(out, "|-") | |||
table.insert(out, | |||
'| class="ability-table-cell-hero" | ' .. hero_cell | |||
.. ' || class="ability-table-cell-abilities" | ' .. table.concat(ability_parts, ", ")) | |||
end | end | ||
local | else | ||
-- Normal mode: one row per ability with stat-specific columns. | |||
local has_notes_header = false | |||
local final_headers = {} | |||
for _, h in ipairs(headers) do | |||
if h == "Notes" then | |||
has_notes_header = true | |||
elseif not hide_set[h] then | |||
table.insert(final_headers, h) | |||
end | |||
end | |||
local needs_notes = (has_notes_header or stat_notes ~= nil) and not hide_set["Notes"] | |||
if needs_notes then table.insert(final_headers, "Notes") end | |||
local | local header_row = '! class="ability-table-col-hero" | Hero' | ||
.. ' !! class="ability-table-col-ability" | Ability' | |||
for _, h in ipairs(final_headers) do | |||
header_row = header_row .. ' !! class="ability-table-col-' | |||
.. h:lower():gsub("%s+", "-") .. '" | ' .. h | |||
end | |||
table.insert(out, header_row) | |||
for _, ability in ipairs(filtered) do | |||
local | local info = key_lookup[ability["Key"]] | ||
local hero_cell | |||
if info then | |||
hero_cell = frame:expandTemplate{ title = "HeroIcon", args = { info.heroName } } | |||
if | |||
else | else | ||
hero_cell = "—" | |||
end | end | ||
row = row .. ' || class="' .. cls .. '" | ' .. content | local ability_cell = frame:expandTemplate{ title = "AbilityIcon", args = { ability["Name"] } } | ||
local extra = get_cells(ability) | |||
if stat_notes and stat_notes[ability["Name"]] then | |||
local human = stat_notes[ability["Name"]] | |||
extra["Notes"] = extra["Notes"] and (extra["Notes"] .. " " .. human) or human | |||
end | |||
local row = '| class="ability-table-cell-hero" | ' .. hero_cell | |||
.. ' || class="ability-table-cell-ability" | ' .. ability_cell | |||
for _, header in ipairs(final_headers) do | |||
local value = extra[header] | |||
local cls = "ability-table-cell-" .. header:lower():gsub("%s+", "-") | |||
local content | |||
if value ~= nil then | |||
local suffix = column_suffix[header] or "" | |||
content = (type(value) == "string" and value:sub(1,1) == "(") | |||
and value or (value .. suffix) | |||
else | |||
content = "—" | |||
end | |||
row = row .. ' || class="' .. cls .. '" | ' .. content | |||
end | |||
table.insert(out, "|-") | |||
table.insert(out, row) | |||
end | end | ||
end | end | ||