Module:Sandbox/Constants: Difference between revisions

Removed the need for a modifier Sign
(Updated Sign check in getModifierDetails)
(Removed the need for a modifier Sign)
Line 908: Line 908:


--Turns a modifier name like 'increasedHPRegenFlat' into several pieces of data:
--Turns a modifier name like 'increasedHPRegenFlat' into several pieces of data:
--Base Name, Description, Sign, IsNegative, valueUnsigned and modifyValue
--Base Name, Description, IsNegative, and modifyValue
--ex. "HPRegenFlat", "+${value} Flat Hitpoints Regeneration", "+", false, false, "multiplyByNumberMultiplier"
--ex. "HPRegenFlat", "+${value} Flat Hitpoints Regeneration", false, "multiplyByNumberMultiplier"
function p.getModifierDetails(modifierName)
function p.getModifierDetails(modifierName)
local baseName = modifierName
local baseName = modifierName
local valueUnsigned = false
local modifier = GameData.rawData.modifierData[modifierName]
local modifier = GameData.rawData.modifierData[modifierName]


Line 921: Line 920:
if Shared.startsWith(modifierName, "increased") or Shared.startsWith(modifierName, "decreased") then
if Shared.startsWith(modifierName, "increased") or Shared.startsWith(modifierName, "decreased") then
baseName = string.sub(modifierName, 10)
baseName = string.sub(modifierName, 10)
end
--TODO: This won't work for ReflectDamage: "+0-${value} Reflect Damage" and "-0-${value} Reflect Damage"
local i, j = string.find(modifier.description, '${value}')
local sign = string.sub(modifier.description, i-1, i-1)
if sign ~= "-" and sign ~= "+" then
sign = "+"
valueUnsigned = true
end
end


return baseName, modifier.description, sign, modifier.isNegative, valueUnsigned, modifier.modifyValue
return baseName, modifier.description, modifier.isNegative, modifier.modifyValue
end
end


function p._getModifierText(modifier, value, doColor)
function p._getModifierText(modifier, value, doColor)
if doColor == nil then doColor = true end
if doColor == nil then doColor = true end
local modName, modText, sign, isNegative, valueUnsigned, modifyValue = p.getModifierDetails(modifier)
local modName, modText, isNegative, modifyValue = p.getModifierDetails(modifier)


if modName == nil then
if modName == nil then