Quantcast

refactor to be able to get stats for only one class from the registry

Silversage of Eitrigg [10-19-11 - 19:29]
refactor to be able to get stats for only one class from the registry
Filename
GearStatsRegistry.lua
SageGearAdvice.toc
SageGearLevelTooltip.lua
diff --git a/GearStatsRegistry.lua b/GearStatsRegistry.lua
index 75d12cb..795e91a 100644
--- a/GearStatsRegistry.lua
+++ b/GearStatsRegistry.lua
@@ -1,3 +1,9 @@
+--[[
+
+  A registry for stat weights
+
+  ]]
+
 local registeredClasses = {}

 namespace("sage.gear").StatsRegistrar = {
@@ -26,4 +32,12 @@ namespace("sage.gear").AllStats = function(callback)
   for spec,data in pairs(registeredClasses) do
     callback(spec, data.class, data.stats, data.color)
   end
+end
+
+namespace("sage.gear").StatsForClass = function(class, callback)
+  for spec,data in pairs(registeredClasses) do
+    if (class == data.class) then
+      callback(spec, data.class, data.stats, data.color)
+    end
+  end
 end
\ No newline at end of file
diff --git a/SageGearAdvice.toc b/SageGearAdvice.toc
index db0e515..81d6fd8 100755
--- a/SageGearAdvice.toc
+++ b/SageGearAdvice.toc
@@ -2,9 +2,11 @@
 ## Title: Sage Gear Advice
 ## Notes: Stat-based gear evaluation that understands reforging.
 ## Version: @project-version@
+## SavedVariables SageGearAdvice
 SageClass.lua
 SageReforge.lua
 SageItem.lua
 GearStatsRegistry.lua
 stats.lua
+PerCharacterGearList.lua
 SageGearLevelTooltip.lua
diff --git a/SageGearLevelTooltip.lua b/SageGearLevelTooltip.lua
index 4cdc2e9..c683d7f 100644
--- a/SageGearLevelTooltip.lua
+++ b/SageGearLevelTooltip.lua
@@ -348,12 +348,7 @@ local SageGearLevelTooltipUpdater do
 	end

 	function class:AddSelfEvaluator(className, e)
-		local playerClassLocal, playerClass = UnitClass('player')
-		if className == playerClass then
-			--self:Debug("Installing evaluator for " .. playerClassLocal .. ": " .. (e:Name()))
-			return self:AddEvaluator(e)
-		end
-		return self
+    return self:AddEvaluator(e)
 	end

 	function class:AddEvaluator(e)
@@ -380,7 +375,8 @@ local tooltipUpdater = SageGearLevelTooltipUpdater:New(methodsToHook)
 		:AddItemCommenter(ItemLevelIdCommenter:New())

 local DEFAULT_COLOR = {r=0.5, g=0.5, b=0.5}
-sage.gear.AllStats(function(spec, class, stats, color)
+local _, playerClass = UnitClass('player')
+sage.gear.StatsForClass(playerClass, function(spec, class, stats, color)
   color = color or DEFAULT_COLOR
   local specInfo = {label = spec, r=color.r, g=color.g, b=color.b}
   tooltipUpdater:AddSelfEvaluator(