Module:Abilities/card: Difference between revisions

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)
Vergir (talk | contribs)
m undo the undo, it works now
Tag: Undo
 
(3 intermediate revisions by 3 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 198: Line 199:
-- healing, charges) that always hold a value of 1 and are never displayed, so
-- healing, charges) that always hold a value of 1 and are never displayed, so
-- return the first entry that actually renders a badge.
-- 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)
local function pick_scale(attr)
if not attr then
if not attr then
Line 213: Line 217:
end
end
local placeholder = nil
for _, entry in ipairs(scale) do
for _, entry in ipairs(scale) do
if type(entry) == 'table' and entry.Value ~= 0 and Icon.isDisplayedScale(entry.Type) then
if type(entry) == 'table' and Icon.isDisplayedScale(entry.Type) then
return entry
if entry.Value ~= 0 then
return entry
end
placeholder = placeholder or entry
end
end
end
end
return nil
return placeholder
end
end


Line 408: Line 416:
local alt_boxes = {}
local alt_boxes = {}
     for k, prop in pairs(props) do
     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 444: 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 453: Line 471:
local upgrade_boxes = {}
local upgrade_boxes = {}
for k, upgrade in pairs(upgrades) do
for k, upgrade in ipairs(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 475: Line 492:
end
end
-- Vary the font size based on the number of characters to prevent overflow
-- Expand once, then size from the text the reader actually sees, rather
local fontsize = '1rem'
-- than from a character count of the unexpanded string.
if desc_length > 30 and desc_length < 51 then
local rendered = frame:preprocess(description)
fontsize = '0.9rem'
local cqw = textfit.fit(rendered, {
elseif desc_length > 50 and desc_length < 71 then
aspect = UG_DESC_ASPECT,
fontsize = '0.8rem'
lineHeight = UG_LINE_HEIGHT,
elseif desc_length > 70 then
max = UG_MAX_CQW,
fontsize = '0.7rem'
min = UG_MIN_CQW,
end
})
local upgrade_scale = pick_scale(upgrade)
local upgrade_scale = pick_scale(upgrade)
Line 491: Line 508:
index = k,
index = k,
cost = UPGRADE_COST_MAP[k],
cost = UPGRADE_COST_MAP[k],
description = frame:preprocess(description),
description = rendered,
scale_value = upgrade_scale and commonutils.round_to_sig_fig(upgrade_scale.Value, 3),
scale_value = upgrade_scale and commonutils.round_to_sig_fig(upgrade_scale.Value, 3),
scale_type =  upgrade_scale and upgrade_scale.Type,
scale_type =  upgrade_scale and upgrade_scale.Type,
fontsize = 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
}
}
}
}