Module:Abilities/card: Difference between revisions

Jump to navigation Jump to search
Added nil check for channel time
Fixed upgrade description generation returning empty string if there is scaling
Line 397: Line 397:
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()


local props = ability.Upgrades
local upgrades = ability.Upgrades
local upgrade_boxes = {}
local upgrade_boxes = {}
for k, prop in pairs(props) do
for k, upgrade in pairs(upgrades) do
local description = lang.get_string(prop.DescKey)
local description = lang.get_string(upgrade.DescKey)
-- Generate a description if there is no localized string
-- Generate a description if there is no localized string
if (description == nil or description == '') then
if (description == nil or description == '') then
description = create_description(prop, frame)
description = create_description(upgrade, frame)
end
end
Line 423: Line 423:
  cost = UPGRADE_COST_MAP[k],
  cost = UPGRADE_COST_MAP[k],
  description = frame:preprocess(description),
  description = frame:preprocess(description),
  scale_value = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3),
  scale_value = upgrade.Scale and commonutils.round_to_sig_fig(upgrade.Scale.Value, 3),
  scale_type =  prop.Scale and prop.Scale.Type,
  scale_type =  upgrade.Scale and upgrade.Scale.Type,
  fontsize = fontsize
  fontsize = fontsize
}
}
Line 440: Line 440:


     for k, v in pairs(prop) do
     for k, v in pairs(prop) do
    
     local value
         if type(v) ~= 'table' then
         if type(v) == 'table' then
            local formatted_value = utils.format_value_with_prepost(k, v, frame)
        value = v.Value
            local attr_name = lang.get_string(k..'_label')
        else
            local key = formatted_value .. '|' .. attr_name  -- Unique identifier
        value = v
    end
   
        local formatted_value = utils.format_value_with_prepost(k, value, frame)
        local attr_name = lang.get_string(k..'_label')
        local key = formatted_value .. '|' .. attr_name  -- Unique identifier


            -- Skip if this combination has already been added
        -- Skip if this combination has already been added
            if not seen[key] then
        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
 
            description = description .. string.format('%s %s', formatted_value, attr_name)
            first = false
            seen[key] = true  -- Mark this combination as added
           
             end
             end
         end
         end
        description = description .. string.format('%s %s', formatted_value, attr_name)
        first = false
        seen[key] = true  -- Mark this combination as added
     end
     end
 
   
     return description
     return description
end
end