Module:AbilityTable: Difference between revisions

add debug output to debuff_cells for Shoulder Charge to diagnose missing note (with help from vergir-bot LLM)
fix debuff_cells: remove debug, replace #upgrades loop with sorted pairs iteration to fix empty notes (with help from vergir-bot LLM)
Line 172: Line 172:
end
end


-- Searches Upgrades[] for a field and returns { tier = N, value = V } at its
-- first appearance, or nil if the field is absent from all upgrade tiers.
local function find_in_upgrades(ability, field)
local function find_in_upgrades(ability, field)
     local upgrades = ability["Upgrades"]
     local upgrades = ability["Upgrades"]
Line 185: Line 183:
end
end


-- Finds the first non-zero value for any of the given fields, checking base
-- then upgrades in order. Returns field, tier (nil=base, N=upgrade), abs value.
local function find_first_value(ability, fields)
local function find_first_value(ability, fields)
     for _, field in ipairs(fields) do
     for _, field in ipairs(fields) do
Line 271: Line 267:
}
}


-- Returns the prop name that matched in base, or nil if none matched.
-- Returns true if prop is found with a non-zero value anywhere in the record
-- Excludes the Upgrades key. Mirrors GameData.record_matches_prop logic.
-- excluding the Upgrades key. Mirrors GameData.record_matches_prop logic.
local function prop_in_base(record, prop)
local function prop_in_base(record, prop)
     for k, v in pairs(record) do
     for k, v in pairs(record) do
Line 291: Line 287:
end
end


-- Renderer shared by debuffresist and dispelmagic.
-- Outputs a Notes cell describing which debuffs are added only by upgrades.
-- If any prop from the stat's list is found in the base ability, outputs nothing.
-- Otherwise lists per-tier debuff names: "T2 slow", "T1 slow, T2 silence", etc.
local function debuff_cells(ability, stat)
local function debuff_cells(ability, stat)
     local props = stat_to_props[stat]
     local props = stat_to_props[stat]
     local cells = {}
     local cells = {}
    local is_debug = stat == "dispelmagic" and ability["Name"] == "Shoulder Charge"


     -- Check base props
     -- If any prop exists in base, this is a base-level debuff — no note needed.
    local base_hit = nil
     for _, prop in ipairs(props) do
     for _, prop in ipairs(props) do
         if prop_in_base(ability, prop) then
         if prop_in_base(ability, prop) then
             base_hit = prop
             return cells
            break
         end
         end
     end
     end
    if is_debug then
        local debug_parts = { "DEBUG:" }
        if base_hit then
            table.insert(debug_parts, "base_hit=" .. base_hit)
        else
            table.insert(debug_parts, "base_hit=none")
        end
        -- scan upgrades
        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(props) do
                        local v = tier[prop]
                        if v ~= nil then
                            if type(v) == "table" then v = v["Value"] end
                            if v ~= nil and v ~= 0 and v ~= "" and v ~= "0" and v ~= "0m" then
                                table.insert(debug_parts, "T"..i.."+"..prop.."="..tostring(v))
                            end
                        end
                    end
                end
            end
        end
        cells["Notes"] = table.concat(debug_parts, " | ")
        return cells
    end
    if base_hit then return cells end


     local upgrades = ability["Upgrades"]
     local upgrades = ability["Upgrades"]
     if type(upgrades) ~= "table" then return cells end
     if type(upgrades) ~= "table" then return cells end


    -- Collect debuff short names per upgrade tier.
     local tier_debuffs = {}
     local tier_debuffs = {}
     local seen_names  = {}
     local seen_names  = {} -- deduplicate short names across all tiers


     for i, tier in ipairs(upgrades) do
     for i, tier in ipairs(upgrades) do
Line 366: Line 334:
         end
         end
     end
     end
    -- Build note in tier order using sorted keys to avoid Lua pairs() ordering issues.
    local tier_indices = {}
    for i in pairs(tier_debuffs) do
        table.insert(tier_indices, i)
    end
    table.sort(tier_indices)


     local parts = {}
     local parts = {}
     for i = 1, #upgrades do
     for _, i in ipairs(tier_indices) do
         if tier_debuffs[i] then
         table.insert(parts, "T" .. i .. " " .. table.concat(tier_debuffs[i], " + "))
            table.insert(parts, "T" .. i .. " " .. table.concat(tier_debuffs[i], " + "))
        end
     end
     end


Line 602: Line 575:
     end
     end


     if #notes > 0 then cells["Notes"] = table.concat(notes, " ") end
     if #parts > 0 then cells["Notes"] = table.concat(notes, " ") end
     return cells
     return cells
end
end