Module:Sandbox/LVL: Difference between revisions

LVL (talk | contribs)
No edit summary
LVL (talk | contribs)
No edit summary
Line 1: Line 1:
local p = {};
local p = {}
local lang = require "Module:Lang"
local util_module = require("Module:Utilities")
local util_module = require "Module:Utilities"
local lang_codes_set = mw.loadJsonData("Data:LangCodes.json")
local data = mw.loadJsonData("Data:Sandbox.json")
local dictionary_module = require("Module:Dictionary")


-- A list of item properties that should have a '%' sign appended to their base value.
-- Overrides applied to searches by key. Designed to handle edge cases where
local percentage_properties = {
-- the expected key does not have a localization entry
AbilityLifestealPercentHero = true,
local KEY_OVERRIDES = {
AbilityLifestealPercentHeroPassive = true,
    MoveSlowPercent_label = 'MovementSlow_label',
ActiveReloadPercent = true,
    BonusHealthRegen_label = 'HealthRegen_label',
AirControlPercent = true,
    BarbedWireRadius_label = 'Radius_label',
AirMoveIncreasePercent = true,
    BarbedWireDamagePerMeter_label = 'DamagePerMeter_label',
AmmoReloadPercent = true,
    BuildUpDuration_label = 'BuildupDuration_label',
BaseAttackDamagePercent = true,
    TechArmorDamageReduction_label = 'TechArmorDamageReduction_Label',
BaseAttackDamagePercentAtMaxDuration = true,
    DamageAbsorb_label = 'DamageAbsorb_Label',
BaseAttackDamagePercentBonus = true,
    InvisRegen_label = 'InvisRegen_Label',
BonusAbilityDurationPercent = true,
    EvasionChance_label = 'EvasionChance_Label',
BonusAttackRangePercent = true,
    DelayBetweenShots_label = 'DelayBetweenShots_Label',
BonusBulletSpeedPercent = true,
BonusClipSizePercent = true,
BonusDamagePercent = true,
BonusFireRate = true,
BonusHeavyMeleeDamage = true,
BonusMeleeDamagePercent = true,
BonusSoulsPct = true,
BonusZoomPercent = true,
BuffMeleeDamageBoost = true,
BulletArmorReduction = true,
BulletDamageReflectedPct = true,
BulletLifestealPercent = true,
BulletProcDeflectionPercent = true,
BulletResist = true,
BulletResistReduction = true,
CooldownBetweenChargeReduction = true,
CooldownReduction = true,
CooldownReductionPctOnNonHeroes = true,
CritDamagePercent = true,
DamagePctVsNonHeroes = true,
DeathImmunityDamageReduction = true,
DeflectionPercent = true,
DotHealthPercent = true,
FireRateSlow = true,
GroundDashReductionPercent = true,
HealAmpCastPercent = true,
HealAmpReceivePenaltyPercent = true,
HealAmpRegenPenaltyPercent = true,
HealAmpRegenPercent = true,
HealLifePercentOutOfCombat = true,
HealPercentAmount = true,
HealPercentPerHeadshot = true,
ItemCooldownReduction = true,
LifestealHealPercent = true,
MagicIncreasePerStack = true,
MagicResistReduction = true,
MaxHealthDamage = true,
MaxHealthLossPercent = true,
MaxHealthPercentAsDPS = true,
MaxSlowPercent = true,
MeleeDistanceScale = true,
MeleeResistPercent = true,
MoveWhileShootingSpeedPenaltyReductionPercent = true,
MoveWhileZoomedSpeedPenaltyReductionPercent = true,
MovementSpeedSlow = true,
NonHeroHealPct = true,
NonHeroReductionPercent = true,
NonPlayerBonusWeaponPower = true,
NonPlayerBulletResist = true,
OutgoingDamagePenaltyPercent = true,
ParrySuccessHealPercentage = true,
PercentDamage = true,
ProcBaseAttackDamagePercent = true,
ProcBaseAttackDamagePercentAltFire = true,
ProcChance = true,
ReduceFootstepSound = true,
ReloadSpeedMultipler = true,
RicochetDamagePercent = true,
SelfModifier = true,
SlideScale = true,
SlowPercent = true,
SlowResistancePercent = true,
SpiritDamageReductionProc = true,
SpiritDamageReflectedPct = true,
StaminaCooldownReduction = true,
StatusResistancePercent = true,
TechArmorDamageReduction = true,
TechDamagePercent = true,
TechDamageReduction = true,
TechPowerPercent = true,
TechPowerReduction = true,
TechRadiusMultiplier = true,
TechRadiusMultiplierBuff = true,
TechRangeMultiplier = true,
TechRangeMultiplierBuff = true,
TechResist = true,
TechResistBelowThreshold = true,
}
}


---------------------------------------- Utility functions
function get_lang_file(lang_code)
 
     -- For testing purposes, always load the sandbox data regardless of language code.
-- Returns the table of a specific item.
    return mw.loadJsonData("Data:Sandbox/Lang.json")
-- Prioritizes active (non-disabled) items if multiple entries share the same name.
end
-- @function  get_json_item
-- @param      {string}
-- @return     {table}
local function get_json_item(name)
-- First, try to find an active item. This handles cases where a disabled item
-- with the same name exists in the data (e.g., old versions).
for _, v in pairs(data) do
if (v["Name"] == name and (v["IsDisabled"] == false or v["IsDisabled"] == nil)) then
return v -- Return the active item immediately
end
end


-- If no active item was found, fall back to finding any item with the name.
local function process_newlines(text)
-- This preserves functionality for items that are intentionally disabled.
    if not text or type(text) ~= "string" then return text end
for _, v in pairs(data) do
    -- Replace "n with newline character
if (v["Name"] == name) then
    return text:gsub('"n', '<br/>')
return v
end
end
return nil -- Return nil if no item was found at all
end
end


-- Returns an array of item tables that have the same properties
local function process_html_tags(text, frame)
-- @function  get_similar_items
    if not text or type(text) ~= "string" then return text end
-- @param      {string}
   
-- @return     {array of tables}
    local replacements = {
local function get_similar_items(property)
    SpiritIcon = {icon='{{Icon/NoColor|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', link='Spirit Damage'},
local similarItems = {}
    tech_damage = {icon='{{Icon/NoColor|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', link='Spirit Damage'},
for _, v in pairs(data) do
    SpiritDamage = {icon='{{Icon/NoColor|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8', link='Spirit Damage'},
if (v[property] ~= nil) then
    StatDesc_TechPower = {icon='{{Icon/NoColor|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8', link='Spirit Damage'},
table.insert(similarItems, v)
    SpiritResist = {icon='{{Icon/Purple|[[File:Spirit_Armor.png|link=Damage_Resistance|20px]]}}', label_color='#bc8ee8', link='Damage_Resistance'},
end
    FireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7', link='Fire Rate'},
end
    fire_rate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7', link='Fire Rate'},
return similarItems
    ReducedFireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7', link='Fire Rate'},
end
    MeleeDamage = {icon='{{Icon/Brown|[[File:Melee damage.png|link=Melee Damage|20px]]}}', label_color='#ec981a', link='Melee Damage'},
    WeaponDamage = {icon='{{Icon/Brown|[[File:Damage.png|link=Weapon Damage|20px]]}}', label_color='#ec981a', link='Weapon Damage'},
    damage = {icon='{{Icon/Brown|[[File:Damage.png|link=Weapon Damage|20px]]}}', label_color='#ec981a', link='Weapon Damage'},
    bullet_damage = {icon='{{Icon/Brown|[[File:Damage.png|link=Weapon Damage|20px]]}}', label_color='#ec981a', link='Weapon Damage'},
    BulletResist = {icon='{{Icon/Brown|[[File:Bullet_Armor.png|link=Damage_Resistance|20px]]}}', label_color='#ec981a', link='Damage_Resistance'},
    CombatBarrier = {icon='{{Icon/White|[[File:Bullet_Armor.png|link=Damage_Resistance|20px]]}}', label_color='#ffefd7', link='Barrier'},
    BonusWeaponDamage = {icon='{{Icon/Brown|[[File:Damage.png|link=Weapon Damage|20px]]}}', label_color='#ec981a', link='Weapon Damage'},
    MoveSpeed = {icon='{{Icon/White|[[File:Move_speed.png|link=Move speed|20px]]}}', label_color='#ffefd7', link='Move speed'},
    BonusSpiritDamage = {icon='{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8', link='Spirit Damage'},
    BonusFireRate = {icon='{{Icon/White|[[File:Fire_Rate.png|link=Fire Rate|20px]]}}', label_color='#ffefd7', link='Fire Rate'},
    Heal = {icon='{{Icon/Green|[[File:Health_regen.png|link=Health_Regen|20px]]}}', label_color='#13f278', link='Health_Regen'},
    BonusMoveSpeed = {icon='{{Icon/White|[[File:Move_speed.png|link=Move speed|20px]]}}', label_color='#ffefd7', link='Move speed'},
    move_speed = {icon='{{Icon/White|[[File:Move_speed.png|link=Move speed|20px]]}}', label_color='#ffefd7', link='Move speed'},
    BonusSprintSpeed = {icon='{{Icon/Green|[[File:Move_speed.png|link=Sprint speed|20px]]}}', label_color='#ffefd7', link='Sprint speed'},
    Spirit = {icon='{{Icon/NoColor|[[File:Spirit_icon.png|link=Spirit Power|20px]]}}', label_color='#bc8ee8', link='Spirit Power'},
    Stun = {icon='{{Icon/White|[[File:Status_Stun.png|link=Stun|20px]]}}', link='Stun'},
    SpiritDPS = {icon='{{Icon/NoColor|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}', label_color='#bc8ee8', link='Spirit Damage'},
    Healing = {icon='{{Icon/Green|[[File:Health_regen.png|link=Healing|20px]]}}', label_color='#13f278', link='Healing'},
    Regen = {icon='{{Icon/Green|[[File:Health_regen.png|link=Health_Regen|20px]]}}', label_color='#13f278', link='Health_Regen'},
    MaxHealth = {icon='{{Icon/Green|[[File:Healing.png|link=Health|20px]]}}', label_color='#13f278', link='Health'},
    Slow = {icon='{{Icon/White|[[File:MoveSlow.png|link=Movement_Slow|20px]]}}', label_color='#ffefd7', link='Movement_Slow'},
    slow = {icon='{{Icon/White|[[File:MoveSlow.png|link=Movement_Slow|20px]]}}', label_color='#ffefd7', link='Movement_Slow'},
    SlowResistance = {icon='{{Icon/White|[[File:MoveSlow.png|link=Movement_Slow#Movement_Slow_Resist|20px]]}}', label_color='#ffefd7', link='Movement_Slow#Movement_Slow_Resist'},
        Immobilize = {icon='{{Icon/White|[[File:Immobilize.png|link=Status Effects#Immobilized|20px]]}}', label_color='#ffefd7', link='Status Effects#Immobilized'},
        cooldown = {icon='{{Icon/White|[[File:AttributeIconTechDuration.png|link=Ability Cooldown|20px]]}}', label_color='#ffefd7', link='Ability Cooldown'},
        stun = {icon='{{Icon/White|[[File:Stun.png|link=|20px]]}}', label_color='#ffefd7', link=''},
        invisible = {icon='{{Icon/White|[[File:Invisible.png|link=|20px]]}}', label_color='#ffefd7', link=''},
        cast = {icon='{{Icon/White|[[File:Cast.png|link=|20px]]}}', label_color='#ffefd7', link=''},
        silence = {icon='{{Icon/White|[[File:Silence.png|link=|20px]]}}', label_color='#ffefd7', link=''},
        Silence = {icon='{{Icon/Purple|[[File:Silence.png|link=Silence|20px]]}}', label_color='#bc8ee8', link='Silence'},
        revealed = {icon='{{Icon/White|[[File:Revealed.png|link=|20px]]}}', label_color='#ffefd7', link=''},
        bullet_armor_up = {icon='{{Icon/White|[[File:Barrier.png|link=Barrier|20px]]}}', label_color='#ffefd7', link='Barrier'},
        tech_armor_up = {icon='{{Icon/White|[[File:Barrier.png|link=Barrier|20px]]}}', label_color='#ffefd7', link='Barrier'},
        Pulling =  {icon='{{Icon/NoColor|[[File:Displacement.png|link=|20px]]}}', label_color='#ffefd7', link='Status_Effects'},
    Pull =      {icon='{{Icon/NoColor|[[File:Displacement.png|link=|20px]]}}', label_color='#ffefd7', link='Status_Effects'},
    Pulls =    {icon='{{Icon/NoColor|[[File:Displacement.png|link=|20px]]}}', label_color='#ffefd7', link='Status_Effects'},
    KnockBack = {icon='{{Icon/NoColor|[[File:Displacement.png|link=|20px]]}}', label_color='#ffefd7', link='Status_Effects'},
    KnockUp =  {icon='{{Icon/NoColor|[[File:Displacement.png|link=|20px]]}}', label_color='#ffefd7', link='Status_Effects'},
}
 
    -- Process HTML spans
    text = text:gsub('<span class="highlight">(.-)</span>', "<span style= font-weight:bold>%1</span>")
    text = text:gsub('<span class="highlight_spirit">(.-)</span>', '<span style="font-weight:bold; color:#bc8ee8">%1</span>')
    text = text:gsub('<span class="diminish">(.-)</span>', '<span style="font-style: italic;color:#C0C0C0">%1</span>')
    text = text:gsub('<span class=".-">(.-)</span>', '%1')
     text = text:gsub('<Panel class=\"AbilityPropertyIcon StatDesc_TechPower\">', '{{Icon/Purple|[[File:AttributeIconTechShieldHealth.png|link=Spirit Damage|12px]]}}')
    text = text:gsub('</Panel>', '')
   
    -- Process panel tags
text = text:gsub('<Panel class=\"AbilityPropertyIcon prop_(.-)\">', function(key)
    local replacement = replacements[key]
    if replacement then
        local label_color = replacement.label_color or 'inherit'
        local icon = replacement.icon or ''
        local link = replacement.link or ''
        -- pre-process string, then check to omit link if the string is empty
        local translated = frame:preprocess('{{#invoke:Lang|get_string|InlineAttribute_' .. key .. '}}')
       
        if translated == '' then
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s</span>', label_color, icon)
        else
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s [[%s|%s]]</span>',
                label_color,
                icon,
                link,
                translated)
        end
    else
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing attribute definition - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
    end
end)
   
    -- Process citadel_inline_attribute tags
text = text:gsub("{g:citadel_inline_attribute:'(.-)'}", function(key)
    local replacement = replacements[key]
    if replacement then
        local label_color = replacement.label_color or 'inherit'
        local icon = replacement.icon or ''
        local link = replacement.link or ''
        -- pre-process string, then check to omit link if the string is empty
        local translated = frame:preprocess('{{#invoke:Lang|get_string|InlineAttribute_' .. key .. '}}')
       
        if translated == '' then
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s</span>', label_color, icon)
        else
            return string.format('<span class="no-blue-link" style="text-wrap:nowrap; font-weight:bold; color:%s;">%s [[%s|%s]]</span>',
                label_color,
                icon,
                link,
                translated)
        end
    else
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing attribute definition - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
    end
end)


-- Adds commas delimiter to the thousands place
    KEYBINDS = {
local function Format(amount)
    Attack = '{{Mouse|1}}',
local contentLanguage = mw.language.getContentLanguage()
    ADS = '{{Mouse|2}}',
    local formatted = amount
    AltCast = '{{Mouse|3}}',
    if(type(formatted) ~= "number") then return "<span style=\"color:red;\">Cannot format non-number value.</span>" end
    Reload = 'R',
    return contentLanguage:formatNum(tonumber(formatted))
    Roll = 'Shift',
end
    Mantle = 'Space',
    Crouch = 'Ctrl',
    AbilityMelee = 'Melee',
    Ability1 = '1',
    Ability2 = '2',
    Ability3 = '3',
    Ability4 = '4',
    MoveDown = 'Down',
    MoveForward = 'Forward',
    }
   
    -- Process citadel_binding/citadel_keybind tags to replace with keybind strings/templates
text = text:gsub("{g:citadel_binding:'(.-)'}", function(key)
    local replacement = KEYBINDS[key]
    if replacement then
        return replacement
    else
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing keybind - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
    end
end)
text = text:gsub("{g:citadel_keybind:'(.-)'}", function(key)
local replacement = KEYBINDS[key]
    if replacement then
        return replacement
    else
        return '<span style="color:red;font-weight:bold;border-bottom:1px dotted red;" title="Missing keybind - Add \''..key..'\' to local replacements in [Module:Lang]">['..key..']</span>'
    end
end)


--- Get cost of an item
return frame:preprocess(text)
-- @function  get_cost
-- @param      {string}
-- @return    {number}
local function get_cost(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
return tonumber(item["Cost"])
end
end


--- Get type/slot/category of an item
-- @function  get_type
-- @param      {string} item_name
-- @param      {boolean} raw (optional)
-- @return    {string}
local function get_type(item_name, raw)
local item = get_json_item(item_name)
if not item then
return "<span style=\"color:red;\">Item Not Found.</span>"
end


local slot = item["Slot"]
function p.get_string(key, lang_code_override, fallback_str, remove_var_index, item_name)
if not slot then return nil end
    -- Get frame object (either passed directly or via first argument)
    local frame
    if type(key) == "table" and key.args then
        frame = key
        key = frame.args[1]
        lang_code_override = frame.args["lang_code_override"]
        fallback_str = frame.args["fallback_str"]
        remove_var_index = frame.args["remove_var_index"]
        item_name = frame.args["item_name"]
    else
        frame = mw.getCurrentFrame()
    end


local key_map = {
    -- Determine lang_code if not overridden
Weapon = 'CitadelCategoryWeapon',
    local lang_code = lang_code_override
Armor = 'CitadelCategoryArmor',
    if (lang_code == '' or lang_code == nil) then
Tech = 'CitadelCategoryTech'
        lang_code = p.get_lang_code()
}
    end


local key = key_map[slot]
    -- Retrieve lang data
if not key then return nil end
    local data = get_lang_file(lang_code)
    if (data == nil) then
        return string.format("Lang code '%s' does not have a json file", lang_code)   
    end
   
    -- Localize
    local label = data[KEY_OVERRIDES[key] or key]


if raw then
-- Some labels use key with "_postvalue_label" instead, so check this if previous search failed
return lang.get_string(key, "en")
if label == nil and key ~= nil and key:sub(-6) == '_label' then
else
    local postvalue_key = key:sub(1, -7) .. '_postvalue_label'
return lang.get_string(key)
    label = data[postvalue_key]
end
end
end
    if (label == nil) then
        -- Apply fallback (without HTML processing for fallback)
        local fallback_tooltip = frame:expandTemplate{title = "MissingValveTranslationTooltip"}
        local fallback
        if (fallback_str == 'en') then
            fallback = p.get_string(key, 'en', key .. fallback_tooltip, remove_var_index, item_name)
        elseif fallback_str == 'dictionary' then
            return dictionary_module.translate(key, lang_code_override)
        elseif fallback_str ~= nil then
            fallback = fallback_str
        else
            return ''
        end
        return fallback .. fallback_tooltip
    end
   
    -- Always retrieve the last parameter if string contains "|"
    if type(label) == "string" and label:find("|") then
        local parts = mw.text.split(label, "|")
        label = parts[#parts]
    end
   
  -- Remove hashtags
  if type(label) == "string" and label:find("#") then
        local parts = mw.text.split(label, "#")
        label = parts[#parts]
    end


 
    -- Apply remove_var
---------------------------------------- Invocable functions
    if (remove_var_index ~= nil) then
 
        label = util_module.remove_var(label, remove_var_index)
--- {{#invoke:ItemData|get_cost|ITEM_NAME}} access point
    end
p.get_cost = function(frame)
   
local item_name = frame.args[1]
    -- Process variables if item_name is provided
return Format(get_cost(item_name))
    if item_name and item_name ~= '' then
        local item_data_module = require('Module:ItemData')
        label = label:gsub("{s:([^}]+)}", function(variable_name)
            -- Get the value from ItemData
            local value = item_data_module.get_prop({args = {item_name, variable_name}})
           
            -- If value exists, remove non-number symbols (but keep + and -)
            if value then
                value = value:gsub("[^0-9+-]", "")
                -- Return empty string if nothing left, otherwise return the filtered value
                return value ~= "" and value or variable_name
            else
                return variable_name -- Fallback to variable name if value not found
            end
        end)
    end
   
    -- Process HTML and return as "raw" HTML
    label = process_newlines(label)
    label = process_html_tags(label, frame)
    -- Create HTML object for safe output
    local html = mw.html.create()
    html:wikitext(label)
    return tostring(html)
end
end


-- Module access point
-- Search for a localized string using its English label
function p._get_cost(a)
p.search_string = function(frame)
a = tostring(a) or '0'
    local label = frame.args[1]
return get_cost(a)
    local lang_code_override = frame.args[2]
end


-- {{#invoke:ItemData|get_type|ITEM_NAME}} access point
    local result = p._search_string(label, lang_code_override)
p.get_type = function(frame)
    result = process_newlines(result)
local item_name = frame.args[1]
    return result
-- Accept 'raw' as string "true" (case sensitive)
local raw = frame.args['raw'] == 'true'
return get_type(item_name, raw)
end
end


-- Module access point
-- search_string, but for internal use by other modules
function p._get_type(a)
p._search_string = function(label, lang_code_override)
a = tostring(a) or ""
    lang_code = lang_code_override
return get_type(a)
    if (lang_code == '' or lang_code == nil) then
end
        lang_code = p.get_lang_code()
    end


--{{#invoke:ItemData|is_active|ITEM_NAME}}--
    -- Load the language files
p.is_active = function(frame)
    local data_en = get_lang_file('en') -- English data
local item_name = frame.args[1]
    local data_lang = get_lang_file(lang_code) -- Target language data
local item = get_json_item(item_name)
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
if (item["Activation"] == "Passive") then
return false
else
return true
end
end


--{{#invoke:ItemData|get_prop|ITEM_NAME|PROPERTY}}--
    if (data_lang == nil) then
--check Data:ItemData.json for properties
        error("Lang code '%s' does not have a json file", lang_code)  
p.get_prop = function(frame)
    end
local item_name = frame.args[1]
   
local property = frame.args[2]
    -- Search for the key in the English data
local item = get_json_item(item_name)
    local key = nil
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
    for k, v in pairs(data_en) do
 
        if v == label then
local prop_value = item[property]
            key = -- Find the key corresponding to the label
if (prop_value == nil) then return nil end
            break
 
        end
local display_value
    end
local scaling_str = "" -- Default to an empty string for non-scaled values
 
-- Determine the base value and scaling string (if any)
if(type(prop_value) == "table") then
if prop_value["Value"] ~= nil and prop_value["Scale"] ~= nil and prop_value["Scale"]["Value"] ~= nil and prop_value["Scale"]["Type"] ~= nil then
-- This is a structured attribute with scaling data
display_value = tostring(prop_value["Value"])
local scale_val = tonumber(prop_value["Scale"]["Value"])
if scale_val ~= 0 then
local scale_type = prop_value["Scale"]["Type"]
local rounded_scale_val = util_module.round_to_sig_fig(scale_val, 2)
local template_title
if scale_type == "power_increase" then
template_title = "Template:Boon"
else
template_title = "Template:Ss"
end
local template_args = { [1] = rounded_scale_val }
-- Add a space before the scaling template for proper separation
scaling_str = " " .. mw.getCurrentFrame():expandTemplate{ title = template_title, args = template_args }
end
else
-- This is a simple list (e.g., TargetTypes), handle and return it directly
local tableValues = {}
for _, v in pairs(prop_value) do
table.insert(tableValues, tostring(v))
end
return table.concat(tableValues, ", ")
end
else
-- This is a simple, non-table property
display_value = tostring(prop_value)
end
-- Assemble the final string, adding the '%' sign if necessary
if percentage_properties[property] == true then
return display_value .. "%" .. scaling_str
else
return display_value .. scaling_str
end
end


p.get_component_name = function(frame)
    -- Default to input label if localized string is not found
local item_name = frame.args[1]
    if (key == nil) then
local item = get_json_item(item_name)
        return label
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
    end
    if (data_lang[key] == nil) then
local components = item['Components']
        return label
--return empty string if no component found
    end
if(components == nil) then return nil end
local component_key = components[1]
local component = data[component_key]
if (component == nil) then return nil end
return component['Name']
end


-- {{Items count}} access point
    return data_lang[key]
function p.get_headcount()
local iter = 0
local tbl = get_similar_items("IsDisabled")
for _, v in ipairs(tbl) do
if (v["IsDisabled"] == false and v["Name"] ~= nil) then
iter = iter + 1
end
end
return iter
end
end


p.get_lang_code = function()
    local title = mw.title.getCurrentTitle()
    local lang_code = title.fullText:match(".*/(.*)$")
      
      
-- Gets the codename (the key in the JSON data) for a given item's display name.
    if lang_code == nil or lang_codes_set[lang_code] == nil then
-- Prioritizes active items to handle cases where disabled duplicates exist.
        return 'en'   
p.get_codename = function(frame)
    end
local name = frame.args[1]
       
    return lang_code
-- First, try to find an active item.
for k, v in pairs(data) do
if (v["Name"] == name and (v["IsDisabled"] == false or v["IsDisabled"] == nil)) then
return k -- Return the codename of the active item
end
end
-- If no active item was found, fall back to finding any item with the name.
for k, v in pairs(data) do
if (v["Name"] == name) then
return k
end
end
return nil -- Return nil if no item was found at all
end
end
 


return p
return p