Module:Abilities/card: Difference between revisions

add line break in generated upgrade descriptions
remove duplicated strings
Line 370: Line 370:
function create_description(prop, frame)
function create_description(prop, frame)
     local description = ''
     local description = ''
     local first = true  -- Track if it's the first entry
     local first = true
    local seen = {} -- Set to track added combinations


     for k, v in pairs(prop) do
     for k, v in pairs(prop) do
   
         if type(v) ~= 'table' then
         if type(v) ~= 'table' then
             local formatted_value = utils.format_value_with_prepost(k, v, frame)
             local formatted_value = utils.format_value_with_prepost(k, v, frame)
             local attr_name = lang.get_string(k..'_label')
             local attr_name = lang.get_string(k..'_label')
              
             local key = formatted_value .. '|' .. attr_name  -- Unique identifier
 
            -- Skip if this combination has already been added
            if not seen[key] then
             -- Add line break if this is not the first item
             -- Add line break if this is not the first item
            if not first then
                if not first then
                description = description .. '<br>'
                  description = description .. '<br>'
            end
                end


             description = description .. string.format('%s %s', formatted_value, attr_name)
             description = description .. string.format('%s %s', formatted_value, attr_name)
             first = false  -- After first item
             first = false
            seen[key] = true -- Mark this combination as added
           
            end
         end
         end
     end
     end