Quantcast

Remove dependencies on OvalePaperDoll solely for the player's class.

Johnny C. Lam [11-10-13 - 00:32]
Remove dependencies on OvalePaperDoll solely for the player's class.

Check the player's class in the individual modules independently by
calling UnitClass("player') instead.

This flattens out the module dependency tree.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@1153 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
Ovale.toc
OvaleComboPoints.lua
OvaleCooldown.lua
OvaleOptions.lua
OvalePaperDoll.lua
OvaleScripts.lua
OvaleState.lua
diff --git a/Ovale.toc b/Ovale.toc
index 9d77abc..dcfb934 100644
--- a/Ovale.toc
+++ b/Ovale.toc
@@ -30,6 +30,8 @@ OvalePool.lua
 OvalePoolGC.lua
 OvalePoolRefCount.lua
 OvaleQueue.lua
+OvaleScripts.lua
+scripts\scripts.xml
 OvaleSpellBook.lua
 OvaleStance.lua
 OvaleTimeSpan.lua
@@ -37,28 +39,24 @@ OvaleTimeSpan.lua
 OvaleDamageTaken.lua
 OvalePaperDoll.lua
 OvaleScore.lua
-#
 OvaleState.lua
 #
 OvaleAura.lua
 OvaleComboPoints.lua
 OvaleCooldown.lua
+OvaleOptions.lua
 OvalePower.lua
 OvaleRecount.lua
-OvaleScripts.lua
-scripts\scripts.xml
 OvaleSkada.lua
 OvaleSpellDamage.lua
 OvaleSwing.lua
 #
-OvaleOptions.lua
-OvaleFuture.lua
-#
-conditions\conditions.xml
 OvaleCompile.lua
+OvaleFuture.lua
 OvaleIcone.lua
 OvaleIcone.xml
 #
+conditions\conditions.xml
 OvaleBestAction.lua
 #
 OvaleFrame.lua
diff --git a/OvaleComboPoints.lua b/OvaleComboPoints.lua
index 78e5b77..f4faaca 100644
--- a/OvaleComboPoints.lua
+++ b/OvaleComboPoints.lua
@@ -16,11 +16,14 @@ Ovale.OvaleComboPoints = OvaleComboPoints
 --<private-static-properties>
 local OvaleData = Ovale.OvaleData
 local OvaleGUID = Ovale.OvaleGUID
-local OvalePaperDoll = Ovale.OvalePaperDoll
 local OvaleState = Ovale.OvaleState

 local API_GetComboPoints = GetComboPoints
+local API_UnitClass = UnitClass
 local MAX_COMBO_POINTS = MAX_COMBO_POINTS
+
+-- Player's class.
+local self_class = select(2, API_UnitClass("player"))
 --</private-static-properties>

 --<public-static-properties>
@@ -29,7 +32,7 @@ OvaleComboPoints.combo = 0

 --<public-static-methods>
 function OvaleComboPoints:OnEnable()
-	if OvalePaperDoll.class == "ROGUE" or OvalePaperDoll.class == "DRUID" then
+	if self_class == "ROGUE" or self_class == "DRUID" then
 		self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
 		self:RegisterEvent("PLAYER_ENTERING_WORLD", "Refresh")
 		self:RegisterEvent("PLAYER_LOGIN", "Refresh")
@@ -41,7 +44,7 @@ function OvaleComboPoints:OnEnable()
 end

 function OvaleComboPoints:OnDisable()
-	if OvalePaperDoll.class == "ROGUE" or OvalePaperDoll.class == "DRUID" then
+	if self_class == "ROGUE" or self_class == "DRUID" then
 		OvaleState:UnregisterState(self)
 		self:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
 		self:UnregisterEvent("PLAYER_ENTERING_WORLD")
diff --git a/OvaleCooldown.lua b/OvaleCooldown.lua
index c98bcd6..464ed11 100644
--- a/OvaleCooldown.lua
+++ b/OvaleCooldown.lua
@@ -20,6 +20,10 @@ local OvaleState = Ovale.OvaleState

 local API_UnitHealth = UnitHealth
 local API_UnitHealthMax = UnitHealthMax
+local API_UnitClass = UnitClass
+
+-- Player's class.
+local self_class = select(2, API_UnitClass("player"))
 --</private-static-properties>

 --<public-static-methods>
@@ -35,15 +39,14 @@ end
 -- If no spellId is given, then returns the GCD after a "yellow-hit" ability has been cast.
 function OvaleCooldown:GetGCD(spellId)
 	-- Base global cooldown.
-	local class = OvalePaperDoll.class
 	local isCaster = false
-	if class == "DEATHKNIGHT" then
+	if self_class == "DEATHKNIGHT" then
 		cd = 1.0
-	elseif class == "DRUID" and OvaleStance:IsStance("druid_cat_form") then
+	elseif self_class == "DRUID" and OvaleStance:IsStance("druid_cat_form") then
 		cd = 1.0
-	elseif class == "MONK" then
+	elseif self_class == "MONK" then
 		cd = 1.0
-	elseif class == "ROGUE" then
+	elseif self_class == "ROGUE" then
 		cd = 1.0
 	else
 		isCaster = true
diff --git a/OvaleOptions.lua b/OvaleOptions.lua
index 35abca0..a6ce701 100644
--- a/OvaleOptions.lua
+++ b/OvaleOptions.lua
@@ -16,7 +16,6 @@ Ovale.OvaleOptions = OvaleOptions

 --<private-static-properties>
 local L = Ovale.L
-local OvalePaperDoll = Ovale.OvalePaperDoll
 local OvaleScripts = Ovale.OvaleScripts
 local OvaleSpellBook = Ovale.OvaleSpellBook
 local OvaleState = Ovale.OvaleState
@@ -25,6 +24,10 @@ local strgmatch = string.gmatch
 local strgsub = string.gsub
 local tostring = tostring
 local API_GetSpellInfo = GetSpellInfo
+local API_UnitClass = UnitClass
+
+-- Player's class.
+local self_class = select(2, API_UnitClass("player"))
 --</private-static-properties>

 --<public-static-properties>
@@ -361,7 +364,7 @@ local self_options =
 						return strgsub(code, "\t", "    ")
 					end,
 					set = function(info, v)
-						OvaleScripts:RegisterScript(OvalePaperDoll.class, "custom", L["Script personnalisé"], v)
+						OvaleScripts:RegisterScript(self_class, "custom", L["Script personnalisé"], v)
 						OvaleOptions.db.profile.code = v
 						OvaleOptions:SendMessage("Ovale_ScriptChanged")
 					end,
@@ -378,7 +381,6 @@ local self_options =
 						return L["Ecraser le Script personnalisé préexistant?"]
 					end,
 					func = function()
-						local class = OvalePaperDoll.class
 						local source = OvaleOptions.db.profile.source
 						local code
 						if source and OvaleScripts.script[source] then
@@ -712,7 +714,7 @@ function OvaleOptions:OnInitialize()
 	self.db.RegisterCallback( self, "OnProfileChanged", "HandleProfileChanges" )
 	self.db.RegisterCallback( self, "OnProfileCopied", "HandleProfileChanges" )

-	OvaleScripts:RegisterScript(OvalePaperDoll.class, "custom", L["Script personnalisé"], self.db.profile.code)
+	OvaleScripts:RegisterScript(self_class, "custom", L["Script personnalisé"], self.db.profile.code)
 	self:HandleProfileChanges()
 end

diff --git a/OvalePaperDoll.lua b/OvalePaperDoll.lua
index 52eb446..a4e751a 100644
--- a/OvalePaperDoll.lua
+++ b/OvalePaperDoll.lua
@@ -40,6 +40,8 @@ local API_UnitRangedAttackPower = UnitRangedAttackPower
 local API_UnitSpellHaste = UnitSpellHaste
 local API_UnitStat = UnitStat

+-- Player's class.
+local self_class = select(2, API_UnitClass("player"))
 -- Snapshot table pool.
 local self_pool = OvalePool("OvalePaperDoll_pool")
 -- Snapshot queue: new snapshots are inserted at the front of the queue.
@@ -106,8 +108,6 @@ local OVALE_SNAPSHOT_STATS = {
 --</private-static-properties>

 --<public-static-properties>
--- player's class token
-OvalePaperDoll.class = select(2, API_UnitClass("player"))
 -- player's level
 OvalePaperDoll.level = API_UnitLevel("player")
 -- Player's current specialization.
@@ -201,7 +201,7 @@ function OvalePaperDoll:COMBAT_RATING_UPDATE(event)
 	self.stat = GetSnapshot(now)
 	self.stat.meleeCrit = API_GetCritChance()
 	self.stat.rangedCrit = API_GetRangedCritChance()
-	self.stat.spellCrit = API_GetSpellCritChance(OVALE_SPELLDAMAGE_SCHOOL[self.class])
+	self.stat.spellCrit = API_GetSpellCritChance(OVALE_SPELLDAMAGE_SCHOOL[self_class])
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, true, "%s", event)
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f%%", OVALE_SNAPSHOT_STATS["meleeCrit"], self.stat.meleeCrit)
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, "    %s = %f%%", OVALE_SNAPSHOT_STATS["rangedCrit"], self.stat.rangedCrit)
@@ -249,7 +249,7 @@ end
 function OvalePaperDoll:SPELL_POWER_CHANGED(event)
 	local now = API_GetTime()
 	self.stat = GetSnapshot(now)
-	self.stat.spellBonusDamage = API_GetSpellBonusDamage(OVALE_SPELLDAMAGE_SCHOOL[self.class])
+	self.stat.spellBonusDamage = API_GetSpellBonusDamage(OVALE_SPELLDAMAGE_SCHOOL[self_class])
 	Ovale:DebugPrintf(OVALE_PAPERDOLL_DEBUG, true, "%s: %s = %d",
 		event, OVALE_SNAPSHOT_STATS["spellBonusDamage"], self.stat.spellBonusDamage)
 end
@@ -333,10 +333,10 @@ function OvalePaperDoll:UpdateDamage(event)
 	local now = API_GetTime()
 	self.stat = GetSnapshot(now)
 	self.stat.baseDamageMultiplier = damageMultiplier
-	if self.class == "DRUID" and OvaleStance:IsStance("druid_cat_form") then
+	if self_class == "DRUID" and OvaleStance:IsStance("druid_cat_form") then
 		-- Cat Form: 100% increased auto-attack damage.
 		damageMultiplier = damageMultiplier * 2
-	elseif self.class == "MONK" and OvaleEquipement:HasOneHandedWeapon() then
+	elseif self_class == "MONK" and OvaleEquipement:HasOneHandedWeapon() then
 		-- Way of the Monk: 40% increased auto-attack damage if dual-wielding.
 		damageMultiplier = damageMultiplier * 1.4
 	end
@@ -346,7 +346,7 @@ function OvalePaperDoll:UpdateDamage(event)
 	local avgDamage = (minDamage + maxDamage) / 2 / damageMultiplier
 	local mainHandWeaponSpeed = mainHandAttackSpeed * self:GetMeleeHasteMultiplier()
 	local normalizedMainHandWeaponSpeed = OvaleEquipement.mainHandWeaponSpeed or 0
-	if self.class == "DRUID" then
+	if self_class == "DRUID" then
 		if OvaleStance:IsStance("druid_cat_form") then
 			normalizedMainHandWeaponSpeed = 1
 		elseif OvaleStance:IsStance("druid_bear_form") then
@@ -363,7 +363,7 @@ function OvalePaperDoll:UpdateDamage(event)
 		offHandAttackSpeed = offHandAttackSpeed or mainHandAttackSpeed
 		local offHandWeaponSpeed = offHandAttackSpeed * self:GetMeleeHasteMultiplier()
 		local normalizedOffHandWeaponSpeed = OvaleEquipement.offHandWeaponSpeed or 0
-		if self.class == "DRUID" then
+		if self_class == "DRUID" then
 			if OvaleStance:IsStance("druid_cat_form") then
 				normalizedOffHandWeaponSpeed = 1
 			elseif OvaleStance:IsStance("druid_bear_form") then
@@ -455,7 +455,6 @@ end

 function OvalePaperDoll:Debug(stat)
 	stat = stat or self.stat
-	Ovale:FormatPrint("Class: %s", self.class)
 	Ovale:FormatPrint("Level: %d", self.level)
 	Ovale:FormatPrint("Specialization: %s", self.specialization)
 	Ovale:FormatPrint("Total snapshots: %d", self_snapshotCount)
diff --git a/OvaleScripts.lua b/OvaleScripts.lua
index 9e2cd2d..3ad634f 100644
--- a/OvaleScripts.lua
+++ b/OvaleScripts.lua
@@ -14,7 +14,11 @@ local OvaleScripts = Ovale:NewModule("OvaleScripts")
 Ovale.OvaleScripts = OvaleScripts

 --<private-static-properties>
-local OvalePaperDoll = Ovale.OvalePaperDoll
+local pairs = pairs
+local API_UnitClass = UnitClass
+
+-- Player's class.
+local self_class = select(2, API_UnitClass("player"))
 --</private-static-properties>

 --<public-static-properties>
@@ -37,7 +41,7 @@ function OvaleScripts:GetDescriptions(scriptType)
 end

 function OvaleScripts:RegisterScript(class, name, description, code, scriptType)
-	if not class or class == OvalePaperDoll.class then
+	if not class or class == self_class then
 		self.script[name] = self.script[name] or {}
 		local script = self.script[name]
 		script.type = scriptType or "script"
diff --git a/OvaleState.lua b/OvaleState.lua
index 98c45e5..711b377 100644
--- a/OvaleState.lua
+++ b/OvaleState.lua
@@ -17,7 +17,6 @@ Ovale.OvaleState = OvaleState

 --<private-static-properties>
 local OvaleData = Ovale.OvaleData
-local OvalePaperDoll = Ovale.OvalePaperDoll
 local OvaleQueue = Ovale.OvaleQueue
 local OvaleSpellBook = Ovale.OvaleSpellBook

@@ -27,6 +26,7 @@ local API_GetEclipseDirection = GetEclipseDirection
 local API_GetRuneCooldown = GetRuneCooldown
 local API_GetRuneType = GetRuneType
 local API_GetTime = GetTime
+local API_UnitClass = UnitClass

 local self_statePrototype = {}
 local self_stateModules = OvaleQueue:NewQueue("OvaleState_stateModules")
@@ -34,6 +34,8 @@ local self_stateModules = OvaleQueue:NewQueue("OvaleState_stateModules")
 local self_runes = {}
 local self_runesCD = {}

+-- Player's class.
+local self_class = select(2, API_UnitClass("player"))
 -- Whether the state of the simulator has been initialized.
 local self_stateIsInitialized = false

@@ -139,7 +141,7 @@ function OvaleState:Reset()

 	self:InvokeMethod("ResetState")

-	if OvalePaperDoll.class == "DEATHKNIGHT" then
+	if self_class == "DEATHKNIGHT" then
 		for i=1,6 do
 			self.state.rune[i].type = API_GetRuneType(i)
 			local start, duration, runeReady = API_GetRuneCooldown(i)