Quantcast

Move ComputeParameter into the dependent code to reduce dependencies.

Johnny C. Lam [07-13-14 - 11:31]
Move ComputeParameter into the dependent code to reduce dependencies.

This has code duplication and needs to refactored.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1541 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleCompile.lua
OvaleCondition.lua
conditions/Damage.lua
conditions/LastEstimatedDamage.lua
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 94862de..4456bd4 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -1015,6 +1015,10 @@ function OvaleCompile:Compile()
 	end
 end

+function OvaleCompile:GetFunctionNode(name)
+	return self.customFunctionNode[name]
+end
+
 function OvaleCompile:GetMasterNodes()
 	-- Compile the script if it is outdated.
 	if not self.serial or self.serial < self_serial then
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index 63105ce..c533275 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -47,11 +47,6 @@ local OvaleCondition = Ovale:NewModule("OvaleCondition")
 Ovale.OvaleCondition = OvaleCondition

 --<private-static-properties>
--- Forward declarations for module dependencies.
-local OvaleBestAction = nil
-local OvaleCompile = nil
-local OvaleData = nil
-
 local type = type
 local wipe = table.wipe

@@ -88,13 +83,6 @@ OvaleCondition.COMPARATOR = {
 --</public-static-properties>

 --<public-static-methods>
-function OvaleCondition:OnInitialize()
-	-- Resolve module dependencies.
-	OvaleBestAction = Ovale.OvaleBestAction
-	OvaleCompile = Ovale.OvaleCompile
-	OvaleData = Ovale.OvaleData
-end
-
 function OvaleCondition:RegisterCondition(name, isSpellbookCondition, func, arg)
 	if arg then
 		if type(func) == "string" then
@@ -125,24 +113,6 @@ function OvaleCondition:EvaluateCondition(name, ...)
 	return self_condition[name](...)
 end

-function OvaleCondition.ComputeParameter(spellId, paramName, state)
-	local si = OvaleData:GetSpellInfo(spellId)
-	if si and si[paramName] then
-		local name = si[paramName]
-		local node = OvaleCompile.customFunctionNode[name]
-		if node then
-			local timeSpan, priority, element = OvaleBestAction:Compute(node, state)
-			if element and element.type == "value" then
-				local value = element.value + (state.currentTime - element.origin) * element.rate
-				return value
-			end
-		else
-			return si[paramName]
-		end
-	end
-	return nil
-end
-
 OvaleCondition.ParseCondition = function(condition, defaultTarget)
 	defaultTarget = defaultTarget or "player"
 	local target = condition.target or defaultTarget
diff --git a/conditions/Damage.lua b/conditions/Damage.lua
index a520924..42e5242 100644
--- a/conditions/Damage.lua
+++ b/conditions/Damage.lua
@@ -10,16 +10,35 @@
 local _, Ovale = ...

 do
+	local OvaleBestAction = Ovale.OvaleBestAction
+	local OvaleCompile = Ovale.OvaleCompile
 	local OvaleCondition = Ovale.OvaleCondition
 	local OvaleData = Ovale.OvaleData
 	local OvaleEquipement = Ovale.OvaleEquipement
 	local OvaleState = Ovale.OvaleState

 	local Compare = OvaleCondition.Compare
-	local ComputeParameter = OvaleCondition.ComputeParameter
 	local ParseCondition = OvaleCondition.ParseCondition
 	local state = OvaleState.state

+	function ComputeParameter(spellId, paramName, state)
+		local si = OvaleData:GetSpellInfo(spellId)
+		if si and si[paramName] then
+			local name = si[paramName]
+			local node = OvaleCompile:GetFunctionNode(name)
+			if node then
+				local timeSpan, priority, element = OvaleBestAction:Compute(node, state)
+				if element and element.type == "value" then
+					local value = element.value + (state.currentTime - element.origin) * element.rate
+					return value
+				end
+			else
+				return si[paramName]
+			end
+		end
+		return nil
+	end
+
 	-- Return the non-critical-strike damage of a spell, given the player's current stats.
 	local function GetDamage(spellId)
 		-- TODO: Use target's debuffs in this calculation.
diff --git a/conditions/LastEstimatedDamage.lua b/conditions/LastEstimatedDamage.lua
index 703dd05..0c7d623 100644
--- a/conditions/LastEstimatedDamage.lua
+++ b/conditions/LastEstimatedDamage.lua
@@ -10,17 +10,37 @@
 local _, Ovale = ...

 do
+	local OvaleBestAction = Ovale.OvaleBestAction
+	local OvaleCompile = Ovale.OvaleCompile
 	local OvaleCondition = Ovale.OvaleCondition
 	local OvaleData = Ovale.OvaleData
-	local OvaleGUID = Ovale.OvaleGUID
+	local OvaleEquipement = Ovale.OvaleEquipement
 	local OvaleFuture = Ovale.OvaleFuture
+	local OvaleGUID = Ovale.OvaleGUID
 	local OvaleState = Ovale.OvaleState

 	local Compare = OvaleCondition.Compare
-	local ComputeParameter = OvaleCondition.ComputeParameter
 	local ParseCondition = OvaleCondition.ParseCondition
 	local state = OvaleState.state

+	function ComputeParameter(spellId, paramName, state)
+		local si = OvaleData:GetSpellInfo(spellId)
+		if si and si[paramName] then
+			local name = si[paramName]
+			local node = OvaleCompile:GetFunctionNode(name)
+			if node then
+				local timeSpan, priority, element = OvaleBestAction:Compute(node, state)
+				if element and element.type == "value" then
+					local value = element.value + (state.currentTime - element.origin) * element.rate
+					return value
+				end
+			else
+				return si[paramName]
+			end
+		end
+		return nil
+	end
+
 	-- Return the damage reduction from armor, assuming the target is boss-level.
 	local BOSS_ARMOR = 24835
 	local WEAKENED_ARMOR_DEBUFF = 113746