Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 11: Line 11:
     local success, lang_data = pcall(mw.loadJsonData, lang_file_name)
     local success, lang_data = pcall(mw.loadJsonData, lang_file_name)
     if not success then lang_data = {} end
     if not success then lang_data = {} end
    -- Keys to explicitly ignore (metadata, not stats)
    local ignore_keys = {
        ["Name"] = true, ["Description"] = true, ["Cost"] = true, ["Tier"] = true,
        ["Activation"] = true, ["Slot"] = true, ["Components"] = true, ["TargetTypes"] = true,
        ["ShopFilters"] = true, ["IsDisabled"] = true, ["StreetBrawl"] = true, ["IsImbue"] = true,
        ["AbilityUnitTargetLimit"] = true, ["AbilityCooldownBetweenCharge"] = true,
        ["ChannelMoveSpeed"] = true, ["NPCDamageMult"] = true, ["DamageHeight"] = true,
        ["Scale"] = true, ["Value"] = true -- Internal sub-table keys we don't need as text
    }


     local terms = {}
     local terms = {}
Line 16: Line 26:
         if type(tbl) ~= "table" then return end
         if type(tbl) ~= "table" then return end
         for k, v in pairs(tbl) do
         for k, v in pairs(tbl) do
             -- Only process string keys
             -- Only process string keys that aren't in our ignore list
             if type(k) == "string" then
             if type(k) == "string" and not ignore_keys[k] then
                 -- Check if the lang file has a readable string for this key (e.g., "TechResist" -> "TechResist_label")
                 -- Try to get the in-game name from the lang file
                 local term = lang_data[k .. "_label"] or lang_data[k]
                 local term = lang_data[k .. "_label"] or lang_data[k]
                 if term and type(term) == "string" then
                 if term and type(term) == "string" then
Line 26: Line 36:
                     table.insert(terms, string.lower(term))
                     table.insert(terms, string.lower(term))
                 else
                 else
                     -- Fallback: Convert CamelCase to spaces (e.g., BonusHealth -> bonus health)
                     -- Fallback: Convert CamelCase to spaces (e.g., BonusMoveSpeed -> bonus move speed)
                     local fallback_term = string.lower(k:gsub("(%u)", " %1"):gsub("^%s", ""))
                     local fallback_term = string.lower(k:gsub("(%u)", " %1"):gsub("^%s", ""))
                     table.insert(terms, fallback_term)
                     table.insert(terms, fallback_term)
Line 34: Line 44:
             if type(v) == "table" then
             if type(v) == "table" then
                 recurse(v)
                 recurse(v)
             elseif type(v) == "string" then
             -- Notice: We completely ignore string values here, which drops descriptions!
                local str = v
             -- We also ignore numbers and booleans. We only want the stat names (keys).
                -- Clean up description HTML tags and inline attributes
                str = str:gsub("<[^>]+>", " ")
                str = str:gsub("{g:citadel_inline_attribute:'(.-)'}", "%1")
                str = mw.text.decode(str)
                table.insert(terms, string.lower(str))
             elseif type(v) == "number" or type(v) == "boolean" then
                -- Explicitly ignore numbers and true/false values
                -- We only want the stat names (keys) and descriptions (strings)
             end
             end
         end
         end