- added tons of divide-by-zero protection all over the place

- general cleanup of values passed to UpdateBar
This commit is contained in:
Parnic
2009-04-18 21:07:42 +00:00
parent f11192bfd1
commit 10af4566d6
16 changed files with 24 additions and 19 deletions

View File

@ -697,6 +697,10 @@ function IceBarElement.prototype:SetScale(texture, scale)
self.CurrScale = IceHUD:Clamp(self:LerpScale(scale), 0, 1)
if not self.currScale or self.currScale == (1/0) or self.currScale == (0/0) then
self.currScale = 0
end
if oldScale ~= self.CurrScale then
if (self.moduleSettings.side == IceCore.Side.Left) then
texture:SetTexCoord(1, 0, 1-self.CurrScale, 1)

View File

@ -135,10 +135,10 @@ function IceCastBar.prototype:OnUpdate()
-- handle casting and channeling
if (self.action == IceCastBar.Actions.Cast or self.action == IceCastBar.Actions.Channel) then
local remainingTime = self.actionStartTime + self.actionDuration - time
local scale = 1 - (remainingTime / self.actionDuration)
local scale = 1 - (self.actionDuration > 0 and remainingTime / self.actionDuration or 0)
if (self.action == IceCastBar.Actions.Channel) then
scale = remainingTime / self.actionDuration
scale = self.actionDuration > 0 and remainingTime / self.actionDuration or 0
end
if (remainingTime < 0) then

View File

@ -203,11 +203,11 @@ function IceUnitBar.prototype:Update()
self.health = UnitHealth(self.unit)
self.maxHealth = UnitHealthMax(self.unit)
self.healthPercentage = self.health/self.maxHealth
self.healthPercentage = self.maxHealth > 0 and (self.health/self.maxHealth) or 0
self.mana = UnitMana(self.unit)
self.maxMana = UnitManaMax(self.unit)
self.manaPercentage = self.mana/self.maxMana
self.manaPercentage = self.maxMana > 0 and (self.mana/self.maxMana) or 0
_, self.unitClass = UnitClass(self.unit)

View File

@ -278,7 +278,7 @@ function IceCustomBar.prototype:UpdateCustomBar(unit, fromUpdate)
remaining = self.auraEndTime - now
end
self:UpdateBar(remaining / self.auraDuration, "undef")
self:UpdateBar(self.auraDuration > 0 and remaining / self.auraDuration or 0, "undef")
else
self:UpdateBar(0, "undef")
self:Show(false)

View File

@ -59,7 +59,7 @@ function DruidMana.prototype:Update()
self:Show(true)
end
self:UpdateBar(self.druidMana / self.druidManaMax, "DruidMana")
self:UpdateBar(self.druidManaMax > 0 and self.druidMana / self.druidManaMax or 0, "DruidMana")
end

View File

@ -368,7 +368,7 @@ function FocusHealth.prototype:Update(unit)
self.color = "Tapped"
end
self:UpdateBar(self.health/self.maxHealth, self.color)
self:UpdateBar(self.healthPercentage, self.color)
if not IceHUD.IceCore:ShouldUseDogTags() then
self:SetBottomText1(math.floor(self.healthPercentage * 100))

View File

@ -83,7 +83,7 @@ function FocusMana.prototype:Update(unit)
color = "Tapped"
end
self:UpdateBar(self.mana/self.maxMana, color)
self:UpdateBar(self.manaPercentage, color)
if not IceHUD.IceCore:ShouldUseDogTags() then
self:SetBottomText1(math.floor(self.manaPercentage * 100))

View File

@ -161,7 +161,7 @@ function GlobalCoolDown.prototype:UpdateGlobalCoolDown()
self:Show(false)
else
self:UpdateBar(1 - (remaining / self.duration), "GlobalCoolDown", 0.8)
self:UpdateBar(1 - (self.duration > 0 and remaining / self.duration or 0), "GlobalCoolDown", 0.8)
end
else
self:Show(false)

View File

@ -191,9 +191,9 @@ function HungerForBlood.prototype:UpdateHungerForBlood(unit, fromUpdate)
remaining = hfbEndTime - now
end
if (hfbBuffCount ~= nil and hfbBuffCount > 2) then
self:UpdateBar(remaining / hfbDuration, "HungerForBloodMax")
self:UpdateBar(hfbDuration > 0 and remaining / hfbDuration or 0, "HungerForBloodMax")
else
self:UpdateBar(remaining / hfbDuration, "HungerForBlood")
self:UpdateBar(hfbDuration > 0 and remaining / hfbDuration or 0, "HungerForBlood")
end
formatString = self.moduleSettings.upperText or ''

View File

@ -73,7 +73,7 @@ function MirrorBar.prototype:OnUpdate(elapsed)
self.value = self.value + (self.timerScale * elapsed * 1000)
scale = self.value / self.maxValue
scale = self.maxValue > 0 and self.value / self.maxValue or 0
if (scale < 0) then -- lag compensation
scale = 0

View File

@ -110,7 +110,7 @@ function PetHealth.prototype:Update(unit)
end
if (self.maxHealth > 0) then
self:UpdateBar(self.health/self.maxHealth, color)
self:UpdateBar(self.healthPercentage, color)
end
if not IceHUD.IceCore:ShouldUseDogTags() then

View File

@ -174,7 +174,7 @@ function PetMana.prototype:Update(unit)
end
if self.maxMana > 0 then
self:UpdateBar(self.mana/self.maxMana, color)
self:UpdateBar(self.manaPercentage, color)
end
if not IceHUD.IceCore:ShouldUseDogTags() then

View File

@ -891,7 +891,7 @@ function PlayerHealth.prototype:Update(unit)
textColor = "Text"
end
self:UpdateBar(self.health/self.maxHealth, color)
self:UpdateBar(self.healthPercentage, color)
-- sadly, animation uses bar-local variables so we can't use the animation for 2 bar textures on the same bar element
if self.moduleSettings.showIncomingHeals and self.healFrame and self.healFrame.bar and incomingHealAmt then

View File

@ -225,7 +225,8 @@ function SliceAndDice.prototype:UpdateSliceAndDice(unit, fromUpdate)
if not remaining then
remaining = sndEndTime - now
end
self:UpdateBar(remaining / (self.moduleSettings.showAsPercentOfMax and CurrMaxSnDDuration or sndDuration), "SliceAndDice")
local denominator = (self.moduleSettings.showAsPercentOfMax and CurrMaxSnDDuration or sndDuration)
self:UpdateBar(denominator > 0 and remaining / denominator or 0, "SliceAndDice")
formatString = self.moduleSettings.upperText or ''
else

View File

@ -293,8 +293,8 @@ function TargetCC.prototype:UpdateTargetDebuffs(unit, isUpdate)
if (name ~= nil) then
self:Show(true)
if (duration ~= nil) then
self:UpdateBar(remaining / duration, "CC:" .. self.debuffList[name])
if (duration ~= nil and duration > 0) then
self:UpdateBar(duration > 0 and remaining / duration or 0, "CC:" .. self.debuffList[name])
self:SetBottomText2(floor(remaining * 10) / 10)
else
self:UpdateBar(0, "CC:" .. self.debuffList[name])

View File

@ -678,7 +678,7 @@ function IceTargetHealth.prototype:Update(unit)
end
end
self:UpdateBar(self.health/self.maxHealth, self.color)
self:UpdateBar(self.healthPercentage, self.color)
if not IceHUD.IceCore:ShouldUseDogTags() then
self:SetBottomText1(math.floor(self.healthPercentage * 100))