Module:Abilities/card: Difference between revisionsGive feedback
Gammaton32 (talk | contribs) weapon power scaling value |
m undo the undo, it works now Tag: Undo |
||
| (5 intermediate revisions by 5 users not shown) | |||
| 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 textfit = require "Module:TextFit" | |||
local p = {} | local p = {} | ||
| Line 124: | Line 125: | ||
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 or 0, | ||
-- Info section #1 defined in "Info1" attribute | -- Info section #1 defined in "Info1" attribute | ||
| Line 194: | Line 195: | ||
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. | ||
-- A zero-valued scaling is still returned when nothing else is displayable. The | |||
-- card renders it as an x0 placeholder, and the ability upgrade gadget fills | |||
-- that element in when an upgrade grants real scaling (Doorman's Doorway). | |||
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 | |||
local placeholder = nil | |||
for _, entry in ipairs(scale) do | |||
if type(entry) == 'table' and Icon.isDisplayedScale(entry.Type) then | |||
if entry.Value ~= 0 then | |||
return entry | |||
end | |||
placeholder = placeholder or entry | |||
end | |||
end | |||
return placeholder | |||
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 246: | ||
-- 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 260: | ||
-- 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 334: | ||
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 362: | ||
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 379: | ||
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 391: | Line 416: | ||
local alt_boxes = {} | local alt_boxes = {} | ||
for k, prop in | for k, prop in ipairs(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 398: | Line 423: | ||
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 439: | ||
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 426: | Line 452: | ||
local UPGRADE_COST_MAP = {1, 2, 5} | local UPGRADE_COST_MAP = {1, 2, 5} | ||
-- Upgrade description sizing. These are design proportions, not copies of any | |||
-- CSS measurement: the browser supplies the box width through the container | |||
-- query on .ac-upgrade-descwrap, so nothing here needs updating if the card's | |||
-- widths, margins or padding change. | |||
local UG_DESC_ASPECT = 0.357 -- max height of the text block, as a multiple of its width | |||
local UG_LINE_HEIGHT = 1.4 -- emitted alongside the size so the two cannot drift | |||
local UG_MAX_CQW = 11.9 -- ceiling, as % of the text width (~16px on a full-width card) | |||
local UG_MIN_CQW = 6.7 -- floor (~9px) | |||
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 435: | Line 471: | ||
local upgrade_boxes = {} | local upgrade_boxes = {} | ||
for k, upgrade in | for k, upgrade in ipairs(upgrades) do | ||
local description = lang.get_string(upgrade.DescKey) | local description = lang.get_string(upgrade.DescKey) | ||
-- bypass some keys if they are mistakenly left in game files | -- bypass some keys if they are mistakenly left in game files | ||
| Line 457: | Line 492: | ||
end | end | ||
-- | -- Expand once, then size from the text the reader actually sees, rather | ||
local | -- than from a character count of the unexpanded string. | ||
local rendered = frame:preprocess(description) | |||
local cqw = textfit.fit(rendered, { | |||
aspect = UG_DESC_ASPECT, | |||
lineHeight = UG_LINE_HEIGHT, | |||
max = UG_MAX_CQW, | |||
min = UG_MIN_CQW, | |||
}) | |||
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 472: | Line 508: | ||
index = k, | index = k, | ||
cost = UPGRADE_COST_MAP[k], | cost = UPGRADE_COST_MAP[k], | ||
description = | description = rendered, | ||
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 = | -- Measured against the box's own width, so the size stays correct | ||
-- when the card renders below its 500px max-width. | |||
fontsize = string.format('%.2fcqw', cqw), | |||
lineheight = UG_LINE_HEIGHT | |||
} | } | ||
} | } | ||
| Line 654: | Line 693: | ||
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 or 0, | ||
} | } | ||
} | } | ||