Module:Abilities/card: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
Removed hex duration as it seems to work without this code now.
LVL (talk | contribs)
Fix Fire Scarabs T3 upgrade description: suppress "0 DPS" and show "Increased Spirit scaling". Refactor create_description to handle scaling‑only properties
Line 475: Line 475:


function create_description(prop, frame)
function create_description(prop, frame)
     local description = ''
     local value_lines = {}  -- normal stat changes
     local first = true
     local scale_lines = {}  -- "Increased X scaling" notes
     local seen = {} -- Set to track added combinations
     local seen = {}


     for k, v in pairs(prop) do
     for k, v in pairs(prop) do
    local value
        if k == 'DescKey' then
         if type(v) == 'table' then
            -- skip
        value = v.Value
         elseif type(v) == 'table' then
        else
            local has_value = v.Value ~= nil
        value = v
            local has_scale = v.Scale and v.Scale.Value and v.Scale.Value ~= 0
    end
 
   
            -- Value is 0 and we have a scaling change → scaling note
        local formatted_value = utils.format_value_with_prepost(k, value, frame)
            if has_value and has_scale and v.Value == 0 then
        local attr_name = lang.get_string(k..'_label')
                if not seen["scale_" .. k] then
        local key = formatted_value .. '|' .. attr_name -- Unique identifier
                    local scale_type = v.Scale.Type
                    local capitalized = scale_type:sub(1,1):upper() .. scale_type:sub(2)
-- skip DescKey for the edge case where we are generating description instead of using localization files
                    table.insert(scale_lines, "Increased " .. capitalized .. " scaling")
if k ~= 'DescKey' then
                    seen["scale_" .. k] = true
        -- Skip if this combination has already been added
                end
        if not seen[key] then
            -- Only a scaling change, no value → scaling note (future bot correction)
        -- Add line break if this is not the first item
            elseif not has_value and has_scale then
            if not first then
                if not seen["scale_" .. k] then
              description = description .. '<br>'
                    local scale_type = v.Scale.Type
            end
                    local capitalized = scale_type:sub(1,1):upper() .. scale_type:sub(2)
        end
                    table.insert(scale_lines, "Increased " .. capitalized .. " scaling")
                    seen["scale_" .. k] = true
        description = description .. string.format('%s %s', formatted_value, attr_name)
                end
        first = false
            -- Normal value (0 without scale, or non‑zero with/without scale)
        seen[key] = true -- Mark this combination as added
            elseif has_value then
                local formatted_value = utils.format_value_with_prepost(k, v.Value, frame)
                local attr_name = lang.get_string(k .. '_label')
                local key = formatted_value .. '|' .. attr_name
                if not seen[key] then
                    table.insert(value_lines, string.format('%s %s', formatted_value, attr_name))
                    seen[key] = true
                end
            end
        else
            -- Plain number/string (e.g. OutgoingDamagePenaltyPercent = -15)
            local formatted_value = utils.format_value_with_prepost(k, v, frame)
            local attr_name = lang.get_string(k .. '_label')
            local key = formatted_value .. '|' .. attr_name
            if not seen[key] then
                table.insert(value_lines, string.format('%s %s', formatted_value, attr_name))
                seen[key] = true
            end
         end
         end
     end
     end


     return description
    -- Combine: value lines first, then scaling lines
    local all_lines = {}
    for _, line in ipairs(value_lines) do
        table.insert(all_lines, line)
    end
    for _, line in ipairs(scale_lines) do
        table.insert(all_lines, line)
    end
 
     return table.concat(all_lines, '<br>')
end
end