diff Core.lua @ 215:fbd52851dcd1

Now using the best item count addon available when the selected is unavailable, rather than a random.
author Zerotorescue
date Sun, 06 Feb 2011 14:00:19 +0100
parents 1959e2b3dfe1
children ca05b8ade1ea
line wrap: on
line diff
--- a/Core.lua	Sun Feb 06 13:43:06 2011 +0100
+++ b/Core.lua	Sun Feb 06 14:00:19 2011 +0100
@@ -229,6 +229,7 @@
 	end
 end
 
+local autoSelectedItemCountAddon;
 function addon:GetItemCountAddon(group)
 	local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
 	
@@ -240,18 +241,47 @@
 		end
 		
 		return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon;
+	elseif self.supportedAddons.itemCount[autoSelectedItemCountAddon] and self.supportedAddons.itemCount[autoSelectedItemCountAddon].IsEnabled() then
+		-- Use previously automatically selected addon
+		
+		if self.supportedAddons.itemCount[autoSelectedItemCountAddon].SetGuildState then
+			self.supportedAddons.itemCount[autoSelectedItemCountAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
+		end
+		
+		return self.supportedAddons.itemCount[autoSelectedItemCountAddon], autoSelectedItemCountAddon;
 	else
 		-- Default not available, get the first one then
 		
+		-- We are finding the best match, quality is used to compare everything
+		local altName, altValue, altQuality;
+		
 		for name, value in pairs(self.supportedAddons.itemCount) do
 			if value.IsEnabled() then
-				if value.SetGuildState then
-					value.SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
+				-- Quality is based on functionality supported; TotalCount, LocalCount & GuildSelect = 3; TotalCount & LocalCount = 2, TotalCount = 1
+				local quality = ((value.GetTotalCount and value.GetCharacterCount and value.SetGuildState and 3) or (value.GetTotalCount and value.GetCharacterCount and 2) or (value.GetTotalCount and 1) or 0);
+				
+				if quality == 3 then
+					-- Best quality means instant return
+					
+					-- Remember this was auto selected so we don't loop again 
+					autoSelectedItemCountAddon = name;
+					
+					return value, name;
+				elseif not altQuality or quality > altQuality then
+					-- Compare quality; improvement? = overwrite
+					altName = name;
+					altValue = value;
+					altQuality = quality;
 				end
-				
-				return value, name;
 			end
 		end
+		
+		if altName and altValue and altQuality then
+			-- Remember this was auto selected so we don't loop again 
+			autoSelectedItemCountAddon = altName;
+			
+			return altValue, altName;
+		end
 	end
 	
 	return;
@@ -264,7 +294,7 @@
 	
 	local itemCountAddon = self:GetItemCountAddon(group);
 	
-	return (itemCountAddon and itemCountAddon.GetTotalCount(itemId)) or -1;
+	return (itemCountAddon and itemCountAddon.GetTotalCount and itemCountAddon.GetTotalCount(itemId)) or -1;
 end
 
 function addon:GetLocalItemCount(itemId, group)