Editing Module:Abilities/card

Jump to navigation Jump to search
Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 525: Line 525:


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


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


    -- Combine: value lines first, then scaling lines
     return description
    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


Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template