Module:Sandbox/Vergir: Difference between revisionsGive feedback
Fix: iterate Upgrades with ipairs (loadJsonData tables have no length) (with help from vergir-bot LLM) |
Use {{Ss}} badge in the Spirit Scaling cell; add plain-text dump for review (with help from vergir-bot LLM) |
||
| Line 65: | Line 65: | ||
local function format_spirit(v) | local function format_spirit(v) | ||
return string.format("%.3g", v) | return string.format("%.3g", v) | ||
end | |||
-- Formats one Spirit scaling for the table cell through the compact {{Ss}} | |||
-- form, the same way RenderBarrier does. The template is expanded via the | |||
-- frame the surrounding #invoke runs under, since module return values are | |||
-- not re-expanded; the plain "×N" fallback covers a nil frame (module | |||
-- console). | |||
local function format_spirit_badge(v) | |||
local text = format_spirit(v) | |||
local frame = mw.getCurrentFrame() | |||
if frame then | |||
return frame:expandTemplate{ | |||
title = "Ss", | |||
args = { text, compact = "1", show_value = "1" }, | |||
} | |||
end | |||
return "×" .. text | |||
end | end | ||
| Line 74: | Line 91: | ||
-- Renders Spirit Power scaling. | -- Renders Spirit Power scaling. | ||
-- Lists every prop that scales with Spirit at base, one per line | -- Lists every prop that scales with Spirit at base, one per line as an {{Ss}} | ||
-- with the prop's name from the ability card: " | -- badge labelled with the prop's name from the ability card: | ||
-- "x0.55 (Base Damage)". Two | |||
-- props sharing a name are told apart by the card's Title | -- props sharing a name are told apart by the card's Title | ||
-- ("Damage: Cost of Stay"); props the card does not list show their raw key. | -- ("Damage: Cost of Stay"); props the card does not list show their raw key. | ||
| Line 127: | Line 145: | ||
local lines = {} | local lines = {} | ||
for _, prop in ipairs(base) do | for _, prop in ipairs(base) do | ||
table.insert(lines, | table.insert(lines, format_spirit_badge(prop.value) .. " (" .. label_of(prop.key) .. ")") | ||
running[prop.key] = prop.value | running[prop.key] = prop.value | ||
end | end | ||
| Line 657: | Line 675: | ||
table.insert(out, "|}") | table.insert(out, "|}") | ||
return table.concat(out, "\n") | return table.concat(out, "\n") | ||
end | |||
-- TEST ONLY: plain-text dump of a list for review, one line per ability. | |||
function p.dump(frame) | |||
local stat = mw.text.trim(frame.args[1] or ""):lower() | |||
local views, order = build_views() | |||
local spec = extra_columns[stat] | |||
local get_cells = spec and spec.get_cells or function() return {} end | |||
local out = {} | |||
for _, key in ipairs(order) do | |||
if p.is_member(stat, key) then | |||
local entry = views[key] | |||
local extra = get_cells(entry.view, entry.cardprops) | |||
local cell = extra["Spirit Scaling"] or "—" | |||
cell = mw.text.killMarkers(cell):gsub("<br>", " / "):gsub("<[^>]+>", "") | |||
table.insert(out, entry.heroName .. " | " .. entry.view["Name"] .. " | " .. cell .. " | " .. (extra["Notes"] or "—")) | |||
end | |||
end | |||
return "<pre>" .. mw.text.nowiki(table.concat(out, "\n")) .. "</pre>" | |||
end | end | ||
return p | return p | ||