Editing Module:AbilityTable/ComplexRenderers

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
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


-- Sums the non-zero values of `fields` within a single record layer (the base
-- Returns the first non-zero value among `fields` within a single record layer
-- ability record, or one upgrade tier). Returns nil when none are present.
-- (the base ability record, or one upgrade tier). Returns nil when none apply.
local function sum_fields(layer, fields)
local function layer_value(layer, fields)
    local total = nil
     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 total = (total or 0) + math.abs(v) end
         if v and v ~= 0 then return math.abs(v) end
     end
     end
     return total
     return nil
end
end


Line 567: Line 566:
     local segments = {}
     local segments = {}


     local running = sum_fields(ability, fields)
     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 = sum_fields(tier, fields)
                 local delta = layer_value(tier, fields)
                 if delta then
                 if delta then
                     running = (running or 0) + delta
                     running = (running or 0) + delta
Please note that all contributions to The Deadlock Wiki are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see Deadlock:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template