Quantcast

Move GetTickLength() back to OvaleData after module de-coupling changes.

Johnny C. Lam [11-26-13 - 14:04]
Move GetTickLength() back to OvaleData after module de-coupling changes.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1201 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleAura.lua
OvaleData.lua
conditions/TickTime.lua
diff --git a/OvaleAura.lua b/OvaleAura.lua
index 906fcda..487e0c9 100644
--- a/OvaleAura.lua
+++ b/OvaleAura.lua
@@ -23,7 +23,6 @@ local OvalePoolRefCount = Ovale.OvalePoolRefCount
 local OvaleData = nil
 local OvaleFuture = nil
 local OvaleGUID = nil
-local OvalePaperDoll = nil
 local OvaleState = nil

 local ipairs = ipairs
@@ -153,7 +152,7 @@ local function UnitGainedAura(guid, spellId, filter, casterGUID, icon, count, de
 				-- Only set the initial tick information for new auras.
 				if not existingAura then
 					aura.ticksSeen = 0
-					aura.tick = self:GetTickLength(spellId)
+					aura.tick = OvaleData:GetTickLength(spellId)
 				end
 				-- Determine whether to snapshot player stats for the aura or to keep the existing stats.
 				local lastSpellcast = OvaleFuture.lastSpellcast
@@ -315,7 +314,7 @@ local function UpdateAuraTick(guid, spellId, timestamp)
 		if not aura.lastTickTime then
 			-- For some reason, there was no lastTickTime information recorded,
 			-- so approximate the tick time using the player's current stats.
-			tick = self:GetTickLength(spellId)
+			tick = OvaleData:GetTickLength(spellId)
 			ticksSeen = 0
 		else
 			-- Tick times tend to vary about the "true" value by a up to a few
@@ -338,7 +337,6 @@ function OvaleAura:OnInitialize()
 	OvaleData = Ovale.OvaleData
 	OvaleFuture = Ovale.OvaleFuture
 	OvaleGUID = Ovale.OvaleGUID
-	OvalePaperDoll = Ovale.OvalePaperDoll
 	OvaleState = Ovale.OvaleState
 end

@@ -557,33 +555,6 @@ function OvaleAura:GetAuraOnAnyTarget(spellId, filter, mine, excludingGUID)
 	return start, ending, count
 end

-function OvaleAura:GetTickLength(spellId)
-	local si
-	if type(spellId) == "number" then
-		si = OvaleData.spellInfo[spellId]
-	elseif OvaleData.buffSpellList[spellId] then
-		for auraId in pairs(OvaleData.buffSpellList[spellId]) do
-			si = OvaleData.spellInfo[auraId]
-			if si then break end
-		end
-	end
-	if si then
-		local tick = si.tick or 3
-		local hasteMultiplier = 1
-		if si.haste then
-			if si.haste == "spell" then
-				hasteMultiplier = OvalePaperDoll:GetSpellHasteMultiplier()
-			elseif si.haste == "melee" then
-				hasteMultiplier = OvalePaperDoll:GetMeleeHasteMultiplier()
-			end
-			return tick / hasteMultiplier
-		else
-			return tick
-		end
-	end
-	return math.huge
-end
-
 function OvaleAura:Debug()
 	self_pool:Debug()
 	self_table_pool:Debug()
@@ -717,7 +688,7 @@ do
 							-- Add new duration after the next tick is complete.
 							local remainingTicks = floor((ending - atTime) / tick)
 							newAura.ending = (ending - tick * remainingTicks) + duration
-							newAura.tick = OvaleAura:GetTickLength(auraId)
+							newAura.tick = OvaleData:GetTickLength(auraId)
 							-- Re-snapshot stats for the DoT.
 							OvaleFuture:UpdateSnapshotFromSpellcast(newAura, spellcast)
 						else
@@ -741,7 +712,7 @@ do
 					newAura.start = atTime
 					newAura.ending = atTime + duration
 					if isDoT then
-						newAura.tick = OvaleAura:GetTickLength(auraId)
+						newAura.tick = OvaleData:GetTickLength(auraId)
 						-- Snapshot stats for the DoT.
 						OvaleFuture:UpdateSnapshotFromSpellcast(newAura, spellcast)
 					end
@@ -902,7 +873,7 @@ do
 			end
 			if si.tick then	-- DoT
 				--DoT duration is tick * numTicks.
-				local tick = OvaleAura:GetTickLength(auraSpellId)
+				local tick = OvaleData:GetTickLength(auraSpellId)
 				local numTicks = floor(duration / tick + 0.5)
 				duration = tick * numTicks
 				return duration, tick, numTicks
diff --git a/OvaleData.lua b/OvaleData.lua
index 0839923..0ce90b9 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -13,6 +13,9 @@ local OvaleData = Ovale:NewModule("OvaleData")
 Ovale.OvaleData = OvaleData

 --<private-static-properties>
+-- Forward declarations for module dependencies.
+local OvalePaperDoll = nil
+
 local API_GetSpellCooldown = GetSpellCooldown

 -- Auras that are refreshed by spells that don't trigger a new snapshot.
@@ -243,6 +246,11 @@ OvaleData.buffSpellList.heroism = OvaleData.buffSpellList.burst_haste
 --</public-static-properties>

 --<public-static-methods>
+function OvaleData:OnInitialize()
+	-- Resolve module dependencies.
+	OvalePaperDoll = Ovale.OvalePaperDoll
+end
+
 function OvaleData:ResetSpellInfo()
 	self.spellInfo = {}
 end
@@ -257,6 +265,18 @@ function OvaleData:NeedNewSnapshot(auraSpellId, spellId)
 	return true
 end

+function OvaleData:GetSpellInfo(spellId)
+	if type(spellId) == "number" then
+		return self.spellInfo[spellId]
+	elseif self.buffSpellList[spellId] then
+		for auraId in pairs(self.buffSpellList[spellId]) do
+			if self.spellInfo[auraId] then
+				return self.spellInfo[auraId]
+			end
+		end
+	end
+end
+
 --Compute the spell Cooldown
 function OvaleData:GetSpellCooldown(spellId)
 	local start, duration, enable = API_GetSpellCooldown(spellId)
@@ -299,4 +319,23 @@ function OvaleData:GetDamage(spellId, attackpower, spellpower, mainHandWeaponDam
 	end
 	return damage
 end
+
+function OvaleData:GetTickLength(spellId)
+	local si = self:GetSpellInfo(spellId)
+	if si then
+		local tick = si.tick or 3
+		local hasteMultiplier = 1
+		if si.haste then
+			if si.haste == "spell" then
+				hasteMultiplier = OvalePaperDoll:GetSpellHasteMultiplier()
+			elseif si.haste == "melee" then
+				hasteMultiplier = OvalePaperDoll:GetMeleeHasteMultiplier()
+			end
+			return tick / hasteMultiplier
+		else
+			return tick
+		end
+	end
+	return math.huge
+end
 --</public-static-methods>
diff --git a/conditions/TickTime.lua b/conditions/TickTime.lua
index 8f07312..dd8cb53 100644
--- a/conditions/TickTime.lua
+++ b/conditions/TickTime.lua
@@ -11,8 +11,8 @@
 local _, Ovale = ...

 do
-	local OvaleAura = Ovale.OvaleAura
 	local OvaleCondition = Ovale.OvaleCondition
+	local OvaleData = Ovale.OvaleData
 	local OvaleState = Ovale.OvaleState

 	local Compare = OvaleCondition.Compare
@@ -40,7 +40,7 @@ do
 		local target, filter, mine = ParseCondition(condition)
 		local aura = state:GetAura(target, auraId, filter, mine)
 		if aura then
-			local value = aura.tick or OvaleAura:GetTickLength(auraId)
+			local value = aura.tick or OvaleData:GetTickLength(auraId)
 			return Compare(value, comparator, limit)
 		end
 		return Compare(math.huge, comparator, limit)