Module:Sandbox/Monster Domosed/AbilityTable/ComplexRenderers: Difference between revisions

No edit summary
Undo
Tag: Undo
Line 402: Line 402:


     return cells
     return cells
end
-- Resolves the human-readable display Name for a prop key. Prefers the prop's
-- own "Name" field on the top-level table; otherwise recurses through the whole
-- ability record looking for any entry of the form { Key = key, Name = str }
-- (e.g. prop entries inside Info1/Info2 ... .Main.Props). Falls back to the key.
local function find_prop_name(ability, key)
    local direct = ability[key]
    if type(direct) == "table" and type(direct["Name"]) == "string" then
        return direct["Name"]
    end
    local found
    local function walk(node)
        if found or type(node) ~= "table" then return end
        for _, v in pairs(node) do
            if type(v) == "table" then
                if v["Key"] == key and type(v["Name"]) == "string" then
                    found = v["Name"]
                    return
                end
                walk(v)
            end
        end
    end
    walk(ability)
    return found or key
end
end


Line 449: Line 422:
               and type(scale["Value"]) == "number"
               and type(scale["Value"]) == "number"
               and scale["Value"] ~= 0 then
               and scale["Value"] ~= 0 then
                 local label = find_prop_name(ability, k)
                 local label = type(v["Name"]) == "string" and v["Name"] or k
                 table.insert(props, { key = k, value = scale["Value"], name = label })
                 table.insert(props, { key = k, value = scale["Value"], name = label })
             end
             end