Module:Sandbox: Difference between revisions

Jump to navigation Jump to search
No edit summary
No edit summary
Line 53: Line 53:
local function formatNum(amount)
local function formatNum(amount)
     return lang:formatNum(toNumber(amount))
     return lang:formatNum(toNumber(amount))
end
-- Smart stat display formatter
local function formatStat(stat, value)
    local icon_map = {
        TechPower = "Spirit icon.png",
        WeaponPower = "Weapon Icon.png",
        TechResist = "Spirit Resist Icon.png",
        BulletResist = "Bullet Resist Icon.png",
        AbilityCooldown = "Cooldown Icon.png"
    }
   
    local suffix_map = {
        Percent = "%",
        Speed = "m/s",
        Range = "m",
        Duration = "s",
        Cooldown = "s",
        Health = " HP",
        Stacks = " stacks",
        Damage = " Damage",
        FireRate = " Fire Rate",
        Lifesteal = "% Lifesteal"
    }
   
    -- Special cases with custom formatting
    if stat == "AmmoPerSoul" then
        return string.format("• %d ammo per Soul", value)
    elseif stat == "SpiritPowerPerSoul" then
        return string.format("• +%d Spirit Power per Soul", value)
    elseif stat == "MaxStacks" then
        return string.format("• Max %d stacks", value)
    end
   
    -- Automatic formatting based on stat name
    local display = "• "
    local icon = icon_map[stat]
    local base_stat = stat:gsub("Bonus", ""):gsub("Percent", "")
   
    -- Add value
    display = display .. tostring(value)
   
    -- Add icon if available
    if icon then
        display = display .. " [[File:" .. icon .. "|20px]]"
    end
   
    -- Add appropriate suffix
    for pattern, suffix in pairs(suffix_map) do
        if stat:find(pattern) then
            return display .. suffix
        end
    end
   
    -- Default case - show stat name if no special formatting
    return display .. " " .. base_stat
end
end


Line 58: Line 114:
p.generate_infobox = function(frame)
p.generate_infobox = function(frame)
     local item_name = frame.args[1]
     local item_name = frame.args[1]
     local manual_component = frame.args.component -- Manual override for "Is component of"
     local manual_component = frame.args.component
      
      
     if not item_name or item_name == "" then
     if not item_name or item_name == "" then
Line 88: Line 144:
     local color = colors[item_type] or colors.Weapon
     local color = colors[item_type] or colors.Weapon


     -- Process components (what this item is made of)
     -- Process components
     local components_text = ""
     local components_text = ""
     if item.Components and type(item.Components) == "table" then
     if item.Components and type(item.Components) == "table" then
Line 109: Line 165:
     end
     end


     -- Process parent items (what this item is used in)
     -- Process parent items
     local parent_items_text = ""
     local parent_items_text = ""
     local parent_items = {}
     local parent_items = {}
      
      
    -- Check for manual override first
     if manual_component and manual_component ~= "" then
     if manual_component and manual_component ~= "" then
         table.insert(parent_items, manual_component)
         table.insert(parent_items, manual_component)
     else
     else
        -- Otherwise look up automatically
         parent_items = get_parent_items(item.Name)
         parent_items = get_parent_items(item.Name)
     end
     end
Line 135: Line 189:
     end
     end


     -- Process stats
     -- Process ALL stats dynamically
     local stats = {}
     local stats = {}
     local stat_config = {
     local skip_stats = {
         TechPower = {icon = "Spirit icon.png", suffix = "Spirit Power"},
         Name = true, Description = true, Cost = true, Tier = true,
        WeaponPower = {icon = "Weapon Icon.png", suffix = "Weapon Damage"},
         Activation = true, Slot = true, Components = true,
         TechResist = {icon = "Spirit Resist Icon.png", suffix = "Tech Resist"},
         TargetTypes = true, ShopFilters = true, IsDisabled = true,
        BulletResist = {icon = "Bullet Resist Icon.png", suffix = "Bullet Resist"},
         AbilityCastDelay = true, AbilityChannelTime = true,
         AbilityCooldown = {icon = "Cooldown Icon.png", suffix = "s Cooldown"},
         AbilityPostCastDuration = true, AbilityCharges = true,
        AbilityCastRange = {suffix = "m Cast Range"},
         AbilityCooldownBetweenCharge = true, ChannelMoveSpeed = true,
         AbilityUnitTargetLimit = {prefix = "Targets: "},
         AbilityResourceCost = true
        CooldownBetweenChargeReduction = {suffix = "% Charge Cooldown Reduction"},
         BonusAbilityCharges = {prefix = "+", suffix = " Bonus Charges"},
         CooldownReductionOnChargedAbilities = {suffix = "% Charged Ability Cooldown Reduction"},
         BaseAttackDamagePercent = {suffix = "% Base Attack Damage"}
     }
     }
 
   
     for stat, config in pairs(stat_config) do
     for stat, value in pairs(item) do
         local value = item[stat]
         if not skip_stats[stat] and value ~= nil and value ~= "0" and value ~= 0 then
        if value and value ~= "0" and value ~= 0 then
             local num_value = toNumber(value)
             local text = "• "
             local formatted = formatStat(stat, num_value)
            if config.prefix then text = text .. config.prefix end
             if formatted then
            text = text .. tostring(value)
                table.insert(stats, formatted)
             if config.icon then text = text .. " [[File:" .. config.icon .. "|20px]]" end
            end
             if config.suffix then text = text .. config.suffix end
            table.insert(stats, text)
         end
         end
     end
     end
   
    -- Sort stats alphabetically for consistent display
    table.sort(stats)


     -- Calculate shop bonus
     -- Calculate shop bonus