Module:AbilityTable/ComplexRenderers: Difference between revisions

Vergir (talk | contribs)
mNo edit summary
Vergir (talk | contribs)
rename val_stat_cells to render_upgradable_stat, simplify RenderHealReduce to use it, fix Lists.props to Lists.lists (with help from vergir-bot LLM)
Line 100: Line 100:


-- ============================================================
-- ============================================================
-- Generic renderer for a single numeric stat column.
-- Generic renderer for a single numeric stat that can increase
-- col_name: column header string
-- additively through upgrades. Shows value in a named column
-- fields:  ordered list of property names (first non-zero wins)
-- and generates upgrade notes with running totals.
-- suffix:  string appended to values in cell and upgrade notes
-- ============================================================
-- ============================================================


local function val_stat_cells(ability, col_name, fields, suffix)
local function render_upgradable_stat(ability, col_name, fields, suffix)
     suffix = suffix or ""
     suffix = suffix or ""
     local cells = {}
     local cells = {}
Line 259: Line 258:
-- HealReduce: shows heal reduction percentage and upgrade notes.
-- HealReduce: shows heal reduction percentage and upgrade notes.
function p.RenderHealReduce(ability)
function p.RenderHealReduce(ability)
     local cells = {}
     -- DisableHealing is always 100%, handle it separately
    local notes = {}
     local v = unwrap_value(ability["DisableHealing"])
    local stat_props = Lists.props["healreduce"]
    if v and v ~= 0 then
 
         return { ["Heal Reduction"] = "100%" }
    local first_pct, first_tier, first_is_disable = nil, nil, false
 
     for _, prop in ipairs(stat_props) do
        local v = unwrap_value(ability[prop])
        if v and v ~= 0 then
            if prop == "DisableHealing" then
                first_is_disable = true
            else
                first_pct = math.abs(v)
            end
            break
        end
    end
    if not first_pct and not first_is_disable then
         local upgrades = ability["Upgrades"]
        if type(upgrades) == "table" then
            for i, tier in ipairs(upgrades) do
                if type(tier) == "table" then
                    for _, prop in ipairs(stat_props) do
                        local v = unwrap_value(tier[prop])
                        if v and v ~= 0 then
                            if prop == "DisableHealing" then
                                first_is_disable, first_tier = true, i
                            else
                                first_pct, first_tier = math.abs(v), i
                            end
                            break
                        end
                    end
                end
                if first_pct or first_is_disable then break end
            end
        end
     end
     end
 
     local upgrade = find_in_upgrades(ability, "DisableHealing")
     if first_is_disable then
     if upgrade then
        cells["Heal Reduction"] = "100%" .. (first_tier and " (T" .. first_tier .. ")" or "")
         return { ["Heal Reduction"] = "100% (T" .. upgrade.tier .. ")" }
     elseif first_pct then
         cells["Heal Reduction"] = tostring(first_pct) .. "%" .. (first_tier and " (T" .. first_tier .. ")" or "")
     end
     end


     local upgrades = ability["Upgrades"]
     -- Everything else goes through the generic renderer
     if type(upgrades) == "table" then
     local filtered = {}
        local running        = first_pct
    for _, prop in ipairs(Lists.lists["healreduce"]) do
        local first_pct_seen = (first_tier == nil)
        if prop ~= "DisableHealing" then table.insert(filtered, prop) end
        for i, tier in ipairs(upgrades) do
            if type(tier) == "table" then
                if first_tier == i then
                    first_pct_seen = true
                    if first_pct then running = first_pct end
                elseif first_pct_seen then
                    local delta = nil
                    for _, prop in ipairs(stat_props) do
                        if prop ~= "DisableHealing" then
                            local v = unwrap_value(tier[prop])
                            if v and v ~= 0 then delta = math.abs(v); break end
                        end
                    end
                    if delta then
                        local total = (running or 0) + delta
                        table.insert(notes, "T" .. i .. " upgrade increases heal reduction by "
                            .. delta .. "% (total " .. total .. "%).")
                        running = total
                    end
                end
            end
        end
     end
     end
 
     return render_upgradable_stat(ability, "Heal Reduction", filtered, "%")
     if #notes > 0 then cells["Notes"] = table.concat(notes, " ") end
    return cells
end
end


Line 339: Line 279:
-- Outputs upgrade-tier notes for debuffs added only in upgrades (not at base).
-- Outputs upgrade-tier notes for debuffs added only in upgrades (not at base).
function p.RenderDebuff(ability, stat)
function p.RenderDebuff(ability, stat)
     local stat_props = Lists.props[stat]
     local stat_props = Lists.lists[stat]
     local cells = {}
     local cells = {}


Line 396: Line 336:
-- MoveSlow: shows move slow percentage and caster slow note if present.
-- MoveSlow: shows move slow percentage and caster slow note if present.
function p.RenderMoveSlow(ability)
function p.RenderMoveSlow(ability)
     local cells = val_stat_cells(ability, "Move Slow", Lists.props["moveslow"], "%")
     local cells = render_upgradable_stat(ability, "Move Slow", Lists.lists["moveslow"], "%")


     local channel_slow = unwrap_value(ability["ChannelSlowPercent"])
     local channel_slow = unwrap_value(ability["ChannelSlowPercent"])
Line 409: Line 349:
-- DashSlow: shows dash slow percentage, auto-detects caster self-slow.
-- DashSlow: shows dash slow percentage, auto-detects caster self-slow.
function p.RenderDashSlow(ability)
function p.RenderDashSlow(ability)
     local stat_props = Lists.props["dashslow"]
     local stat_props = Lists.lists["dashslow"]
     local props = {}
     local props = {}
     for _, p in ipairs(stat_props) do table.insert(props, p) end
     for _, pr in ipairs(stat_props) do table.insert(props, pr) end


     local caster_dash_slow = nil
     local caster_dash_slow = nil
Line 451: Line 391:
     end
     end


     local cells = val_stat_cells(ability, "Dash Slow", props, "%")
     local cells = render_upgradable_stat(ability, "Dash Slow", props, "%")


     if caster_dash_slow then
     if caster_dash_slow then