Quantcast

Add a new method OvaleData.GetSpellName(spellId).

Johnny C. Lam [03-23-13 - 21:39]
Add a new method OvaleData.GetSpellName(spellId).

This returns the name associated with the given spell ID and guards
against nil spell IDs.

git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@823 d5049fe3-3747-40f7-a4b5-f36d6801af5f
Filename
OvaleBestAction.lua
OvaleCompile.lua
OvaleCondition.lua
OvaleData.lua
diff --git a/OvaleBestAction.lua b/OvaleBestAction.lua
index a219137..b35f659 100644
--- a/OvaleBestAction.lua
+++ b/OvaleBestAction.lua
@@ -751,10 +751,7 @@ function OvaleBestAction:GetActionInfo(element)
 			end
 		end

-		local spellName = OvaleData.spellList[spellId]
-		if not spellName then
-			spellName = API_GetSpellInfo(spellId)
-		end
+		local spellName = OvaleData:GetSpellName(spellId)
 		actionTexture = API_GetSpellTexture(spellId)
 		actionInRange = API_IsSpellInRange(spellName, target)
 		actionUsable = API_IsUsableSpell(spellId)
@@ -780,9 +777,7 @@ function OvaleBestAction:GetActionInfo(element)
 			return nil
 		end

-		if (Ovale.trace) then
-			Ovale:Print("Item "..tostring(itemId))
-		end
+		Ovale:Log("Item "..tostring(itemId))

 		local spellName = API_GetItemSpell(itemId)
 		actionUsable = (spellName~=nil)
diff --git a/OvaleCompile.lua b/OvaleCompile.lua
index 599578f..ddbc7ed 100644
--- a/OvaleCompile.lua
+++ b/OvaleCompile.lua
@@ -613,11 +613,12 @@ local function ParseCanStopChannelling(text)
 end

 local function ParseSpellName(text)
-	local spell = OvaleData:GetSpellInfoOrNil(text)
-	if (spell) then
-		return '"'..spell..'"'
+	local spellId = tonumber(text)
+	local spell = OvaleData:GetSpellName(spellId)
+	if spell then
+		return '"' .. spell .. '"'
 	else
-		Ovale:Print("SpellName of "..text.." unknown")
+		Ovale:Print("SpellName of " .. text .. " unknown")
 		return nil
 	end
 end
diff --git a/OvaleCondition.lua b/OvaleCondition.lua
index 240f100..60e2df5 100644
--- a/OvaleCondition.lua
+++ b/OvaleCondition.lua
@@ -2722,7 +2722,7 @@ OvaleCondition.conditions.totemexpires = function(condition)
 	if not startTime then
 		return 0
 	end
-	if (condition.totem and OvaleData:GetSpellInfoOrNil(condition.totem)~=totemName) then
+	if condition.totem and OvaleData:GetSpellName(condition.totem) ~= totemName then
 		return 0
 	end
 	return addTime(startTime + duration, -(condition[2] or 0))
@@ -2750,7 +2750,7 @@ OvaleCondition.conditions.totempresent = function(condition)
 	if not startTime then
 		return nil
 	end
-	if (condition.totem and OvaleData:GetSpellInfoOrNil(condition.totem)~=totemName) then
+	if condition.totem and OvaleData:GetSpellName(condition.totem) ~= totemName then
 		return nil
 	end
 	return startTime, startTime + duration
@@ -2760,12 +2760,12 @@ end
 	-- 1: the spell id
 	-- return bool
 OvaleCondition.conditions.tracking = function(condition)
-	local what = OvaleData:GetSpellInfoOrNil(condition[1])
+	local what = OvaleData:GetSpellName(condition[1])
 	local numTrackingTypes = API_GetNumTrackingTypes()
 	local present = false
-	for i=1,numTrackingTypes do
-		local name, texture, active = API_GetTrackingInfo(i)
-		if name == what then
+	for i = 1, numTrackingTypes do
+		local name, _, active = API_GetTrackingInfo(i)
+		if name and name == what then
 			present = (active == 1)
 			break
 		end
diff --git a/OvaleData.lua b/OvaleData.lua
index 8e776e1..1206945 100644
--- a/OvaleData.lua
+++ b/OvaleData.lua
@@ -394,6 +394,11 @@ function OvaleData:GetSpellInfoOrNil(spell)
 	end
 end

+function OvaleData:GetSpellName(spellId)
+	if not spellId then return nil end
+	return self.spellList[spellId] or API_GetSpellInfo(spellId)
+end
+
 function OvaleData:FillPetSpellList()
 	--TODO pas moyen d'avoir le nombre de skills pour le pet
 	local book=BOOKTYPE_PET