Module:AbilityTable/ComplexRenderers: Difference between revisions

Sum all matching fields per layer in RenderExtraDebuffResist (with help from vergir-bot LLM)
Vergir (talk | contribs)
add RenderBarrier for the barrier list: running totals of barrier value and Spirit scaling per upgrade tier (with help from vergir-bot LLM)
Line 56: Line 56:
     end
     end
     return total
     return total
end
-- Sums the barrier value and Spirit scaling contributed by a single record
-- layer (the base ability record, or one upgrade tier). Returns nil when the
-- layer grants no barrier at all; a tier that only raises the scaling still
-- counts, so "+0 value, +1.0 scaling" upgrades are not lost.
local function sum_barrier(layer, fields)
    local value, scale, found = 0, 0, false
    for _, field in ipairs(fields) do
        local entry = layer[field]
        if entry ~= nil then
            local v = unwrap_value(entry) or 0
            local s = 0
            if type(entry) == "table" and type(entry["Scale"]) == "table" then
                s = entry["Scale"]["Value"] or 0
            end
            if v ~= 0 or s ~= 0 then found = true end
            value = value + v
            scale = scale + s
        end
    end
    if not found then return nil end
    return value, scale
end
-- Formats one barrier step. Spirit scaling goes through {{Ss}}, expanded via
-- the frame the surrounding #invoke is already running under: module return
-- values are not re-expanded, so a literal "{{Ss|0.8}}" would reach the page
-- as text. The plain fallback covers a nil frame (module console).
local function format_barrier(value, scale)
    local out = tostring(value)
    if scale and scale ~= 0 then
        local frame = mw.getCurrentFrame()
        if frame then
            out = out .. " " .. frame:expandTemplate{ title = "Ss", args = { scale } }
        else
            out = out .. " ×" .. scale
        end
    end
    return out
end
end


Line 114: Line 154:


local p = {}
local p = {}
-- Renders the barrier an ability grants, with its Spirit Power scaling.
-- Both the value and the scaling accumulate across upgrades, so every step
-- after the first shows the running total: "100 x0.8 → 180 x1.5 (T2)".
-- A tier that only improves the scaling still gets its own segment.
function p.RenderBarrier(ability)
    local fields  = Lists.lists["barrier"]
    local segments = {}
    local value, scale = sum_barrier(ability, fields)
    if value then
        table.insert(segments, format_barrier(value, scale))
    else
        value, scale = 0, 0
    end
    local upgrades = ability["Upgrades"]
    if type(upgrades) == "table" then
        for i, tier in ipairs(upgrades) do
            if type(tier) == "table" then
                local delta_value, delta_scale = sum_barrier(tier, fields)
                if delta_value then
                    value, scale = value + delta_value, scale + delta_scale
                    table.insert(segments,
                        format_barrier(value, scale) .. " (T" .. i .. ")")
                end
            end
        end
    end
    if #segments == 0 then return {} end
    return { ["Barrier"] = table.concat(segments, " → ") }
end


-- Renders charge count and time between charges.
-- Renders charge count and time between charges.