changeset 242:b56cff349bd6

Move non-option stuff out of State.lua Remove unused callbacks
author Flick
date Fri, 25 Mar 2011 17:06:56 -0700
parents 09c8e9baa35a
children 0ea0cdd7f386
files ReAction.lua classes/Bar.lua classes/State.lua
diffstat 3 files changed, 35 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/ReAction.lua	Fri Mar 25 16:50:43 2011 -0700
+++ b/ReAction.lua	Fri Mar 25 17:06:56 2011 -0700
@@ -109,12 +109,14 @@
   self.db.RegisterCallback(self,"OnProfileReset", "OnNewProfile")
 
   self:RegisterEvent("PLAYER_REGEN_DISABLED")
+  self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
 
   self:InitializeOptions()
 end
 
 function ReAction:OnEnable()
   self:InitializeBars()
+  self:UPDATE_SHAPESHIFT_FORMS() -- it doesn't fire on a /reloadui
 end
 
 function ReAction:OnDisable()
@@ -130,6 +132,16 @@
   end
 end
 
+function module:UPDATE_SHAPESHIFT_FORMS()
+  -- Re-parse the rules table according to the new form list.
+  -- This happens both at initial login (after PLAYER_ENTERING_WORLD)
+  -- as well as when gaining new abilities. 
+  ReAction.Bar:InitRuleFormats()
+  for _, bar in self:IterateBars() do
+    bar:ApplyStates()
+  end
+end
+
 function ReAction:LIBKEYBOUND_ENABLED( evt )
   self:SetKeybindMode(true)
 end
@@ -242,13 +254,6 @@
   end
 end
 
-function ReAction:RefreshBar(x)
-  local bar, name = self:GetBar(x)
-  if bar and name then
-    self.callbacks:Fire("OnRefreshBar", bar, name)
-  end
-end
-
 function ReAction:InitializeBars()
   if not self.barsInitialized then
     self:ManageBlizzardBars()
@@ -258,10 +263,9 @@
         self:CreateBar(name, config)
       end
     end
-    -- re-anchor and refresh in case anchor order does not match init order
+    -- re-anchor in case anchor order does not match init order
     for name, bar in pairs(self.bars) do
       bar:ApplyAnchor()
-      self.callbacks:Fire("OnRefreshBar", bar, name)
     end
     self.barsInitialized = true
   end
@@ -305,7 +309,6 @@
 function ReAction:EraseBar(x)
   local bar, name = self:GetBar(x)
   if bar and name then
-    self.callbacks:Fire("OnEraseBar", bar, name)
     self:DestroyBar(bar)
     self.db.profile.bars[name] = nil
   end
--- a/classes/Bar.lua	Fri Mar 25 16:50:43 2011 -0700
+++ b/classes/Bar.lua	Fri Mar 25 17:06:56 2011 -0700
@@ -8,6 +8,7 @@
 local fmod = math.fmod
 local format = string.format
 local tfetch = addonTable.tfetch
+local tbuild = addonTable.tbuild
 local fieldsort = addonTable.fieldsort
 
 local LSG = LibStub("ReAction-LibShowActionGrid-1.0")
@@ -228,12 +229,14 @@
   ReAction.RegisterCallback(self, "OnConfigModeChanged")
 
   buttonClass:SetupBar(self)
+  self:ApplyStates()
 
   return self
 end
 
 function Bar:Destroy()
   local f = self:GetFrame()
+  self:CleanupStates()
   for idx, b in self:IterateButtons() do
     b:Destroy()
   end
@@ -322,7 +325,6 @@
   c.x = x or c.x
   c.y = y or c.y
   self:ApplyAnchor()
-  ReAction:RefreshBar(self)
 end
 
 function Bar:GetSize()
@@ -350,7 +352,6 @@
     self.config.btnWidth = w
     self.config.btnHeight = h
   end
-  ReAction:RefreshBar(self)
 end
 
 function Bar:GetNumButtons()
@@ -374,7 +375,6 @@
     cfg.spacing = s
   end
   self.buttonClass:SetupBar(self)
-  ReAction:RefreshBar(self)
 end
 
 function Bar:GetAlpha()
@@ -385,7 +385,6 @@
   self.config.alpha = value
   self:GetFrame():SetAlpha(value or 1.0)
   self:UpdateDefaultStateAlpha()
-  ReAction:RefreshBar(self)
 end
 
 function Bar:IterateButtons()
@@ -535,11 +534,24 @@
 end
 
 function Bar:GetStateProperty(state, propname)
-  -- override in modules/State.lua for now
+  return tfetch(self:GetConfig(), "states", state, propname)
 end
 
 function Bar:SetStateProperty(state, propname, value)
-  -- override in modules/State.lua for now
+  local s = tbuild(self:GetConfig(), "states", state)
+  s[propname] = value
+  self:SetSecureStateData(state, propname, value)
+end
+
+function Bar:ApplyStates()
+  local states = tfetch(self:GetConfig(), "states")
+  if states then
+    self:SetStateDriver(states)
+  end
+end
+
+function Bar:CleanupStates()
+  self:SetStateDriver(nil)
 end
 
 function Bar:RefreshSecureState()
--- a/classes/State.lua	Fri Mar 25 16:50:43 2011 -0700
+++ b/classes/State.lua	Fri Mar 25 17:06:56 2011 -0700
@@ -13,75 +13,20 @@
 local RegisterStateDriver = RegisterStateDriver
 local tfetch = addonTable.tfetch
 local tbuild = addonTable.tbuild
+local ApplyStates   = Bar.ApplyStates
+local CleanupStates = Bar.CleanupStates
+local SetProperty   = Bar.SetStateProperty
+local GetProperty   = Bar.GetStateProperty
 
 -- module declaration
 local moduleID = "State"
 local module = ReAction:NewModule( moduleID, "AceEvent-3.0" )
 
--- Utility --
-
-
-
-local ApplyStates, CleanupStates, SetProperty, GetProperty
-
--- PRIVATE --
-do
-  function GetProperty( bar, state, propname )
-    return tfetch(bar:GetConfig(), "states", state, propname)
-  end
-
-  function SetProperty( bar, state, propname, value )
-    local s = tbuild(bar:GetConfig(), "states", state)
-    s[propname] = value
-    bar:SetSecureStateData(state, propname, value)
-  end
-
-  function ApplyStates( bar )
-    local states = tfetch(bar:GetConfig(), "states")
-    if states then
-      bar:SetStateDriver(states)
-    end
-  end
-
-  function CleanupStates( bar )
-    bar:SetStateDriver(nil)
-  end
-end
-
-
 
 -- module event handlers --
 
 function module:OnInitialize()
-  self:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
-
   ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
-
-  ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar")
-  ReAction.RegisterCallback(self, "OnDestroyBar")
-  ReAction.RegisterCallback(self, "OnRefreshBar")
-end
-
-function module:OnEnable()
-  self:UPDATE_SHAPESHIFT_FORMS() -- it doesn't fire on a /reloadui
-end
-
-function module:UPDATE_SHAPESHIFT_FORMS()
-  -- Re-parse the rules table according to the new form list.
-  -- This happens both at initial login (after PLAYER_ENTERING_WORLD)
-  -- as well as when gaining new abilities. 
-  ReAction.Bar.InitRuleFormats()
-  for _, bar in ReAction:IterateBars() do
-    ApplyStates(bar)
-  end
-end
-
-function module:OnRefreshBar(event, bar, name)
-  ApplyStates(bar)
-end
-
-function module:OnDestroyBar(event, bar, name)
-  CleanupStates(bar)
 end