Module:Sandbox/Monster Domosed/AbilityTable/ComplexRenderers: Difference between revisionsGive feedback
test |
No edit summary |
||
| 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 422: | Line 449: | ||
and type(scale["Value"]) == "number" | and type(scale["Value"]) == "number" | ||
and scale["Value"] ~= 0 then | and scale["Value"] ~= 0 then | ||
local label = | local label = find_prop_name(ability, k) | ||
table.insert(props, { key = k, value = scale["Value"], name = label }) | table.insert(props, { key = k, value = scale["Value"], name = label }) | ||
end | end | ||