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

No edit summary
No edit summary
Line 402: Line 402:


     return cells
     return cells
end
-- Memoized display-name lookup that calls Module:Lang's get_string with the prop
-- key suffixed by "_label" (e.g. "MaxDamageBeforePerfect_label"). The flat
-- AbilityData.json records only carry { Value, Scale }; the localized,
-- human-readable prop name is a Lang string keyed by the prop key + "_label".
-- The module is required lazily so this file can still load when Lang is absent
-- (e.g. module console), in which case the fallback to the raw key applies.
local Lang = nil
local _label_lookup = nil
local function prop_label(key)
    if _label_lookup == nil then _label_lookup = {} end
    if _label_lookup[key] ~= nil then return _label_lookup[key] end
    if Lang == nil then
        local ok, mod = pcall(require, "Module:Lang")
        if ok and type(mod) == "table" then Lang = mod end
    end
    if Lang and type(Lang.get_string) == "function" then
        local ok, label = pcall(Lang.get_string, key .. "_label")
        if ok and type(label) == "string" and label ~= "" then
            _label_lookup[key] = label
            return label
        end
    end
    -- Cache the miss (as nil) so we don't hit Lang again for this key.
    _label_lookup[key] = nil
    return nil
end
end


Line 438: Line 467:
               and type(scale["Value"]) == "number"
               and type(scale["Value"]) == "number"
               and scale["Value"] ~= 0 then
               and scale["Value"] ~= 0 then
                 -- Prefer a Name carried directly on the prop, then a name
                 -- Prefer a Name carried directly on the prop, then any name
                 -- recovered from the nested Key/Name entries, else the key.
                 -- recovered from nested Key/Name entries inside this record,
                -- then the localized Lang label for "<key>_label", else the key.
                 local label = type(v["Name"]) == "string" and v["Name"]
                 local label = type(v["Name"]) == "string" and v["Name"]
                               or names[k] or k
                               or names[k]
                              or prop_label(k)
                              or k
                 table.insert(props, { key = k, value = scale["Value"], name = label })
                 table.insert(props, { key = k, value = scale["Value"], name = label })
             end
             end