Editing Module:Sandbox/Monster Domosed/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 404: Line 404:
end
end


-- Memoized Key -> label map built from Data:AbilityCards.json. The flat
-- Memoized display-name lookup that calls Module:Lang's get_string with the prop
-- AbilityData.json records only carry { Value, Scale }; the human-readable
-- key suffixed by "_label" (e.g. "MaxDamageBeforePerfect_label"). The flat
-- label lives inside the Info1/Info2 prop entries of AbilityCards.json, where
-- AbilityData.json records only carry { Value, Scale }; the localized,
-- Title takes precedence over Name ("On Perfect Hold" before "Perfect Damage").
-- human-readable prop name is a Lang string keyed by the prop key + "_label".
-- A trailing colon on a Title is stripped so it reads cleanly in "(...)".
-- The module is required lazily so this file can still load when Lang is absent
local _card_labels = nil
-- (e.g. module console), in which case the fallback to the raw key applies.
local function build_card_label_map()
local Lang = nil
     if _card_labels then return _card_labels end
local _label_lookup = nil
    _card_labels = {}
local function prop_label(key)
    if type(mw) ~= "table" or type(mw.loadJsonData) ~= "function" then
     if _label_lookup == nil then _label_lookup = {} end
        return _card_labels
     if _label_lookup[key] ~= nil then return _label_lookup[key] end
    end
    local ok, cards = pcall(mw.loadJsonData, "Data:AbilityCards.json")
     if not ok or type(cards) ~= "table" then return _card_labels end


     -- Label for a single prop entry: Title wins, else Name; strip any
     if Lang == nil then
    -- trailing colon/whitespace (a Title like "On Perfect Hold:" -> "On Perfect Hold").
        local ok, mod = pcall(require, "Module:Lang")
    local function entry_label(entry)
         if ok and type(mod) == "table" then Lang = mod end
        local label = entry["Title"] or entry["Name"]
         if type(label) ~= "string" then return nil end
        if entry["Title"] ~= nil then label = label:gsub(":%s*$", "") end
        return label
     end
     end
 
     if Lang and type(Lang.get_string) == "function" then
    local seen = {}
         local ok, label = pcall(Lang.get_string, key .. "_label")
     local function walk(node)
         if ok and type(label) == "string" and label ~= "" then
        if type(node) ~= "table" or seen[node] then return end
             _label_lookup[key] = label
        seen[node] = true
             return label
         local k = node["Key"]
         if type(k) == "string" and (node["Title"] ~= nil or node["Name"] ~= nil) then
             local label = entry_label(node)
            if label and label ~= "" then _card_labels[k] = label end
        end
        for _, v in pairs(node) do
             if type(v) == "table" then walk(v) end
         end
         end
     end
     end
     walk(cards)
 
     return _card_labels
     -- Cache the miss (as nil) so we don't hit Lang again for this key.
    _label_lookup[key] = nil
     return nil
end
end


Line 479: 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 any label
                 -- Prefer a Name carried directly on the prop, then any name
                 -- recovered from nested Key/Title-or-Name entries inside this
                 -- recovered from nested Key/Name entries inside this record,
                 -- record, then the AbilityCards label map (Title over Name),
                 -- then the localized Lang label for "<key>_label", else the key.
                -- 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 names[k]
                               or build_card_label_map()[k]
                               or prop_label(k)
                               or k
                               or k
                 table.insert(props, { key = k, value = scale["Value"], name = label })
                 table.insert(props, { key = k, value = scale["Value"], name = label })
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