comparison modules/ReAction_State/ReAction_State.lua @ 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
comparison
equal deleted inserted replaced
64:2000f4f4c6af 65:5ea65ec7d162
9 local _G = _G 9 local _G = _G
10 local InCombatLockdown = InCombatLockdown 10 local InCombatLockdown = InCombatLockdown
11 11
12 -- module declaration 12 -- module declaration
13 local moduleID = "State" 13 local moduleID = "State"
14 local module = ReAction:NewModule( moduleID ) 14 local module = ReAction:NewModule( moduleID, "AceEvent-3.0" )
15
16
17 -- module event handlers
18 function module:OnInitialize()
19 self.db = ReAction.db:RegisterNamespace( moduleID,
20 {
21 profile = {
22 bars = { },
23 }
24 }
25 )
26
27 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
28
29 ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar")
30 ReAction.RegisterCallback(self, "OnRefreshBar")
31 ReAction.RegisterCallback(self, "OnEraseBar")
32 ReAction.RegisterCallback(self, "OnRenameBar")
33 ReAction.RegisterCallback(self, "OnConfigModeChanged")
34 end
35
36 function module:OnRefreshBar(event, bar, name)
37 local c = self.db.profile.bars[name]
38 if c then
39 self:UpdateStates(bar)
40 end
41 end
42
43 function module:OnEraseBar(event, bar, name)
44 self.db.profile.bars[name] = nil
45 end
46
47 function module:OnRenameBar(event, bar, oldname, newname)
48 local b = self.db.profile.bars
49 bars[newname], bars[oldname] = bars[oldname], nil
50 end
51
52 function module:OnConfigModeChanged(event, mode)
53 -- TODO: unregister all state drivers (temporarily) and hidestates
54 end
55
56
57
58 15
59 -- Utility -- 16 -- Utility --
60 17
61 -- traverse a table tree by key list and fetch the result or first nil 18 -- traverse a table tree by key list and fetch the result or first nil
62 local function tfetch(t, ...) 19 local function tfetch(t, ...)
75 end 32 end
76 return t 33 return t
77 end 34 end
78 35
79 -- PRIVATE -- 36 -- PRIVATE --
80 local BuildRuleString, ApplyStates 37 local InitRules, ApplyStates
81 do 38 do
82 local forms = { } 39 local ruleformats = { }
83 for i = 1, GetNumShapeshiftForms() do 40
84 local icon, name = GetShapeshiftFormInfo(i) 41 function InitRules()
85 forms[name] = i; 42 local forms = { }
86 end 43 for i = 1, GetNumShapeshiftForms() do
87 -- TODO: need to find out if form name is localized, it probably is 44 local icon = GetShapeshiftFormInfo(i)
88 local dStance = forms["Defensive Stance"] or 2 45 forms[icon] = i;
89 local zStance = forms["Berserker Stance"] or 3 46 end
90 local bForm = forms["Dire Bear Form"] or forms["Bear Form"] or 1 47 -- sort by icon since it's locale-independent
91 local cForm = forms["Cat Form"] or 3 48 -- use 9 if not found since 9 is never a valid stance/form
92 local tForm = forms["Tree of Life"] or forms["Moonkin Form"] or 5 49 -- we do these shenanigans instead of hardcoding the stances because
93 local aForm = forms["Aquatic Form"] or 2 50 -- the ordering varies if the character is missing a form. For warriors
94 local trForm = forms["Travel Form"] or 4 51 -- this is rarely a problem but for druids it can be. Some people never bother
95 local fForm = forms["Flight Form"] or forms["Swift Flight Form"] or 6 52 -- to do the aquatic form quest, and stance 5 can be either flight or tree/boomkin
96 53 -- depending on talents.
97 -- TODO: do the macro conditional strings need to be localized? 54 local defensive = forms["Interface\\Icons\\Ability_Warrior_DefensiveStance"] or 9
98 -- they're not contained in GlobalStrings.lua, but the parsing is done 55 local berserker = forms["Interface\\Icons\\Ability_Racial_Avatar"] or 9
99 -- via the C function SecureCmdOptionParse(), so it's not clear 56 local bear = forms["Interface\\Icons\\Ability_Racial_BearForm"] or 9 -- bear and dire bear share the same icon
100 local ruleformats = { 57 local aquatic = forms["Interface\\Icons\\Ability_Druid_AquaticForm"] or 9
101 battle = "stance:1", 58 local cat = forms["Interface\\Icons\\Ability_Druid_CatForm"] or 9
102 defensive = ("stance:%d"):format(dStance), 59 local travel = forms["Interface\\Icons\\Ability_Druid_TravelForm"] or 9
103 berserker = ("stance:%d"):format(zStance), 60 local treekin = forms["Interface\\Icons\\Ability_Druid_TreeofLife"] or forms["Interface\\Icons\\Spell_Nature_ForceOfNature"] or 9
104 caster = ("form:0/%d/%d/%d"):format(aForm, trForm, fForm), 61 local flight = forms["Interface\\Icons\\Ability_Druid_FlightForm"] or 9 -- both flight and swift flight share the same icon
105 bear = ("form:%d"):format(bForm), 62
106 cat = ("form:%d"):format(cForm), 63 -- As far as I can tell the macro clauses are NOT locale-specific.
107 treeOrMoonkin = ("form:%d"):format(tForm), 64 ruleformats.battle = "stance:1"
108 stealth = "stealth", 65 ruleformats.defensive = ("stance:%d"):format(defensive)
109 nostealth = "nostealth", 66 ruleformats.berserker = ("stance:%d"):format(berserker)
110 shadowform = "form:1", 67 ruleformats.caster = ("form:0/%d/%d/%d"):format(aquatic, travel, flight)
111 noshadowform = "noform", 68 ruleformats.bear = ("form:%d"):format(bear)
112 pet = "pet", 69 ruleformats.cat = ("form:%d"):format(cat)
113 nopet = "nopet", 70 ruleformats.treeOrMoonkin = ("form:%d"):format(treekin)
114 harm = "target=target,harm", 71 ruleformats.stealth = "stealth"
115 help = "target=target,help", 72 ruleformats.nostealth = "nostealth"
116 notarget = "target=target,noexists", 73 ruleformats.shadowform = "form:1"
117 focusharm = "target=focus,harm", 74 ruleformats.noshadowform = "noform"
118 focushelp = "target=focus,help", 75 ruleformats.pet = "pet"
119 nofocus = "target=focus,noexists", 76 ruleformats.nopet = "nopet"
120 raid = "group:raid", 77 ruleformats.harm = "target=target,harm"
121 party = "group:party", 78 ruleformats.help = "target=target,help"
122 solo = "nogroup", 79 ruleformats.notarget = "target=target,noexists"
123 combat = "combat", 80 ruleformats.focusharm = "target=focus,harm"
124 nocombat = "nocombat", 81 ruleformats.focushelp = "target=focus,help"
125 } 82 ruleformats.nofocus = "target=focus,noexists"
126 83 ruleformats.raid = "group:raid"
127 function BuildRuleString(states) 84 ruleformats.party = "group:party"
85 ruleformats.solo = "nogroup"
86 ruleformats.combat = "combat"
87 ruleformats.nocombat = "nocombat"
88 end
89
90 local function BuildRuleString(states)
128 local s = "" 91 local s = ""
129 local default 92 local default
130 local sorted = { } 93 local sorted = { }
131 for name in pairs(states) do 94 for name in pairs(states) do
132 table.insert(sorted,name) 95 table.insert(sorted,name)
198 end 161 end
199 end 162 end
200 end 163 end
201 end 164 end
202 165
166
167 -- module event handlers
168 function module:OnInitialize()
169 self.db = ReAction.db:RegisterNamespace( moduleID,
170 {
171 profile = {
172 bars = { },
173 }
174 }
175 )
176
177 InitRules()
178 self:RegisterEvent("PLAYER_AURAS_CHANGED")
179
180 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions")
181
182 ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar")
183 ReAction.RegisterCallback(self, "OnRefreshBar")
184 ReAction.RegisterCallback(self, "OnEraseBar")
185 ReAction.RegisterCallback(self, "OnRenameBar")
186 ReAction.RegisterCallback(self, "OnConfigModeChanged")
187 end
188
189 function module:PLAYER_AURAS_CHANGED()
190 self:UnregisterEvent("PLAYER_AURAS_CHANGED")
191 -- for some classes the number of stances is 0 until this event fires
192 InitRules()
193 end
194
195 function module:OnRefreshBar(event, bar, name)
196 local c = self.db.profile.bars[name]
197 if c then
198 self:UpdateStates(bar)
199 end
200 end
201
202 function module:OnEraseBar(event, bar, name)
203 self.db.profile.bars[name] = nil
204 end
205
206 function module:OnRenameBar(event, bar, oldname, newname)
207 local b = self.db.profile.bars
208 bars[newname], bars[oldname] = bars[oldname], nil
209 end
210
211 function module:OnConfigModeChanged(event, mode)
212 -- TODO: unregister all state drivers (temporarily) and hidestates
213 end
203 214
204 215
205 -- API -- 216 -- API --
206 217
207 function module:UpdateStates( bar ) 218 function module:UpdateStates( bar )