changeset 65:5ea65ec7d162

Fixed stance initializers for locale-independent behavior as well as proper initialization for druids (after PLAYER_AURAS_CHANGED)
author Flick <flickerstreak@gmail.com>
date Wed, 28 May 2008 17:26:27 +0000
parents 2000f4f4c6af
children 44d3716aba8d
files modules/ReAction_State/ReAction_State.lua
diffstat 1 files changed, 100 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/modules/ReAction_State/ReAction_State.lua	Wed May 28 00:20:04 2008 +0000
+++ b/modules/ReAction_State/ReAction_State.lua	Wed May 28 17:26:27 2008 +0000
@@ -11,50 +11,7 @@
 
 -- module declaration
 local moduleID = "State"
-local module = ReAction:NewModule( moduleID )
-
-
--- module event handlers
-function module:OnInitialize()
-  self.db = ReAction.db:RegisterNamespace( moduleID, 
-    {
-      profile = { 
-        bars = { },
-      }
-    }
-  )
-
-  ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
-
-  ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar")
-  ReAction.RegisterCallback(self, "OnRefreshBar")
-  ReAction.RegisterCallback(self, "OnEraseBar")
-  ReAction.RegisterCallback(self, "OnRenameBar")
-  ReAction.RegisterCallback(self, "OnConfigModeChanged")
-end
-
-function module:OnRefreshBar(event, bar, name)
-  local c = self.db.profile.bars[name]
-  if c then
-    self:UpdateStates(bar)
-  end
-end
-
-function module:OnEraseBar(event, bar, name)
-  self.db.profile.bars[name] = nil
-end
-
-function module:OnRenameBar(event, bar, oldname, newname)
-  local b = self.db.profile.bars
-  bars[newname], bars[oldname] = bars[oldname], nil
-end
-
-function module:OnConfigModeChanged(event, mode)
-  -- TODO: unregister all state drivers (temporarily) and hidestates
-end
-
-
-
+local module = ReAction:NewModule( moduleID, "AceEvent-3.0" )
 
 -- Utility --
 
@@ -77,54 +34,60 @@
 end
 
 -- PRIVATE --
-local BuildRuleString, ApplyStates
+local InitRules, ApplyStates
 do
-  local forms = { }
-  for i = 1, GetNumShapeshiftForms() do
-    local icon, name = GetShapeshiftFormInfo(i)
-    forms[name] = i;
+  local ruleformats = { }
+
+  function InitRules()
+    local forms = { }
+    for i = 1, GetNumShapeshiftForms() do
+      local icon = GetShapeshiftFormInfo(i)
+      forms[icon] = i;
+    end
+      -- sort by icon since it's locale-independent
+      -- use 9 if not found since 9 is never a valid stance/form
+      -- we do these shenanigans instead of hardcoding the stances because
+      -- the ordering varies if the character is missing a form. For warriors
+      -- this is rarely a problem but for druids it can be. Some people never bother
+      -- to do the aquatic form quest, and stance 5 can be either flight or tree/boomkin
+      -- depending on talents.
+    local defensive = forms["Interface\\Icons\\Ability_Warrior_DefensiveStance"] or 9
+    local berserker = forms["Interface\\Icons\\Ability_Racial_Avatar"] or 9
+    local bear      = forms["Interface\\Icons\\Ability_Racial_BearForm"] or 9 -- bear and dire bear share the same icon
+    local aquatic   = forms["Interface\\Icons\\Ability_Druid_AquaticForm"] or 9
+    local cat       = forms["Interface\\Icons\\Ability_Druid_CatForm"] or 9
+    local travel    = forms["Interface\\Icons\\Ability_Druid_TravelForm"] or 9
+    local treekin   = forms["Interface\\Icons\\Ability_Druid_TreeofLife"] or forms["Interface\\Icons\\Spell_Nature_ForceOfNature"] or 9
+    local flight    = forms["Interface\\Icons\\Ability_Druid_FlightForm"] or 9 -- both flight and swift flight share the same icon
+
+    -- As far as I can tell the macro clauses are NOT locale-specific.
+    ruleformats.battle        = "stance:1"
+    ruleformats.defensive     = ("stance:%d"):format(defensive)
+    ruleformats.berserker     = ("stance:%d"):format(berserker)
+    ruleformats.caster        = ("form:0/%d/%d/%d"):format(aquatic, travel, flight)
+    ruleformats.bear          = ("form:%d"):format(bear)
+    ruleformats.cat           = ("form:%d"):format(cat)
+    ruleformats.treeOrMoonkin = ("form:%d"):format(treekin)
+    ruleformats.stealth       = "stealth"
+    ruleformats.nostealth     = "nostealth"
+    ruleformats.shadowform    = "form:1"
+    ruleformats.noshadowform  = "noform"
+    ruleformats.pet           = "pet"
+    ruleformats.nopet         = "nopet"
+    ruleformats.harm          = "target=target,harm"
+    ruleformats.help          = "target=target,help"
+    ruleformats.notarget      = "target=target,noexists"
+    ruleformats.focusharm     = "target=focus,harm"
+    ruleformats.focushelp     = "target=focus,help"
+    ruleformats.nofocus       = "target=focus,noexists"
+    ruleformats.raid          = "group:raid"
+    ruleformats.party         = "group:party"
+    ruleformats.solo          = "nogroup"
+    ruleformats.combat        = "combat"
+    ruleformats.nocombat      = "nocombat"
   end
-    -- TODO: need to find out if form name is localized, it probably is
-  local dStance = forms["Defensive Stance"] or 2
-  local zStance = forms["Berserker Stance"] or 3
-  local bForm   = forms["Dire Bear Form"] or forms["Bear Form"] or 1
-  local cForm   = forms["Cat Form"] or 3
-  local tForm   = forms["Tree of Life"] or forms["Moonkin Form"] or 5
-  local aForm   = forms["Aquatic Form"] or 2
-  local trForm  = forms["Travel Form"] or 4
-  local fForm   = forms["Flight Form"] or forms["Swift Flight Form"] or 6
 
-  -- TODO: do the macro conditional strings need to be localized?
-  --       they're not contained in GlobalStrings.lua, but the parsing is done
-  --       via the C function SecureCmdOptionParse(), so it's not clear
-  local ruleformats = { 
-    battle        = "stance:1",
-    defensive     = ("stance:%d"):format(dStance),
-    berserker     = ("stance:%d"):format(zStance),
-    caster        = ("form:0/%d/%d/%d"):format(aForm, trForm, fForm),
-    bear          = ("form:%d"):format(bForm),
-    cat           = ("form:%d"):format(cForm),
-    treeOrMoonkin = ("form:%d"):format(tForm),
-    stealth       = "stealth",
-    nostealth     = "nostealth",
-    shadowform    = "form:1",
-    noshadowform  = "noform",
-    pet           = "pet",
-    nopet         = "nopet",
-    harm          = "target=target,harm",
-    help          = "target=target,help",
-    notarget      = "target=target,noexists",
-    focusharm     = "target=focus,harm",
-    focushelp     = "target=focus,help",
-    nofocus       = "target=focus,noexists",
-    raid          = "group:raid",
-    party         = "group:party",
-    solo          = "nogroup",
-    combat        = "combat",
-    nocombat      = "nocombat",
-  }
-
-  function BuildRuleString(states)
+  local function BuildRuleString(states)
     local s = ""
     local default
     local sorted = { }
@@ -201,6 +164,54 @@
 end
 
 
+-- module event handlers
+function module:OnInitialize()
+  self.db = ReAction.db:RegisterNamespace( moduleID, 
+    {
+      profile = { 
+        bars = { },
+      }
+    }
+  )
+
+  InitRules()
+  self:RegisterEvent("PLAYER_AURAS_CHANGED")
+
+  ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
+
+  ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar")
+  ReAction.RegisterCallback(self, "OnRefreshBar")
+  ReAction.RegisterCallback(self, "OnEraseBar")
+  ReAction.RegisterCallback(self, "OnRenameBar")
+  ReAction.RegisterCallback(self, "OnConfigModeChanged")
+end
+
+function module:PLAYER_AURAS_CHANGED()
+  self:UnregisterEvent("PLAYER_AURAS_CHANGED")
+  -- for some classes the number of stances is 0 until this event fires
+  InitRules()
+end
+
+function module:OnRefreshBar(event, bar, name)
+  local c = self.db.profile.bars[name]
+  if c then
+    self:UpdateStates(bar)
+  end
+end
+
+function module:OnEraseBar(event, bar, name)
+  self.db.profile.bars[name] = nil
+end
+
+function module:OnRenameBar(event, bar, oldname, newname)
+  local b = self.db.profile.bars
+  bars[newname], bars[oldname] = bars[oldname], nil
+end
+
+function module:OnConfigModeChanged(event, mode)
+  -- TODO: unregister all state drivers (temporarily) and hidestates
+end
+
 
 -- API --