Editing Module:AbilityTable/ComplexRenderersGive feedback
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 47: | Line 47: | ||
end | end | ||
-- | -- Returns the first non-zero value among `fields` within a single record layer | ||
-- (the base ability record, or one upgrade tier). Returns nil when none apply. | |||
local function | local function layer_value(layer, fields) | ||
for _, field in ipairs(fields) do | for _, field in ipairs(fields) do | ||
local v = unwrap_value(layer[field]) | local v = unwrap_value(layer[field]) | ||
if v and v ~= 0 then | if v and v ~= 0 then return math.abs(v) end | ||
end | end | ||
return | return nil | ||
end | end | ||
| Line 567: | Line 566: | ||
local segments = {} | local segments = {} | ||
local running = | local running = layer_value(ability, fields) | ||
if running then | if running then | ||
table.insert(segments, running .. "%") | table.insert(segments, running .. "%") | ||
| Line 576: | Line 575: | ||
for i, tier in ipairs(upgrades) do | for i, tier in ipairs(upgrades) do | ||
if type(tier) == "table" then | if type(tier) == "table" then | ||
local delta = | local delta = layer_value(tier, fields) | ||
if delta then | if delta then | ||
running = (running or 0) + delta | running = (running or 0) + delta | ||