Module:ItemData: Difference between revisionsGive feedback
Updated module to support new scaling format |
Added percentage formatting for stats and removed old scalar functions as they're not needed. |
||
| Line 3: | Line 3: | ||
local util_module = require "Module:Utilities" | local util_module = require "Module:Utilities" | ||
local data = mw.loadJsonData("Data:ItemData.json") | local data = mw.loadJsonData("Data:ItemData.json") | ||
-- A list of item properties that should have a '%' sign appended to their base value. | |||
local percentage_properties = { | |||
AbilityLifestealPercentHero = true, | |||
BaseAttackDamagePercent = true, | |||
BonusAbilityDurationPercent = true, | |||
BonusBulletSpeedPercent = true, | |||
BonusClipSizePercent = true, | |||
BonusFireRate = true, | |||
BonusMeleeDamagePercent = true, | |||
BulletArmorReduction = true, | |||
BulletLifestealPercent = true, | |||
BulletResist = true, | |||
CooldownReduction = true, | |||
CooldownReductionPctOnOthers = 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, | |||
MagicIncreasePerStack = true, | |||
MagicResistReduction = true, | |||
MaxSlowPercent = true, | |||
MaxHealthLossPercent = true, | |||
MeleeDistanceScale = true, | |||
MeleeResistPercent = true, | |||
MoveWhileShootingSpeedPenaltyReductionPercent = true, | |||
MoveWhileZoomedSpeedPenaltyReductionPercent = true, | |||
NonHeroHealPct = true, | |||
NonPlayerBonusWeaponPower = true, | |||
NonPlayerBulletResist = true, | |||
OutgoingDamagePenaltyPercent = true, | |||
PercentDamage = true, | |||
ProcChance = true, | |||
RicochetDamagePercent = true, | |||
SlideScale = true, | |||
SlowPercent = true, | |||
SlowResistancePercent = true, | |||
StatusResistancePercent = true, | |||
TechArmorDamageReduction = true, | |||
TechPowerPercent = true, | |||
TechPowerReduction = true, | |||
TechRadiusMultiplier = true, | |||
TechRangeMultiplier = true, | |||
TechResist = true, | |||
TechResistBelowThreshold = true | |||
} | |||
---------------------------------------- Utility functions | ---------------------------------------- Utility functions | ||
| Line 51: | Line 108: | ||
end | end | ||
--- Get type/slot/category of an item | --- Get type/slot/category of an item | ||
-- @function get_type | -- @function get_type | ||
| Line 138: | Line 191: | ||
if (prop_value == nil) then return nil end | if (prop_value == nil) then return nil end | ||
-- | local display_value | ||
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(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 | 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"]) | 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 | end | ||
else | else | ||
-- | -- This is a simple list (e.g., TargetTypes), handle and return it directly | ||
local tableValues = {} | local tableValues = {} | ||
for _, v in pairs(prop_value) do | for _, v in pairs(prop_value) do | ||
| Line 177: | Line 224: | ||
return table.concat(tableValues, ", ") | return table.concat(tableValues, ", ") | ||
end | end | ||
else | |||
-- This is a simple, non-table property | |||
display_value = tostring(prop_value) | |||
end | 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 | ||
end | end | ||