Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 2: Line 2:
local lang = require "Module:Lang"
local lang = require "Module:Lang"
local util_module = require "Module:Utilities"
local util_module = require "Module:Utilities"
local data = mw.loadJsonData("Data:Monster_Domosed/ItemData.json")
local data = mw.loadJsonData("Data:Monster_Domosed/ItemCards.json")
local stat_links = mw.loadJsonData("Data:StatLinks.json")
local stat_links = mw.loadJsonData("Data:StatLinks.json")


Line 9: Line 9:


local MOVE_SPEED_RATES = mw.loadJsonData("Data:LocalizedUnits.json")
local MOVE_SPEED_RATES = mw.loadJsonData("Data:LocalizedUnits.json")
--------------------------------------------------------------------------------
-- Utility helpers
--------------------------------------------------------------------------------


local function has_rate_unit(str)
local function has_rate_unit(str)
Line 23: Line 27:
end
end


-- Get raw value, CSS class, and LocTokenOverride for a property
local function get_raw_value(item_name, prop)
    local item = data[item_name] or nil
    if not item then
        for k,v in pairs(data) do
            if v.Name == item_name then item = v; break end
        end
    end
    if not item then return nil, nil, nil end
    local raw_prop = item[prop]
    if type(raw_prop) == "table" then
        local loc_override = raw_prop.LocTokenOverride or prop
        return raw_prop.Value, raw_prop.CSSClass, loc_override
    else
        return raw_prop, nil, prop
    end
end
-- Strip embedded unit postfix when not EN (e.g. "3.0m" -> "3.0")
local function strip_embedded_postfix(val)
    if IS_EN then return val end
    if type(val) ~= "string" then return val end
    return val:match("^%-?%d+%.?%d*") or val
end
-- Check if property exists in language data
local function is_property_in_lang_data(prop)
    local suffixes = {"_label", "_Label", "_prefix", "_Prefix", "_postfix", "_Postfix", "_postvalue_label", "_Postvalue_Label"}
    for _, suffix in ipairs(suffixes) do
        if lang.get_string(prop .. suffix) then
            return true
        end
    end
    return false
end
-- Get item by name, ignoring disabled if possible
local function get_json_item(name)
    for _, v in pairs(data) do
        if v.Name == name and (v.IsDisabled == false or v.IsDisabled == nil) then
            return v
        end
    end
    for _, v in pairs(data) do
        if v.Name == name then return v end
    end
    return nil
end
-- Helper function: get first non-nil string from variants
local function first_non_nil(...)
local function first_non_nil(...)
     for i = 1, select("#", ...) do
     for i = 1, select("#", ...) do
Line 83: Line 35:
end
end


-- Helper: get lang string with case fallback
local function get_lang_with_fallback(base_key, suffix1, suffix2)
local function get_lang_with_fallback(base_key, suffix1, suffix2)
     return first_non_nil(
     return first_non_nil(
Line 91: Line 42:
end
end


-- Enhanced stat wrapper - prefix and value get enhanced styling, postfix/label don't
--------------------------------------------------------------------------------
local function format_stat_enhanced(item_name, prop, skip_label, allow_conditional)
-- Data access helpers (adapted for new Info-section format)
skip_label = skip_label or false
--------------------------------------------------------------------------------
if allow_conditional == nil then allow_conditional = true end
local value, css, loc_key = get_raw_value(item_name, prop)
if value == nil or value == 0 or value == "" then
return nil
end


local numeric_val = tonumber(tostring(value):match("^-?%d+%.?%d*")) or 0
-- Get item by name, preferring non-disabled
if numeric_val == 0 then
local function get_json_item(name)
return nil
    if data[name] and not data[name].IsDisabled then
end
        return data[name]
 
    end
local label_key = loc_key:gsub("^#", "")
    for _, v in pairs(data) do
 
        if v.Name == name and not v.IsDisabled then return v end
if not (
    end
lang.get_string(label_key.."_label") or
    for _, v in pairs(data) do
lang.get_string(label_key.."_Label") or
        if v.Name == name then return v end
lang.get_string(label_key.."_prefix") or
    end
lang.get_string(label_key.."_Prefix") or
    return nil
lang.get_string(label_key.."_postfix") or
end
lang.get_string(label_key.."_Postfix") or
lang.get_string(label_key.."_postvalue_label") or
lang.get_string(label_key.."_Postvalue_Label")
) then
return nil
end
 
if prop == "BuildUpPerShot" then label_key = "BuildupPerShot"
elseif prop == "DotDuration" then label_key = "DOTDuration"
end
 
local label = skip_label and "" or get_lang_with_fallback(label_key, "_label", "_Label")
local prefix = get_lang_with_fallback(label_key, "_prefix", "_Prefix")
local postfix = get_lang_with_fallback(label_key, "_postfix", "_Postfix")
 
if prefix == "" and postfix == "" and label == "" then
return nil
end
 
--------------------------------------------------
-- VALUE (Enhanced) with PREFIX and POSTFIX/SUFFIX
--------------------------------------------------
local val_str
local suffix = postfix


        -- Special spacing rule for HP/s
-- Get ordered Info sections (Info1, Info2, ...) from an item
     if postfix == "HP/s" then
local function get_info_sections(item)
         suffix = " " .. postfix
     local sections = {}
    local i = 1
    while item["Info" .. i] do
         table.insert(sections, item["Info" .. i])
        i = i + 1
     end
     end
      
     return sections
    if (css == "move_speed" or css == "sprint_speed")
end
    and postfix ~= "%"
    and not has_rate_unit(postfix)
    then
        local override = get_movespeed_rate_suffix()


         if override then
-- Find a property object by key across all Info sections and Other
            suffix = override
local function find_property_obj(item, prop_key)
         else
    for _, section in ipairs(get_info_sections(item)) do
             suffix = "m/s"
         for _, obj in ipairs(section.Main or {}) do
            suffix = suffix .. get_missing_rate_warning()
            if obj.Key == prop_key then return obj end
        end
         for _, obj in ipairs(section.Alt or {}) do
             if obj.Key == prop_key then return obj end
         end
         end
     end
     end
    if item.Other and item.Other[prop_key] then
        return item.Other[prop_key]
    end
    return nil
end


if prefix ~= "" then
-- Get raw value, type (CSS class), and LocTokenOverride for a property
if prefix == "{s:sign}" then
local function get_raw_value(item_name, prop)
local num = tonumber(tostring(value):match("^-?%d+%.?%d*"))
    local item = data[item_name] or get_json_item(item_name)
if num and num >= 0 then
    if not item then return nil, nil, nil end
prefix = "+"
else
prefix = ""
end
end
if suffix ~= "" and suffix ~= "%" then
val_str = string.format(
"{{#invoke:Enhanced|render|%s|%s|prefix=%s|suffix=%s|noicon=true}}",
item_name,
prop,
prefix,
suffix
)
else
val_str = string.format(
"{{#invoke:Enhanced|render|%s|%s|prefix=%s|noicon=true}}",
item_name,
prop,
prefix
)
end
else
if suffix ~= "" and suffix ~= "%" then
val_str = string.format(
"{{#invoke:Enhanced|render|%s|%s|suffix=%s|noicon=true}}",
item_name,
prop,
suffix
)
else
val_str = string.format(
"{{#invoke:Enhanced|render|%s|%s|noicon=true}}",
item_name,
prop
)
end
end


--------------------------------------------------
    local obj = find_property_obj(item, prop)
-- Postfix (UNSTYLED)
    if not obj then return nil, nil, nil end
--------------------------------------------------
if postfix ~= "" and postfix ~= "%" and not val_str:find(postfix, 1, true) then
if postfix == "HP/s" then
val_str = val_str .. " " .. postfix
else
val_str = val_str .. postfix
end
end


--------------------------------------------------
    return obj.Value, obj.Type, obj.LocTokenOverride or prop
-- Label (UNSTYLED - only if not skipped)
end
--------------------------------------------------
if label ~= "" then
    local link_page = stat_links[prop]
    if link_page then
        if link_page == label then
            val_str = val_str .. " [[" .. label .. "]]"
        else
            val_str = val_str .. " [[" .. link_page .. "|" .. label .. "]]"
        end
    else
        val_str = val_str .. " " .. label
    end
end


--------------------------------------------------
-- Check if property has language data (checks both key and optional loc override)
-- Conditional marker
local function is_property_in_lang_data(prop, loc_override)
--------------------------------------------------
    local suffixes = {
    if allow_conditional then
         "_label", "_Label", "_prefix", "_Prefix",
        local item = get_json_item(item_name)
        "_postfix", "_Postfix", "_postvalue_label", "_Postvalue_Label"
        local raw = item and item[prop]
    }
         if type(raw) == "table"
    local keys = { prop }
          and (raw.UsageFlags == "ConditionallyApplied"
    if loc_override and loc_override ~= prop then
            or raw.UsageFlags == "ConditionallyEnemyApplied")
         table.insert(keys, loc_override)
         then
    end
            val_str = val_str .. string.format(
    for _, key in ipairs(keys) do
                ' <span style="color:#C0C0C0">(%s)</span>',
        for _, suffix in ipairs(suffixes) do
                lang.get_string("Citadel_Shop_ConditionalAttribute")
            if lang.get_string(key .. suffix) then return true end
            )
         end
         end
     end
     end
 
    return false
return val_str
end
end


-- Special formatting for StatusEffect properties (enhanced variant)
-- Returns item keys that build from this item, sorted by tier
local function format_property_for_infobox_enhanced(item_name, prop)
    if prop:match("^StatusEffect") then
        return string.format(
            "[[{{#invoke:Lang|get_string|Citadel_%s}}]] [[{{#invoke:Lang|get_string|Citadel_StatusEffect}}]]",
            prop
        )
    else
        return format_stat_enhanced(item_name, prop)
    end
end
 
-- Returns items that build from this item, sorted by tier
local function get_component_of_sorted(item_input)
local function get_component_of_sorted(item_input)
     local target_key = nil
     local target_key = nil
Line 265: Line 123:
     else
     else
         for k, v in pairs(data) do
         for k, v in pairs(data) do
             if v.Name == item_input and (v.IsDisabled == false or v.IsDisabled == nil) then
             if v.Name == item_input and not v.IsDisabled then
                 target_key = k; break
                 target_key = k; break
             end
             end
Line 274: Line 132:
     local parents = {}
     local parents = {}
     for key, item in pairs(data) do
     for key, item in pairs(data) do
         if item.IsDisabled ~= true and item.Components and type(item.Components) == "table" then
         if not item.IsDisabled and item.Components and type(item.Components) == "table" then
             for _, comp in ipairs(item.Components) do
             for _, comp in ipairs(item.Components) do
                 if comp == target_key then
                 if comp == target_key then
Line 285: Line 143:


     table.sort(parents, function(a, b)
     table.sort(parents, function(a, b)
         local tier_a = tonumber(data[a] and data[a]["Tier"]) or 0
         local tier_a = tonumber(data[a] and data[a].Tier) or 0
         local tier_b = tonumber(data[b] and data[b]["Tier"]) or 0
         local tier_b = tonumber(data[b] and data[b].Tier) or 0
         return tier_a < tier_b
         return tier_a < tier_b
     end)
     end)
Line 293: Line 151:
end
end


-- Format stat value for Infobox, handling prefix/postfix, CSS, scaling, and conditional
--------------------------------------------------------------------------------
-- allow_conditional should be true for ImportantProperties, false for regular Properties
-- Shared formatting sub-routines
--------------------------------------------------------------------------------
 
local function resolve_label_key(prop_key, loc_override)
    local label_key = (loc_override or prop_key):gsub("^#", "")
    if prop_key == "BuildUpPerShot" then label_key = "BuildupPerShot"
    elseif prop_key == "DotDuration" then label_key = "DOTDuration" end
    return label_key
end
 
local function resolve_prefix(prefix, numeric_val)
    if prefix == "{s:sign}" then
        return (numeric_val >= 0) and "+" or ""
    end
    return prefix
end
 
local function resolve_suffix(postfix, css_type)
    local suffix = postfix
    if postfix == "HP/s" then suffix = "&#32;" .. postfix end
    if (css_type == "move_speed" or css_type == "sprint_speed")
      and postfix ~= "%" and not has_rate_unit(postfix) then
        local override = get_movespeed_rate_suffix()
        suffix = override or ("m/s" .. get_missing_rate_warning())
    end
    return suffix
end
 
local function append_label(val_str, prop_key, label)
    if label == "" then return val_str end
    local link_page = stat_links[prop_key]
    if link_page then
        if link_page == label then
            return val_str .. " [[" .. label .. "]]"
        else
            return val_str .. " [[" .. link_page .. "|" .. label .. "]]"
        end
    end
    return val_str .. " " .. label
end
 
local function append_conditional(val_str, allow_conditional, usage_flags)
    if allow_conditional
      and (usage_flags == "ConditionallyApplied"
        or usage_flags == "ConditionallyEnemyApplied") then
        return val_str .. string.format(
            ' <span style="color:#C0C0C0">(%s)</span>',
            lang.get_string("Citadel_Shop_ConditionalAttribute")
        )
    end
    return val_str
end
 
--------------------------------------------------------------------------------
-- Core formatting: non-enhanced
--------------------------------------------------------------------------------
 
local function format_value(prop_key, value, css_type, loc_override,
                            skip_label, allow_conditional, usage_flags, scale_info)
    if value == nil or value == 0 or value == "" then return nil end
 
    local numeric_val = tonumber(tostring(value):match("^-?%d+%.?%d*")) or 0
    if numeric_val == 0 then return nil end
 
    local label_key = resolve_label_key(prop_key, loc_override)
    local label  = skip_label and "" or get_lang_with_fallback(label_key, "_label", "_Label")
    local prefix  = get_lang_with_fallback(label_key, "_prefix", "_Prefix")
    local postfix = get_lang_with_fallback(label_key, "_postfix", "_Postfix")
 
    if prefix == "" and postfix == "" and label == "" then return nil end
 
    prefix = resolve_prefix(prefix, numeric_val)
    local suffix = resolve_suffix(postfix, css_type)
 
    -- Compose value string
    local val_str = tostring(numeric_val)
    if prefix ~= "" then val_str = prefix .. val_str end
    if suffix ~= "" and not val_str:find(suffix, 1, true) then
        val_str = val_str .. suffix
    end
 
    -- Scale handling
    if scale_info and scale_info.Value and scale_info.Value ~= 0 then
        local scale_val = util_module.round_to_sig_fig(scale_info.Value, 2)
        local tmpl = (scale_info.Type == "power_increase") and "Boon" or "Ss"
        val_str = val_str .. " " .. mw.getCurrentFrame():expandTemplate{
            title = tmpl, args = { scale_val }
        }
    end
 
    val_str = append_label(val_str, prop_key, label)
    val_str = append_conditional(val_str, allow_conditional, usage_flags)
 
    return val_str
end
 
-- Convenience wrapper: look up a property from item data, then format
local function format_stat(item_name, prop, skip_label, debug, allow_conditional)
local function format_stat(item_name, prop, skip_label, debug, allow_conditional)
     skip_label = skip_label or false
     skip_label = skip_label or false
     if allow_conditional == nil then allow_conditional = true end
     if allow_conditional == nil then allow_conditional = true end


     local value, css, loc_key = get_raw_value(item_name, prop)
     local item = get_json_item(item_name)
    if not item then return nil end
 
    local obj = find_property_obj(item, prop)
    if not obj then return nil end
 
    return format_value(
        prop, obj.Value, obj.Type, obj.LocTokenOverride,
        skip_label, allow_conditional, obj.UsageFlags, obj.Scale
    )
end
 
--------------------------------------------------------------------------------
-- Core formatting: enhanced
--------------------------------------------------------------------------------
 
local function format_value_enhanced(item_name, prop_key, value, css_type,
                                    loc_override, skip_label,
                                    allow_conditional, usage_flags)
     if value == nil or value == 0 or value == "" then return nil end
     if value == nil or value == 0 or value == "" then return nil end


Line 305: Line 277:
     if numeric_val == 0 then return nil end
     if numeric_val == 0 then return nil end


     local label_key = loc_key:gsub("^#", "")
     local label_key = resolve_label_key(prop_key, loc_override)
    if prop == "BuildUpPerShot" then label_key = "BuildupPerShot"
    elseif prop == "DotDuration" then label_key = "DOTDuration" end


     local label = skip_label and "" or get_lang_with_fallback(label_key, "_label", "_Label")
    -- Enhanced requires lang data to exist
     local prefix = get_lang_with_fallback(label_key, "_prefix", "_Prefix")
    if not (
        lang.get_string(label_key.."_label") or lang.get_string(label_key.."_Label") or
        lang.get_string(label_key.."_prefix") or lang.get_string(label_key.."_Prefix") or
        lang.get_string(label_key.."_postfix") or lang.get_string(label_key.."_Postfix") or
        lang.get_string(label_key.."_postvalue_label") or lang.get_string(label_key.."_Postvalue_Label")
    ) then return nil end
 
     local label   = skip_label and "" or get_lang_with_fallback(label_key, "_label", "_Label")
     local prefix = get_lang_with_fallback(label_key, "_prefix", "_Prefix")
     local postfix = get_lang_with_fallback(label_key, "_postfix", "_Postfix")
     local postfix = get_lang_with_fallback(label_key, "_postfix", "_Postfix")


     if prefix == "" and postfix == "" and label == "" then return nil end
     if prefix == "" and postfix == "" and label == "" then return nil end


     --------------------------------------------------
     prefix = resolve_prefix(prefix, numeric_val)
     -- Prefix logic
    local suffix = resolve_suffix(postfix, css_type)
     --------------------------------------------------
 
     if prefix == "{s:sign}" then
     -- Build Enhanced invoke
        if numeric_val >= 0 then
     local extras = {}
            prefix = "+"
     if prefix ~= "" then table.insert(extras, "prefix=" .. prefix) end
         else
    if suffix ~= "" and suffix ~= "%" then table.insert(extras, "suffix=" .. suffix) end
            prefix = ""
    table.insert(extras, "noicon=true")
         end
 
    local val_str = string.format(
        "{{#invoke:Enhanced|render|%s|%s|%s}}",
         item_name, prop_key, table.concat(extras, "|")
    )
 
    -- Unstyled postfix (if not already present)
    if postfix ~= "" and postfix ~= "%" and not val_str:find(postfix, 1, true) then
         val_str = val_str .. (postfix == "HP/s" and (" " .. postfix) or postfix)
     end
     end


     --------------------------------------------------
     val_str = append_label(val_str, prop_key, label)
    -- Postfix / move speed handling
    val_str = append_conditional(val_str, allow_conditional, usage_flags)
    --------------------------------------------------
 
    local suffix = postfix
    return val_str
    if postfix == "HP/s" then suffix = "&#32;" .. postfix end
end
    if (css == "move_speed" or css == "sprint_speed") and postfix ~= "%" and not has_rate_unit(postfix) then
        local override = get_movespeed_rate_suffix()
        if override then
            suffix = override
        else
            suffix = "m/s" .. get_missing_rate_warning()
        end
    end


    --------------------------------------------------
-- Convenience wrapper: look up a property from item data, then format (enhanced)
    -- Compose main value string
local function format_stat_enhanced(item_name, prop, skip_label, allow_conditional)
    --------------------------------------------------
     skip_label = skip_label or false
    local val_str = tostring(numeric_val)
     if allow_conditional == nil then allow_conditional = true end
     if prefix ~= "" then val_str = prefix .. val_str end
     if suffix ~= "" and not val_str:find(suffix, 1, true) then val_str = val_str .. suffix end


    --------------------------------------------------
    -- Scale handling (Boon / Ss)
    --------------------------------------------------
     local item = get_json_item(item_name)
     local item = get_json_item(item_name)
     local raw_prop = item and item[prop]
    if not item then return nil end
     if type(raw_prop) == "table" and raw_prop.Scale and raw_prop.Scale.Value ~= 0 then
 
         local scale_val = util_module.round_to_sig_fig(raw_prop.Scale.Value, 2)
     local obj = find_property_obj(item, prop)
        local template_name = (raw_prop.Scale.Type == "power_increase") and "Boon" or "Ss"
     if not obj then return nil end
         val_str = val_str .. " " .. mw.getCurrentFrame():expandTemplate{ title = template_name, args = { scale_val } }
 
    end
    return format_value_enhanced(
         item_name, prop, obj.Value, obj.Type,
         obj.LocTokenOverride, skip_label, allow_conditional, obj.UsageFlags
    )
end


    --------------------------------------------------
--------------------------------------------------------------------------------
    -- Label (unstyled)
-- StatusEffect special formatting
    --------------------------------------------------
--------------------------------------------------------------------------------
    if label ~= "" then
        local link_page = stat_links[prop]
        if link_page then
            if link_page == label then
                val_str = val_str .. " [[" .. label .. "]]"
            else
                val_str = val_str .. " [[" .. link_page .. "|" .. label .. "]]"
            end
        else
            val_str = val_str .. " " .. label
        end
    end


    --------------------------------------------------
local function format_property_for_infobox(item_name, prop, skip_label, debug)
    -- Conditional marker
     if prop:match("^StatusEffect") then
    --------------------------------------------------
         return string.format(
     if allow_conditional and type(raw_prop) == "table" and
             "[[{{#invoke:Lang|get_string|Citadel_%s}}]] [[{{#invoke:Lang|get_string|Citadel_StatusEffect}}]]",
      (raw_prop.UsageFlags == "ConditionallyApplied" or raw_prop.UsageFlags == "ConditionallyEnemyApplied") then
             prop
         val_str = val_str .. string.format(
             ' <span style="color:#C0C0C0">(%s)</span>',
             lang.get_string("Citadel_Shop_ConditionalAttribute")
         )
         )
     end
     end
 
     return format_stat(item_name, prop, skip_label, debug, true)
     return val_str
end
end


-- Special formatting for StatusEffect properties
local function format_property_for_infobox_enhanced(item_name, prop)
local function format_property_for_infobox(item_name, prop, skip_label, debug)
     if prop:match("^StatusEffect") then
     if prop:match("^StatusEffect") then
         return string.format(
         return string.format(
Line 395: Line 355:
             prop
             prop
         )
         )
    else
        return format_stat(item_name, prop, skip_label, debug, true)
     end
     end
    return format_stat_enhanced(item_name, prop)
end
--------------------------------------------------------------------------------
-- Tooltip builder helpers
--------------------------------------------------------------------------------
-- Format the Cooldown / ChargeUp fields that sit directly on an Info section
local function format_section_cooldown(section, item_name, enhanced)
    local result = {}
    if section.Cooldown and section.Cooldown ~= 0 then
        if enhanced then
            result.cooldown = format_value_enhanced(
                item_name, "AbilityCooldown", section.Cooldown,
                nil, nil, true, false, nil
            )
        else
            result.cooldown = format_value(
                "AbilityCooldown", section.Cooldown,
                nil, nil, true, false, nil, nil
            )
        end
    end
    if section.ChargeUp and section.ChargeUp ~= 0 then
        if enhanced then
            result.chargeup = format_value_enhanced(
                item_name, "AbilityChargeUpTime", section.ChargeUp,
                nil, nil, true, false, nil
            )
        else
            result.chargeup = format_value(
                "AbilityChargeUpTime", section.ChargeUp,
                nil, nil, true, false, nil, nil
            )
        end
    end
    return result
end
-- Iterate a property list (Main or Alt), format each, and append to lines
-- Returns the next stat_index
local function process_stats(lines, fmt, counter, start_index, prop_list,
                            item_name, seen, formatter)
    local stat_index = start_index
    for _, prop_obj in ipairs(prop_list or {}) do
        local key = prop_obj.Key
        if is_property_in_lang_data(key, prop_obj.LocTokenOverride) and not seen[key] then
            local val = formatter(prop_obj)
            if val then
                table.insert(lines, string.format(fmt, counter, stat_index, val))
                stat_index = stat_index + 1
                seen[key] = true
            end
        end
    end
    return stat_index
end
end


-- Build raw wikitext for the default tooltip infobox (no preprocess)
--------------------------------------------------------------------------------
-- Build default (non-enhanced) tooltip
--------------------------------------------------------------------------------
 
local function build_tooltip(frame)
local function build_tooltip(frame)
     local item_name = frame.args[1]
     local item_name = frame.args[1]
Line 419: Line 436:
     end
     end


     ----------------------------------------------------------------------
     local sections = get_info_sections(item)
    -- Check if AbilityCooldown or AbilityChargeUpTime exists in sections
    ----------------------------------------------------------------------
    local cooldown_found_in_sections = false
    local chargeup_found_in_sections = false
    for _, section in ipairs(item.TooltipSections or {}) do
        for _, entry in ipairs(section.Entries or {}) do
            for _, prop in ipairs(entry.Properties or {}) do
                if prop == "AbilityCooldown" then cooldown_found_in_sections = true end
                if prop == "AbilityChargeUpTime" then chargeup_found_in_sections = true end
            end
            for _, prop in ipairs(entry.ImportantProperties or {}) do
                if prop == "AbilityCooldown" then cooldown_found_in_sections = true end
                if prop == "AbilityChargeUpTime" then chargeup_found_in_sections = true end
            end
        end
    end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Innate stats
     -- Innate stats
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     local innate_index = 1
     local innate_index = 1
     for _, section in ipairs(item.TooltipSections or {}) do
     for _, section in ipairs(sections) do
         if section.Type == "EArea_Innate" then
         if section.Type == "Innate" then
             for _, entry in ipairs(section.Entries or {}) do
             for _, prop_obj in ipairs(section.Alt or {}) do
                 for _, prop in ipairs(entry.Properties or {}) do
                 if is_property_in_lang_data(prop_obj.Key, prop_obj.LocTokenOverride) then
                     if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime" then
                     local val = format_value(
                        local val = format_stat(item_name, prop, false, debug, false)
                        prop_obj.Key, prop_obj.Value, prop_obj.Type,
                        if val then
                        prop_obj.LocTokenOverride, false, false,
                            table.insert(lines, string.format("| item_stat%d = %s", innate_index, val))
                        prop_obj.UsageFlags, prop_obj.Scale
                            innate_index = innate_index + 1
                    )
                        end
                    if val then
                        table.insert(lines, string.format("| item_stat%d = %s", innate_index, val))
                        innate_index = innate_index + 1
                     end
                     end
                 end
                 end
             end
             end
            local cd = format_section_cooldown(section, item_name, false)
            if cd.cooldown then table.insert(lines, "| item_stat_cooldown = " .. cd.cooldown) end
            if cd.chargeup then table.insert(lines, "| item_stat_chargeup = " .. cd.chargeup) end
         end
         end
     end
     end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Passive stats
     -- Passive stats (any section that is not Innate or Active)
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     local passive_counter = 1
     local passive_counter = 1
     for _, section in ipairs(item.TooltipSections or {}) do
     for _, section in ipairs(sections) do
         if section.Type ~= "EArea_Innate" and section.Type ~= "EArea_Active" then
         if section.Type ~= "Innate" and section.Type ~= "Active" then
             for _, entry in ipairs(section.Entries or {}) do
             local loc = section.DescKey and section.DescKey:gsub("#", "") or nil
                local loc = entry.LocString and entry.LocString:gsub("#","") or nil
            if loc and loc ~= "" then
                if loc then
                table.insert(lines, string.format(
                    table.insert(lines, string.format(
                    "| passive%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}",
                        "| passive%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}",
                    passive_counter, loc, item_name
                        passive_counter, loc, item_name
                ))
                    ))
            end
                end


                local stat_index = 1
            local stat_index = 1
                local seen_props = {}
            local seen = {}


                for _, prop in ipairs(entry.ImportantProperties or {}) do
            -- Main (important properties) — allow_conditional = true
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
            stat_index = process_stats(
                      and is_property_in_lang_data(prop) and not seen_props[prop] then
                lines, "| passive%d_stat%d = %s", passive_counter, stat_index,
                        local val = format_stat(item_name, prop, false, debug, true)
                section.Main, item_name, seen,
                        if val then
                function(obj)
                            table.insert(lines, string.format("| passive%d_stat%d = %s", passive_counter, stat_index, val))
                    return format_value(
                            stat_index = stat_index + 1
                        obj.Key, obj.Value, obj.Type, obj.LocTokenOverride,
                            seen_props[prop] = true
                         false, true, obj.UsageFlags, obj.Scale
                         end
                     )
                     end
                 end
                 end
            )


                for _, prop in ipairs(entry.Properties or {}) do
            -- Alt (regular properties) — allow_conditional = false
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
            process_stats(
                      and is_property_in_lang_data(prop) and not seen_props[prop] then
                lines, "| passive%d_stat%d = %s", passive_counter, stat_index,
                        local val = format_stat(item_name, prop, false, debug, false)
                section.Alt, item_name, seen,
                        if val then
                function(obj)
                            table.insert(lines, string.format("| passive%d_stat%d = %s", passive_counter, stat_index, val))
                    return format_value(
                            stat_index = stat_index + 1
                        obj.Key, obj.Value, obj.Type, obj.LocTokenOverride,
                            seen_props[prop] = true
                         false, false, obj.UsageFlags, obj.Scale
                         end
                     )
                     end
                 end
                 end
            )


                for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do
            local cd = format_section_cooldown(section, item_name, false)
                    for _, prop in ipairs(prop_list) do
            if cd.cooldown then
                        if prop == "AbilityCooldown" then
                table.insert(lines, string.format("| passive%d_cooldown = %s", passive_counter, cd.cooldown))
                            local cd = format_stat(item_name, prop, true, debug)
            end
                            if cd then table.insert(lines, string.format("| passive%d_cooldown = %s", passive_counter, cd)) end
            if cd.chargeup then
                        end
                table.insert(lines, string.format("| passive%d_chargeup = %s", passive_counter, cd.chargeup))
                        if prop == "AbilityChargeUpTime" then
            end
                            local cu = format_stat(item_name, prop, true, debug)
                            if cu then table.insert(lines, string.format("| passive%d_chargeup = %s", passive_counter, cu)) end
                        end
                    end
                end


                passive_counter = passive_counter + 1
            passive_counter = passive_counter + 1
            end
         end
         end
     end
     end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Active stats
     -- Active stats
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     local active_index = 1
     local active_index = 1
     for _, section in ipairs(item.TooltipSections or {}) do
     for _, section in ipairs(sections) do
         if section.Type == "EArea_Active" then
         if section.Type == "Active" then
             for _, entry in ipairs(section.Entries or {}) do
             local loc = section.DescKey and section.DescKey:gsub("#", "") or nil
                if entry.LocString then
            if loc and loc ~= "" then
                    table.insert(lines, string.format(
                table.insert(lines, string.format(
                        "| active%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}",
                    "| active%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}",
                        active_index, entry.LocString:gsub("#",""), item_name
                    active_index, loc, item_name
                    ))
                ))
                end
            end


                local stat_index = 1
            local stat_index = 1
                local seen_props = {}
            local seen = {}


                for _, prop in ipairs(entry.ImportantProperties or {}) do
            stat_index = process_stats(
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                lines, "| active%d_stat%d = %s", active_index, stat_index,
                      and is_property_in_lang_data(prop) and not seen_props[prop] then
                section.Main, item_name, seen,
                        local val = format_stat(item_name, prop, false, debug, true)
                function(obj)
                        if val then
                    return format_value(
                            table.insert(lines, string.format("| active%d_stat%d = %s", active_index, stat_index, val))
                        obj.Key, obj.Value, obj.Type, obj.LocTokenOverride,
                            stat_index = stat_index + 1
                         false, true, obj.UsageFlags, obj.Scale
                            seen_props[prop] = true
                     )
                         end
                     end
                 end
                 end
            )


                for _, prop in ipairs(entry.Properties or {}) do
            process_stats(
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                lines, "| active%d_stat%d = %s", active_index, stat_index,
                      and is_property_in_lang_data(prop) and not seen_props[prop] then
                section.Alt, item_name, seen,
                        local val = format_stat(item_name, prop, false, debug, false)
                function(obj)
                        if val then
                    return format_value(
                            table.insert(lines, string.format("| active%d_stat%d = %s", active_index, stat_index, val))
                        obj.Key, obj.Value, obj.Type, obj.LocTokenOverride,
                            stat_index = stat_index + 1
                         false, false, obj.UsageFlags, obj.Scale
                            seen_props[prop] = true
                     )
                         end
                     end
                 end
                 end
            )


                for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do
            local cd = format_section_cooldown(section, item_name, false)
                    for _, prop in ipairs(prop_list) do
            if cd.cooldown then
                        if prop == "AbilityCooldown" then
                table.insert(lines, string.format("| active%d_cooldown = %s", active_index, cd.cooldown))
                            local cd = format_stat(item_name, prop, true, debug)
            end
                            if cd then table.insert(lines, string.format("| active%d_cooldown = %s", active_index, cd)) end
            if cd.chargeup then
                        end
                table.insert(lines, string.format("| active%d_chargeup = %s", active_index, cd.chargeup))
                        if prop == "AbilityChargeUpTime" then
                            local cu = format_stat(item_name, prop, true, debug)
                            if cu then table.insert(lines, string.format("| active%d_chargeup = %s", active_index, cu)) end
                        end
                    end
                end
 
                active_index = active_index + 1
             end
             end
        end
    end


    ----------------------------------------------------------------------
             active_index = active_index + 1
    -- Global fallback for AbilityCooldown and AbilityChargeUpTime
    -- Attaches to the active section if one exists, otherwise innate
    ----------------------------------------------------------------------
    if not cooldown_found_in_sections and not chargeup_found_in_sections and item.AbilityCooldown then
        local cd = format_stat(item_name, "AbilityCooldown", true, debug)
        if cd then
            local has_active = false
             for _, section in ipairs(item.TooltipSections or {}) do
                if section.Type == "EArea_Active" then has_active = true; break end
            end
            if has_active then
                table.insert(lines, "| active1_cooldown = " .. cd)
            else
                table.insert(lines, "| item_stat_cooldown = " .. cd)
            end
         end
         end
     end
     end


     if not chargeup_found_in_sections and item.AbilityChargeUpTime then
     ------------------------------------------------------------------
        local cu = format_stat(item_name, "AbilityChargeUpTime", true, debug)
        if cu then table.insert(lines, "| item_stat_chargeup = " .. cu) end
    end
 
    ----------------------------------------------------------------------
     -- Components
     -- Components
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     for i = 1, 2 do
     for i = 1, 2 do
         local comp = ItemData.get_component_name { args = { item_name, i } }
         local comp = ItemData.get_component_name { args = { item_name, i } }
Line 610: Line 577:
     end
     end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Is Component Of (sorted by tier)
     -- Is Component Of (sorted by tier)
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     local parents = get_component_of_sorted(item_name)
     local parents = get_component_of_sorted(item_name)
     for i, key in ipairs(parents) do
     for i, key in ipairs(parents) do
         local parent_name = data[key] and data[key]["Name"] or ""
         local parent_name = data[key] and data[key].Name or ""
         if parent_name ~= "" then
         if parent_name ~= "" then
             table.insert(lines, string.format("| iscomponentof%d_name = %s", i, parent_name))
             table.insert(lines, string.format("| iscomponentof%d_name = %s", i, parent_name))
Line 621: Line 588:
     end
     end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Sounds
     -- Sounds
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     for key, value in pairs(frame.args) do
     for key, value in pairs(frame.args) do
         local index = tostring(key):match("^sound(%d+)$")
         local index = tostring(key):match("^sound(%d+)$")
Line 631: Line 598:
     end
     end


    ----------------------------------------------------------------------
     table.insert(lines, "}}")
     table.insert(lines, "}}")
     return table.concat(lines, "\n"), debug
     return table.concat(lines, "\n"), debug
end
end


-- Build raw wikitext for the enhanced tooltip infobox (no preprocess)
--------------------------------------------------------------------------------
-- Build enhanced tooltip
--------------------------------------------------------------------------------
 
local function build_tooltip_enhanced(frame)
local function build_tooltip_enhanced(frame)
     local item_name = frame.args[1]
     local item_name = frame.args[1]
Line 655: Line 624:
     end
     end


     ----------------------------------------------------------------------
     local sections = get_info_sections(item)
    -- Check if AbilityCooldown or AbilityChargeUpTime exists in sections
    ----------------------------------------------------------------------
    local cooldown_found_in_sections = false
    local chargeup_found_in_sections = false
    for _, section in ipairs(item.TooltipSections or {}) do
        for _, entry in ipairs(section.Entries or {}) do
            for _, prop in ipairs(entry.Properties or {}) do
                if prop == "AbilityCooldown" then cooldown_found_in_sections = true end
                if prop == "AbilityChargeUpTime" then chargeup_found_in_sections = true end
            end
            for _, prop in ipairs(entry.ImportantProperties or {}) do
                if prop == "AbilityCooldown" then cooldown_found_in_sections = true end
                if prop == "AbilityChargeUpTime" then chargeup_found_in_sections = true end
            end
        end
    end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Innate stats (Enhanced)
     -- Innate stats (Enhanced)
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     local innate_index = 1
     local innate_index = 1
     for _, section in ipairs(item.TooltipSections or {}) do
     for _, section in ipairs(sections) do
         if section.Type == "EArea_Innate" then
         if section.Type == "Innate" then
             for _, entry in ipairs(section.Entries or {}) do
             for _, prop_obj in ipairs(section.Alt or {}) do
                 for _, prop in ipairs(entry.Properties or {}) do
                 if is_property_in_lang_data(prop_obj.Key, prop_obj.LocTokenOverride) then
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                    local val = format_value_enhanced(
                      and is_property_in_lang_data(prop) then
                        item_name, prop_obj.Key, prop_obj.Value, prop_obj.Type,
                        local val = format_stat_enhanced(item_name, prop, nil, false)
                        prop_obj.LocTokenOverride, nil, false, prop_obj.UsageFlags
                        if val then
                    )
                            table.insert(
                    if val then
                                lines,
                        table.insert(lines, string.format("| item_stat%d = %s", innate_index, val))
                                string.format(
                        innate_index = innate_index + 1
                                    "| item_stat%d = %s",
                                    innate_index,
                                    val
                                )
                            )
                            innate_index = innate_index + 1
                        end
                     end
                     end
                 end
                 end
Line 701: Line 647:
     end
     end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Passive stats (Enhanced)
     -- Passive stats (Enhanced)
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     local passive_counter = 1
     local passive_counter = 1
     for _, section in ipairs(item.TooltipSections or {}) do
     for _, section in ipairs(sections) do
         if section.Type ~= "EArea_Innate" and section.Type ~= "EArea_Active" then
         if section.Type ~= "Innate" and section.Type ~= "Active" then
             for _, entry in ipairs(section.Entries or {}) do
             local loc = section.DescKey and section.DescKey:gsub("#", "") or nil
                if entry.LocString then
            if loc and loc ~= "" then
                    table.insert(lines, string.format(
                table.insert(lines, string.format(
                        "| passive%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}",
                    "| passive%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}",
                        passive_counter,
                    passive_counter, loc, item_name
                        entry.LocString:gsub("#",""),
                ))
                        item_name
            end
                    ))
                end


                local stat_index = 1
            local stat_index = 1
                local seen = {}
            local seen = {}


                for _, prop in ipairs(entry.ImportantProperties or {}) do
            -- Main — use format_property_for_infobox_enhanced (handles StatusEffect)
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
            stat_index = process_stats(
                      and is_property_in_lang_data(prop) and not seen[prop] then
                lines, "| passive%d_stat%d = %s", passive_counter, stat_index,
                        local val = format_property_for_infobox_enhanced(item_name, prop)
                section.Main, item_name, seen,
                        if val then
                function(obj)
                            table.insert(
                    return format_property_for_infobox_enhanced(item_name, obj.Key)
                                lines,
                                string.format(
                                    "| passive%d_stat%d = %s",
                                    passive_counter,
                                    stat_index,
                                    val
                                )
                            )
                            stat_index = stat_index + 1
                            seen[prop] = true
                        end
                    end
                 end
                 end
            )


                for _, prop in ipairs(entry.Properties or {}) do
            -- Alt — use format_value_enhanced directly
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
            process_stats(
                      and is_property_in_lang_data(prop) and not seen[prop] then
                lines, "| passive%d_stat%d = %s", passive_counter, stat_index,
                        local val = format_stat_enhanced(item_name, prop, nil, false)
                section.Alt, item_name, seen,
                        if val then
                function(obj)
                            table.insert(
                    return format_value_enhanced(
                                lines,
                        item_name, obj.Key, obj.Value, obj.Type,
                                string.format(
                         obj.LocTokenOverride, nil, false, obj.UsageFlags
                                    "| passive%d_stat%d = %s",
                     )
                                    passive_counter,
                                    stat_index,
                                    val
                                )
                            )
                            stat_index = stat_index + 1
                            seen[prop] = true
                         end
                     end
                 end
                 end
            )


                for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do
            local cd = format_section_cooldown(section, item_name, true)
                    for _, prop in ipairs(prop_list) do
            if cd.cooldown then
                        if prop == "AbilityCooldown" then
                table.insert(lines, string.format("| passive%d_cooldown = %s", passive_counter, cd.cooldown))
                            local cd = format_stat_enhanced(item_name, prop, true)
            end
                            if cd then
            if cd.chargeup then
                                table.insert(lines, string.format("| passive%d_cooldown = %s", passive_counter, cd))
                table.insert(lines, string.format("| passive%d_chargeup = %s", passive_counter, cd.chargeup))
                            end
            end
                        end
                        if prop == "AbilityChargeUpTime" then
                            local cu = format_stat_enhanced(item_name, prop, true)
                            if cu then
                                table.insert(lines, string.format("| passive%d_chargeup = %s", passive_counter, cu))
                            end
                        end
                    end
                end


                passive_counter = passive_counter + 1
            passive_counter = passive_counter + 1
            end
         end
         end
     end
     end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Active stats (Enhanced)
     -- Active stats (Enhanced)
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     local active_index = 1
     local active_index = 1
     for _, section in ipairs(item.TooltipSections or {}) do
     for _, section in ipairs(sections) do
         if section.Type == "EArea_Active" then
         if section.Type == "Active" then
             for _, entry in ipairs(section.Entries or {}) do
             local loc = section.DescKey and section.DescKey:gsub("#", "") or nil
                if entry.LocString then
            if loc and loc ~= "" then
                    table.insert(lines, string.format(
                table.insert(lines, string.format(
                        "| active%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}",
                    "| active%d_description = {{#invoke:Lang|get_string|%s|item_name=%s}}",
                        active_index,
                    active_index, loc, item_name
                        entry.LocString:gsub("#",""),
                ))
                        item_name
            end
                    ))
                end


                local stat_index = 1
            local stat_index = 1
                local seen = {}
            local seen = {}


                for _, prop in ipairs(entry.ImportantProperties or {}) do
            stat_index = process_stats(
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                lines, "| active%d_stat%d = %s", active_index, stat_index,
                      and is_property_in_lang_data(prop) and not seen[prop] then
                section.Main, item_name, seen,
                        local val = format_property_for_infobox_enhanced(item_name, prop)
                function(obj)
                        if val then
                    return format_property_for_infobox_enhanced(item_name, obj.Key)
                            table.insert(
                                lines,
                                string.format(
                                    "| active%d_stat%d = %s",
                                    active_index,
                                    stat_index,
                                    val
                                )
                            )
                            stat_index = stat_index + 1
                            seen[prop] = true
                        end
                    end
                 end
                 end
            )


                for _, prop in ipairs(entry.Properties or {}) do
            process_stats(
                    if prop ~= "AbilityCooldown" and prop ~= "AbilityChargeUpTime"
                lines, "| active%d_stat%d = %s", active_index, stat_index,
                      and is_property_in_lang_data(prop) and not seen[prop] then
                section.Alt, item_name, seen,
                        local val = format_stat_enhanced(item_name, prop, nil, false)
                function(obj)
                        if val then
                    return format_value_enhanced(
                            table.insert(
                        item_name, obj.Key, obj.Value, obj.Type,
                                lines,
                         obj.LocTokenOverride, nil, false, obj.UsageFlags
                                string.format(
                     )
                                    "| active%d_stat%d = %s",
                                    active_index,
                                    stat_index,
                                    val
                                )
                            )
                            stat_index = stat_index + 1
                            seen[prop] = true
                         end
                     end
                 end
                 end
            )


                for _, prop_list in ipairs({entry.Properties or {}, entry.ImportantProperties or {}}) do
            local cd = format_section_cooldown(section, item_name, true)
                    for _, prop in ipairs(prop_list) do
            if cd.cooldown then
                        if prop == "AbilityCooldown" then
                table.insert(lines, string.format("| active%d_cooldown = %s", active_index, cd.cooldown))
                            local cd = format_stat_enhanced(item_name, prop, true)
            end
                            if cd then
            if cd.chargeup then
                                table.insert(lines, string.format("| active%d_cooldown = %s", active_index, cd))
                table.insert(lines, string.format("| active%d_chargeup = %s", active_index, cd.chargeup))
                            end
                        end
                        if prop == "AbilityChargeUpTime" then
                            local cu = format_stat_enhanced(item_name, prop, true)
                            if cu then
                                table.insert(lines, string.format("| active%d_chargeup = %s", active_index, cu))
                            end
                        end
                    end
                end
 
                active_index = active_index + 1
             end
             end
        end
    end


    ----------------------------------------------------------------------
             active_index = active_index + 1
    -- Global fallback for AbilityCooldown and AbilityChargeUpTime
    -- Attaches to the active section if one exists, otherwise innate
    ----------------------------------------------------------------------
    if not cooldown_found_in_sections and not chargeup_found_in_sections and item.AbilityCooldown then
        local cd = format_stat_enhanced(item_name, "AbilityCooldown", true)
        if cd then
            local has_active = false
             for _, section in ipairs(item.TooltipSections or {}) do
                if section.Type == "EArea_Active" then has_active = true; break end
            end
            if has_active then
                table.insert(lines, "| active1_cooldown = " .. cd)
            else
                table.insert(lines, "| passive1_cooldown = " .. cd)
            end
         end
         end
     end
     end


     if not chargeup_found_in_sections and item.AbilityChargeUpTime then
     ------------------------------------------------------------------
        local cu = format_stat_enhanced(item_name, "AbilityChargeUpTime", true)
        if cu then table.insert(lines, "| passive1_chargeup = " .. cu) end
    end
 
    ----------------------------------------------------------------------
     -- Components
     -- Components
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     for i = 1, 2 do
     for i = 1, 2 do
         local comp = ItemData.get_component_name { args = { item_name, i } }
         local comp = ItemData.get_component_name { args = { item_name, i } }
Line 897: Line 755:
     end
     end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Is Component Of (sorted by tier)
     -- Is Component Of (sorted by tier)
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     local parents = get_component_of_sorted(item_name)
     local parents = get_component_of_sorted(item_name)
     for i, key in ipairs(parents) do
     for i, key in ipairs(parents) do
         local parent_name = data[key] and data[key]["Name"] or ""
         local parent_name = data[key] and data[key].Name or ""
         if parent_name ~= "" then
         if parent_name ~= "" then
             table.insert(lines, string.format("| iscomponentof%d_name = %s", i, parent_name))
             table.insert(lines, string.format("| iscomponentof%d_name = %s", i, parent_name))
Line 908: Line 766:
     end
     end


     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     -- Sounds
     -- Sounds
     ----------------------------------------------------------------------
     ------------------------------------------------------------------
     for key, value in pairs(frame.args) do
     for key, value in pairs(frame.args) do
         local index = tostring(key):match("^sound(%d+)$")
         local index = tostring(key):match("^sound(%d+)$")
Line 918: Line 776:
     end
     end


    ----------------------------------------------------------------------
     table.insert(lines, "}}")
     table.insert(lines, "}}")
     return table.concat(lines, "\n")
     return table.concat(lines, "\n")
end
end
--------------------------------------------------------------------------------
-- Public interface
--------------------------------------------------------------------------------


function p.fill_tooltip(frame)
function p.fill_tooltip(frame)
     local output, debug = build_tooltip(frame)
     local output, debug = build_tooltip(frame)
     if debug == 1 or debug == 2 then
     if debug == 1 or debug == 2 then return output end
        return output
    end
     return mw.getCurrentFrame():preprocess(output)
     return mw.getCurrentFrame():preprocess(output)
end
end