Editing Module:Abilities/cardGive feedback
Jump to navigation
Jump to search
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 3: | Line 3: | ||
local utils = require "Module:Abilities/utils" | local utils = require "Module:Abilities/utils" | ||
local Icon = require"Module:Abilities/icon" | local Icon = require"Module:Abilities/icon" | ||
local p = {} | local p = {} | ||
| Line 125: | Line 124: | ||
charge_cooldown_scale_type = get_attr_scale_type(ability.AbilityCooldownBetweenCharge), | charge_cooldown_scale_type = get_attr_scale_type(ability.AbilityCooldownBetweenCharge), | ||
charge_cooldown_scale_multiply = get_attr_scale_multiply(ability.AbilityCooldownBetweenCharge), | charge_cooldown_scale_multiply = get_attr_scale_multiply(ability.AbilityCooldownBetweenCharge), | ||
num_of_charges = ability.AbilityCharges and ability.AbilityCharges.Value | num_of_charges = ability.AbilityCharges and ability.AbilityCharges.Value, | ||
-- Info section #1 defined in "Info1" attribute | -- Info section #1 defined in "Info1" attribute | ||
| Line 195: | Line 194: | ||
end | end | ||
-- | -- Get scaling of attribute, return nil if none is found | ||
function get_attr_scale(attr) | |||
if not attr then | |||
return nil | |||
if not attr then | |||
return nil | |||
end | end | ||
local scale = attr.Scale | local scale = attr.Scale | ||
if not scale then | if not scale then | ||
return nil | return nil | ||
| Line 246: | Line 214: | ||
-- 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 = | if not attr then | ||
return nil | |||
end | |||
local scale = attr.Scale | |||
if not scale then | if not scale then | ||
return nil | return nil | ||
| Line 260: | Line 232: | ||
-- 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 = | if not attr then | ||
return nil | |||
end | |||
local scale = attr.Scale | |||
if not scale then | if not scale then | ||
return nil | return nil | ||
| Line 334: | Line 310: | ||
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 | ||
-- 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 prop.Scale and prop.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 * prop.Scale.Value | ||
elseif | elseif prop.Scale and prop.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 * prop.Scale.Value | ||
elseif | elseif prop.Scale and prop.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 * (prop.Scale.Value + 100) / 100 | ||
end | end | ||
| Line 362: | Line 337: | ||
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 = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3), | ||
scale_type = | scale_type = prop.Scale and prop.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 379: | 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 = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3), | ||
scale_type = | scale_type = prop.Scale and prop.Scale.Type, | ||
hide = (value == nil or value == 0) and "true" or "false", | hide = (value == nil or value == 0) and "true" or "false", | ||
} | } | ||
| Line 416: | Line 391: | ||
local alt_boxes = {} | local alt_boxes = {} | ||
for k, prop in | for k, prop in pairs(props) do | ||
-- Some props don't have values, as those come from upgrades | -- Some props don't have values, as those come from upgrades | ||
-- For now, we will ignore these and only show data for the base ability | -- For now, we will ignore these and only show data for the base ability | ||
| Line 423: | Line 398: | ||
local value = prop.Value | local value = prop.Value | ||
if | if prop.Scale and prop.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 * (prop.Scale.Value + 100) / 100 | ||
end | end | ||
| Line 439: | Line 413: | ||
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 = prop.Scale and commonutils.round_to_sig_fig(prop.Scale.Value, 3), | ||
scale_type = | scale_type = prop.Scale and prop.Scale.Type, | ||
hide = value == 0 and "true" or "false", | hide = value == 0 and "true" or "false", | ||
} | } | ||
| Line 452: | Line 426: | ||
local UPGRADE_COST_MAP = {1, 2, 5} | local UPGRADE_COST_MAP = {1, 2, 5} | ||
function get_upgrade_boxes(hero_key, ability_num) | function get_upgrade_boxes(hero_key, ability_num) | ||
local ability = utils.get_ability_card_data(hero_key, ability_num) | local ability = utils.get_ability_card_data(hero_key, ability_num) | ||
| Line 471: | Line 435: | ||
local upgrade_boxes = {} | local upgrade_boxes = {} | ||
for k, upgrade in | for k, upgrade in pairs(upgrades) do | ||
local description = lang.get_string(upgrade.DescKey) | local description = lang.get_string(upgrade.DescKey) | ||
local desc_length = description and #description or 0 | |||
-- bypass some keys if they are mistakenly left in game files | -- bypass some keys if they are mistakenly left in game files | ||
| Line 492: | Line 457: | ||
end | end | ||
-- | -- Vary the font size based on the number of characters to prevent overflow | ||
local fontsize = '1rem' | |||
local | if desc_length > 30 and desc_length < 51 then | ||
fontsize = '0.9rem' | |||
elseif desc_length > 50 and desc_length < 71 then | |||
fontsize = '0.8rem' | |||
elseif desc_length > 70 then | |||
fontsize = '0.7rem' | |||
end | |||
local upgrade_box = frame:expandTemplate{ | local upgrade_box = frame:expandTemplate{ | ||
title = "Ability_card_v2/Card/UpgradeBox", | title = "Ability_card_v2/Card/UpgradeBox", | ||
| Line 508: | Line 472: | ||
index = k, | index = k, | ||
cost = UPGRADE_COST_MAP[k], | cost = UPGRADE_COST_MAP[k], | ||
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 = | |||
} | } | ||
} | } | ||
| Line 693: | Line 654: | ||
charge_cooldown_scale_type = get_attr_scale_type(ability.AbilityCooldownBetweenCharge), | charge_cooldown_scale_type = get_attr_scale_type(ability.AbilityCooldownBetweenCharge), | ||
charge_cooldown_scale_multiply = get_attr_scale_multiply(ability.AbilityCooldownBetweenCharge), | charge_cooldown_scale_multiply = get_attr_scale_multiply(ability.AbilityCooldownBetweenCharge), | ||
num_of_charges = ability.AbilityCharges and ability.AbilityCharges.Value | num_of_charges = ability.AbilityCharges and ability.AbilityCharges.Value, | ||
} | } | ||
} | } | ||