Quantcast

I can't remember why I did these changes, hopefully they work.

Christopher Rosell [09-01-10 - 13:26]
I can't remember why I did these changes, hopefully they work.
Filename
kungaloosh.lua
diff --git a/kungaloosh.lua b/kungaloosh.lua
index b1167fc..8637748 100644
--- a/kungaloosh.lua
+++ b/kungaloosh.lua
@@ -57,15 +57,8 @@ end
 function addon:UNIT_THREAT_LIST_UPDATE(unit)
 	if not unit then return end

-	local icon = self:GetNextIcon()
 	local guid = UnitGUID(unit)
-
-	for i,v in pairs(self.iconstate) do
-		if v == guid then
-			icon = i
-			break
-		end
-	end
+	local icon = self:GetRaidIconByGUID(guid) or self:GetNextIcon()

 	if icon and GetRaidTargetIndex(unit) == nil then
 		local istanking, status, threatpct, rawthreatpct, threat = UnitDetailedThreatSituation('player', unit)
@@ -78,43 +71,76 @@ end

 function addon:COMBAT_LOG_EVENT(timestamp, event, sguid, sname, sflags, dguid, dname, dflags)
 	if event == 'UNIT_DIED' then
-		for icon, guid in pairs(self.iconstate) do
-			if dguid == guid then
-				self.iconstate[icon] = nil
-			end
+		local icon = self:GetRaidIconByGUID(dguid)
+		if icon then
+			self.iconguids[icon] = nil
 		end
 	end
 end

-function addon:RAID_TARGET_UPDATE()
-	local function check(unit)
-		if UnitExists(unit) then
-			local icon = GetRaidTargetIndex(unit)
-			if icon then
-				self.iconstate[icon] = UnitGUID(unit)
+local function CheckUnit(unit)
+	if UnitExists(unit) then
+		local icon = GetRaidTargetIndex(unit)
+		local guid = UnitGUID(unit)
+
+		if icon then
+			local oldguid = addon:GetGUIDByRaidIcon(icon)
+			local oldicon = addon:GetRaidIconByGUID(guid)
+
+			if guid ~= oldguid then
+				if oldicon then
+					addon.iconguids[oldicon] = nil
+				end
+
+				addon.iconguids[icon] = guid
+			end
+		else
+			local oldicon = addon:GetRaidIconByGUID(guid)
+
+			if oldicon then
+				addon.iconguids[oldicon] = nil
 			end
 		end
 	end
+end

-	check('target')
-	check('pettarget')
-	for i=1,5 do
-		check('party'..i..'target')
-	end
+function addon:RAID_TARGET_UPDATE()
+	CheckUnit'player'
+	CheckUnit'target'
+	CheckUnit'pet'
+	CheckUnit'pettarget'
+
+	for i = 1,40 do
+		if i <= 5 then
+			CheckUnit('party'..i)
+			CheckUnit('party'..i..'target')
+		end

-	for i=1,40 do
-		check('raid'..i..'target')
+		CheckUnit('raid'..i)
+		CheckUnit('raid'..i..'target')
 	end
 end

 function addon:ResetState()
-	self.iconstate = self.iconstate or {}
-	table.wipe(self.iconstate)
+	self.iconguids = self.iconguids or {}
+	table.wipe(self.iconguids)
+end
+
+function addon:GetRaidIconByGUID(guid)
+	for icon, iguid in pairs(self.iconguids) do
+		if guid == iguid then
+			return icon
+		end
+	end
+end
+
+function addon:GetGUIDByRaidIcon(icon)
+	return self.iconguids[icon]
 end

 function addon:GetNextIcon()
 	for i, icon in ipairs(self.db.profile.raid_icons) do
-		if not self.iconstate[icon] then
+		if not addon:GetGUIDByRaidIcon(icon) then
 			return icon
 		end
 	end