Module:Sandbox: Difference between revisionsGive feedback
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 | 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 | -- 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 | -- Process parent items | ||
local parent_items_text = "" | local parent_items_text = "" | ||
local parent_items = {} | local parent_items = {} | ||
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 | ||
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 | local skip_stats = { | ||
Name = true, Description = true, Cost = true, Tier = true, | |||
Activation = true, Slot = true, Components = true, | |||
TargetTypes = true, ShopFilters = true, IsDisabled = true, | |||
AbilityCastDelay = true, AbilityChannelTime = true, | |||
AbilityPostCastDuration = true, AbilityCharges = true, | |||
AbilityCooldownBetweenCharge = true, ChannelMoveSpeed = true, | |||
AbilityResourceCost = true | |||
} | } | ||
for stat, | for stat, value in pairs(item) do | ||
if not skip_stats[stat] and value ~= nil and value ~= "0" and value ~= 0 then | |||
local num_value = toNumber(value) | |||
local | local formatted = formatStat(stat, num_value) | ||
if formatted then | |||
table.insert(stats, formatted) | |||
end | |||
if | |||
end | end | ||
end | end | ||
-- Sort stats alphabetically for consistent display | |||
table.sort(stats) | |||
-- Calculate shop bonus | -- Calculate shop bonus | ||