Module:Abilities/card: Difference between revisionsGive feedback
Fix missing AbilityCharges HTML element for JS gadget by defaulting num_of_charges to 0 |
Handle attributes carrying multiple scalings by picking the first one that renders, so real coefficients are not dropped when paired with a hidden stat-category marker (with help from vergir-bot LLM) |
||
| Line 194: | Line 194: | ||
end | end | ||
-- | -- An attribute may carry either a single scaling or a list of them. | ||
function | -- Extra entries are stat-category markers (duration, cooldown, range, radius, | ||
if not attr then | -- healing, charges) that always hold a value of 1 and are never displayed, so | ||
return nil | -- return the first entry that actually renders a badge. | ||
local function pick_scale(attr) | |||
if not attr then | |||
return nil | |||
end | end | ||
local scale = attr.Scale | local scale = attr.Scale | ||
if type(scale) ~= 'table' then | |||
return nil | |||
end | |||
-- A single scaling is stored directly as an object | |||
if scale[1] == nil then | |||
return scale | |||
end | |||
for _, entry in ipairs(scale) do | |||
if type(entry) == 'table' and entry.Value ~= 0 and Icon.isDisplayedScale(entry.Type) then | |||
return entry | |||
end | |||
end | |||
return nil | |||
end | |||
-- Get scaling of attribute, return nil if none is found | |||
function get_attr_scale(attr) | |||
local scale = pick_scale(attr) | |||
if not scale then | if not scale then | ||
return nil | return nil | ||
| Line 214: | Line 238: | ||
-- Get scaling type of attribute, return nil if none is found | -- Get scaling type of attribute, return nil if none is found | ||
function get_attr_scale_type(attr) | function get_attr_scale_type(attr) | ||
local scale = pick_scale(attr) | |||
local scale = attr | |||
if not scale then | if not scale then | ||
return nil | return nil | ||
| Line 232: | Line 252: | ||
-- Check if scaling should be multiplied instead of added | -- Check if scaling should be multiplied instead of added | ||
function get_attr_scale_multiply(attr) | function get_attr_scale_multiply(attr) | ||
local scale = pick_scale(attr) | |||
local scale = attr | |||
if not scale then | if not scale then | ||
return nil | return nil | ||
| Line 310: | Line 326: | ||
for k, prop in ipairs(props) do -- use ipairs for ordered iteration | for k, prop in ipairs(props) do -- use ipairs for ordered iteration | ||
local value = prop.Value | local value = prop.Value | ||
local scale = pick_scale(prop) | |||
-- If it scales with melee damage, set the value using the hero's base melee to match in game visuals | -- If it scales with melee damage, set the value using the hero's base melee to match in game visuals | ||
if | if scale and scale.Type == 'melee' then | ||
local hero = get_hero_data(hero_key) | local hero = get_hero_data(hero_key) | ||
value = prop.Value + hero.LightMeleeDamage * | value = prop.Value + hero.LightMeleeDamage * scale.Value | ||
elseif | elseif scale and scale.Type == 'heavy_melee' then | ||
local hero = get_hero_data(hero_key) | local hero = get_hero_data(hero_key) | ||
value = prop.Value + hero.HeavyMeleeDamage * | value = prop.Value + hero.HeavyMeleeDamage * scale.Value | ||
elseif | elseif scale and scale.Type == 'weapon_power' then | ||
local hero = get_hero_data(hero_key) | local hero = get_hero_data(hero_key) | ||
value = hero.Weapon.BulletDamage * hero.Weapon.BulletsPerBurst * ( | value = hero.Weapon.BulletDamage * hero.Weapon.BulletsPerBurst * (scale.Value + 100) / 100 | ||
end | end | ||
| Line 337: | Line 354: | ||
icon_color = icon and icon.color, | icon_color = icon and icon.color, | ||
icon_size = icon and icon.size, | icon_size = icon and icon.size, | ||
scale_value = | scale_value = scale and commonutils.round_to_sig_fig(scale.Value, 3), | ||
scale_type = | scale_type = scale and scale.Type, | ||
-- allow nil value here as some status effects don't have a value but should not be hidden | -- allow nil value here as some status effects don't have a value but should not be hidden | ||
hide = value == 0 and "true" or "false", | hide = value == 0 and "true" or "false", | ||
| Line 354: | Line 371: | ||
icon_color = icon and icon.color, | icon_color = icon and icon.color, | ||
icon_size = icon and icon.size, | icon_size = icon and icon.size, | ||
scale_value = | scale_value = scale and commonutils.round_to_sig_fig(scale.Value, 3), | ||
scale_type = | scale_type = scale and scale.Type, | ||
hide = (value == nil or value == 0) and "true" or "false", | hide = (value == nil or value == 0) and "true" or "false", | ||
} | } | ||
| Line 398: | Line 415: | ||
local value = prop.Value | local value = prop.Value | ||
local scale = pick_scale(prop) | |||
if | if scale and scale.Type == 'weapon_power' then | ||
local hero = get_hero_data(hero_key) | local hero = get_hero_data(hero_key) | ||
value = hero.Weapon.BulletDamage * hero.Weapon.BulletsPerBurst * ( | value = hero.Weapon.BulletDamage * hero.Weapon.BulletsPerBurst * (scale.Value + 100) / 100 | ||
end | end | ||
| Line 413: | Line 431: | ||
icon_color = icon and icon.color, | icon_color = icon and icon.color, | ||
icon_size = icon and icon.size, | icon_size = icon and icon.size, | ||
scale_value = | scale_value = scale and commonutils.round_to_sig_fig(scale.Value, 3), | ||
scale_type = | scale_type = scale and scale.Type, | ||
hide = value == 0 and "true" or "false", | hide = value == 0 and "true" or "false", | ||
} | } | ||
| Line 467: | Line 485: | ||
end | end | ||
local upgrade_scale = pick_scale(upgrade) | |||
local upgrade_box = frame:expandTemplate{ | local upgrade_box = frame:expandTemplate{ | ||
title = "Ability_card_v2/Card/UpgradeBox", | title = "Ability_card_v2/Card/UpgradeBox", | ||
| Line 473: | Line 492: | ||
cost = UPGRADE_COST_MAP[k], | cost = UPGRADE_COST_MAP[k], | ||
description = frame:preprocess(description), | description = frame:preprocess(description), | ||
scale_value = | scale_value = upgrade_scale and commonutils.round_to_sig_fig(upgrade_scale.Value, 3), | ||
scale_type = | scale_type = upgrade_scale and upgrade_scale.Type, | ||
fontsize = fontsize | fontsize = fontsize | ||
} | } | ||