comparison 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
comparison
equal deleted inserted replaced
214:a7c02f65b072 215:fbd52851dcd1
227 else 227 else
228 return nil; 228 return nil;
229 end 229 end
230 end 230 end
231 231
232 local autoSelectedItemCountAddon;
232 function addon:GetItemCountAddon(group) 233 function addon:GetItemCountAddon(group)
233 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon"); 234 local selectedExternalAddon = self:GetOptionByKey(group, "itemCountAddon");
234 235
235 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then 236 if self.supportedAddons.itemCount[selectedExternalAddon] and self.supportedAddons.itemCount[selectedExternalAddon].IsEnabled() then
236 -- Try to use the default item count addon 237 -- Try to use the default item count addon
238 if self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState then 239 if self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState then
239 self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded); 240 self.supportedAddons.itemCount[selectedExternalAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
240 end 241 end
241 242
242 return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon; 243 return self.supportedAddons.itemCount[selectedExternalAddon], selectedExternalAddon;
244 elseif self.supportedAddons.itemCount[autoSelectedItemCountAddon] and self.supportedAddons.itemCount[autoSelectedItemCountAddon].IsEnabled() then
245 -- Use previously automatically selected addon
246
247 if self.supportedAddons.itemCount[autoSelectedItemCountAddon].SetGuildState then
248 self.supportedAddons.itemCount[autoSelectedItemCountAddon].SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded);
249 end
250
251 return self.supportedAddons.itemCount[autoSelectedItemCountAddon], autoSelectedItemCountAddon;
243 else 252 else
244 -- Default not available, get the first one then 253 -- Default not available, get the first one then
245 254
255 -- We are finding the best match, quality is used to compare everything
256 local altName, altValue, altQuality;
257
246 for name, value in pairs(self.supportedAddons.itemCount) do 258 for name, value in pairs(self.supportedAddons.itemCount) do
247 if value.IsEnabled() then 259 if value.IsEnabled() then
248 if value.SetGuildState then 260 -- Quality is based on functionality supported; TotalCount, LocalCount & GuildSelect = 3; TotalCount & LocalCount = 2, TotalCount = 1
249 value.SetGuildState(self.db.profile.defaults.itemCountGuildsExcluded); 261 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);
262
263 if quality == 3 then
264 -- Best quality means instant return
265
266 -- Remember this was auto selected so we don't loop again
267 autoSelectedItemCountAddon = name;
268
269 return value, name;
270 elseif not altQuality or quality > altQuality then
271 -- Compare quality; improvement? = overwrite
272 altName = name;
273 altValue = value;
274 altQuality = quality;
250 end 275 end
251 276 end
252 return value, name; 277 end
253 end 278
279 if altName and altValue and altQuality then
280 -- Remember this was auto selected so we don't loop again
281 autoSelectedItemCountAddon = altName;
282
283 return altValue, altName;
254 end 284 end
255 end 285 end
256 286
257 return; 287 return;
258 end 288 end
262 292
263 if not itemId then return; end 293 if not itemId then return; end
264 294
265 local itemCountAddon = self:GetItemCountAddon(group); 295 local itemCountAddon = self:GetItemCountAddon(group);
266 296
267 return (itemCountAddon and itemCountAddon.GetTotalCount(itemId)) or -1; 297 return (itemCountAddon and itemCountAddon.GetTotalCount and itemCountAddon.GetTotalCount(itemId)) or -1;
268 end 298 end
269 299
270 function addon:GetLocalItemCount(itemId, group) 300 function addon:GetLocalItemCount(itemId, group)
271 itemId = tonumber(itemId); 301 itemId = tonumber(itemId);
272 302