Quantcast

Add GUID lookup.

Christopher Rosell [07-24-12 - 15:14]
Add GUID lookup.
Filename
modules/tooltip.lua
modules/uniquecount.lua
petjournalex.lua
diff --git a/modules/tooltip.lua b/modules/tooltip.lua
old mode 100644
new mode 100755
index d88537d..d3364a9
--- a/modules/tooltip.lua
+++ b/modules/tooltip.lua
@@ -10,8 +10,11 @@ end
 function module:UPDATE_MOUSEOVER_UNIT()
 	if not UnitIsWildBattlePet"mouseover" then return end

-	local name = UnitName"mouseover"
-	local species = addon:GetPetInfoByName(name)
+	local guid = UnitGUID"mouseover"
+	local species = select(2, addon:GetPetInfoByGUID(guid))
+
+	if not species then return end
+
 	local collected = addon:IsPetSpeciesOwned(species)

 	if not collected then return end
diff --git a/modules/uniquecount.lua b/modules/uniquecount.lua
old mode 100644
new mode 100755
diff --git a/petjournalex.lua b/petjournalex.lua
index 5692c37..8017691 100755
--- a/petjournalex.lua
+++ b/petjournalex.lua
@@ -69,7 +69,24 @@ function addon:GetPetInfoByName(name)
 	for i = 1, self:GetNumPets() do
 		local pname = select(2, self:GetPetInfo(i))
 		if pname == name then
-			return self:GetPetInfo(i)
+			return i, self:GetPetInfo(i)
+		end
+	end
+end
+
+function addon:GetPetInfoByGUID(guid)
+	local first3 = tonumber("0x"..guid:sub(3, 5))
+	local unittype = bit.band(first3, 0x00f)
+
+	if unittype ~= 0x03 then return end
+
+	local npcid = tonumber("0x"..guid:sub(7, 10))
+
+	for i = 1, self:GetNumPets() do
+		local petnpc = select(5, self:GetPetInfo(i))
+
+		if petnpc == npcid then
+			return i, self:GetPetInfo(i)
 		end
 	end
 end
@@ -79,13 +96,9 @@ function addon:IsPetSpeciesOwned(species)
 	return self.petown[species]
 end

-function addon:PET_JOURNAL_LIST_UPDATE(...)
-	if self.updating then return end
+function addon:ClearPetJournalFilters()
 	self.updating = true

-	wipe(self.petidx)
-	wipe(self.petown)
-
 	for key, val in pairs(filterflags) do
 		filterflags[key] = not PJ.IsFlagFiltered(key)
 	end
@@ -105,13 +118,11 @@ function addon:PET_JOURNAL_LIST_UPDATE(...)
 	PJ.SetFlagFilter(LE_PET_JOURNAL_FLAG_NOT_COLLECTED, true)
 	PJ.SetSearchFilter("")

-	for i = 1, PJ.GetNumPets(false) do
-		local petid, speciesid, isowned = PJ.GetPetInfoByIndex(i, false)
-		if speciesid then
-			table.insert(self.petidx, speciesid)
-			self.petown[speciesid] = isowned
-		end
-	end
+	self.updating = false
+end
+
+function addon:RestorePetJournalFilters()
+	self.updating = true

 	for key, val in pairs(filterflags) do
 		PJ.SetFlagFilter(key, val)
@@ -132,6 +143,25 @@ function addon:PET_JOURNAL_LIST_UPDATE(...)
 	self.updating = false
 end

+function addon:PET_JOURNAL_LIST_UPDATE(...)
+	if self.updating then return end
+
+	wipe(self.petidx)
+	wipe(self.petown)
+
+	self:ClearPetJournalFilters()
+
+	for i = 1, PJ.GetNumPets(false) do
+		local petid, speciesid, isowned = PJ.GetPetInfoByIndex(i, false)
+		if speciesid then
+			table.insert(self.petidx, speciesid)
+			self.petown[speciesid] = isowned
+		end
+	end
+
+	self:RestorePetJournalFilters()
+end
+
 function addon:ADDON_LOADED(loaded)
 	if loaded ~= addonname then return end