Mercurial > wow > reaction
comparison modules/State.lua @ 157:e77f716af1b7
Pushed state rule logic from State.lua to Bar.lua
author | Flick <flickerstreak@gmail.com> |
---|---|
date | Fri, 12 Jun 2009 21:44:44 +0000 |
parents | 806a61b331a0 |
children | 8cc187143acd |
comparison
equal
deleted
inserted
replaced
156:611e6ce08717 | 157:e77f716af1b7 |
---|---|
52 end) | 52 end) |
53 return r | 53 return r |
54 end | 54 end |
55 | 55 |
56 | 56 |
57 local InitRules, ApplyStates, CleanupStates, SetProperty, GetProperty, RegisterProperty | 57 local ApplyStates, CleanupStates, SetProperty, GetProperty, RegisterProperty |
58 | 58 |
59 -- PRIVATE -- | 59 -- PRIVATE -- |
60 do | 60 do |
61 | |
62 -- the field names must match the field names of the options table, below | |
63 -- the field values are secure snippets or 'true' to skip the snippet for that property. | |
64 local properties = { | |
65 hide = true, | |
66 --keybindState = true, TODO: broken | |
67 anchorEnable = true, | |
68 anchorFrame = true, | |
69 anchorPoint = true, | |
70 anchorRelPoint = true, | |
71 anchorX = true, | |
72 anchorY = true, | |
73 enableScale = true, | |
74 scale = true, | |
75 enableAlpha = true, | |
76 alpha = true, | |
77 } | |
78 | |
79 local playerClass = select(2, UnitClass("player")) | |
80 local function ClassFilter(...) | |
81 for i = 1, select('#',...) do | |
82 if playerClass == select(i,...) then | |
83 return false | |
84 end | |
85 end | |
86 return true | |
87 end | |
88 | |
89 -- As far as I can tell the macro clauses are NOT locale-specific. | |
90 -- 'filter' specifies whether rules should be omitted from execution. | |
91 -- 'true' indicates they should be filtered out. | |
92 local ruleformats = { | |
93 stealth = { format = "stealth", filter = ClassFilter("ROGUE","DRUID") }, | |
94 nostealth = { format = "nostealth", filter = ClassFilter("ROGUE","DRUID") }, | |
95 shadowform = { format = "form:1", filter = ClassFilter("PRIEST") }, | |
96 noshadowform = { format = "noform", filter = ClassFilter("PRIEST") }, | |
97 battle = { format = "stance:1", filter = ClassFilter("WARRIOR") }, | |
98 defensive = { format = "stance:2", filter = ClassFilter("WARRIOR") }, | |
99 berserker = { format = "stance:3", filter = ClassFilter("WARRIOR") }, | |
100 caster = { format = "form:0/2/4/5/6", filter = ClassFilter("DRUID") }, | |
101 bear = { format = "form:1", filter = ClassFilter("DRUID") }, | |
102 cat = { format = "form:3", filter = ClassFilter("DRUID") }, | |
103 tree = { format = "form:5", filter = ClassFilter("DRUID") }, | |
104 moonkin = { format = "form:5", filter = ClassFilter("DRUID") }, | |
105 pet = { format = "pet" }, | |
106 nopet = { format = "nopet" }, | |
107 harm = { format = "target=target,harm" }, | |
108 help = { format = "target=target,help" }, | |
109 notarget = { format = "target=target,noexists" }, | |
110 focusharm = { format = "target=focus,harm" }, | |
111 focushelp = { format = "target=focus,help" }, | |
112 nofocus = { format = "target=focus,noexists" }, | |
113 raid = { format = "group:raid" }, | |
114 party = { format = "group:party" }, | |
115 solo = { format = "nogroup" }, | |
116 combat = { format = "combat" }, | |
117 nocombat = { format = "nocombat" }, | |
118 possess = { format = "bonusbar:5" }, | |
119 vehicle = { format = "target=vehicle,exists,bonusbar:5" }, | |
120 } | |
121 | |
122 -- Determine the stance #'s programmatically: they can vary if for some reason the | |
123 -- player is missing a stance/form (due to not training it). Also moonkin/flight/tree form | |
124 -- can be stance 5 or 6, depending. | |
125 function InitRules() | |
126 local forms = { } | |
127 for i = 1, GetNumShapeshiftForms() do | |
128 local _, name = GetShapeshiftFormInfo(i) | |
129 forms[name] = i; | |
130 end | |
131 -- use 9 if not found since 9 is never a valid stance/form | |
132 local defensive = forms[GetSpellInfo(71)] or 9 | |
133 local berserker = forms[GetSpellInfo(2458)] or 9 | |
134 local bear = forms[GetSpellInfo(9634)] or forms[GetSpellInfo(5487)] or 9 | |
135 local aquatic = forms[GetSpellInfo(1066)] or 9 | |
136 local cat = forms[GetSpellInfo(768)] or 9 | |
137 local travel = forms[GetSpellInfo(783)] or 9 | |
138 local tree = forms[GetSpellInfo(33891)] or 9 | |
139 local moonkin = forms[GetSpellInfo(24858)] or 9 | |
140 local flight = forms[GetSpellInfo(40120)] or forms[GetSpellInfo(33943)] or 9 | |
141 | |
142 ruleformats.defensive.format = format("stance:%d",defensive) | |
143 ruleformats.berserker.format = format("stance:%d",berserker) | |
144 ruleformats.caster.format = format("form:0/%d/%d/%d", aquatic, travel, flight) | |
145 ruleformats.bear.format = format("form:%d",bear) | |
146 ruleformats.cat.format = format("form:%d",cat) | |
147 ruleformats.tree.format = format("form:%d",tree) | |
148 ruleformats.moonkin.format = format("form:%d",moonkin) | |
149 end | |
150 | |
151 local function BuildRule(states) | |
152 local rules = { } | |
153 local default | |
154 | |
155 for idx, state in ipairs(fieldsort(states, "rule", "order")) do | |
156 local c = states[state].rule | |
157 local type = c.type | |
158 if type == "default" then | |
159 default = default or state | |
160 elseif type == "custom" then | |
161 if c.custom then | |
162 -- strip out all spaces from the custom rule | |
163 table.insert(rules, format("%s %s", c.custom:gsub("%s",""), state)) | |
164 end | |
165 elseif type == "any" or type == "all" then | |
166 if c.values then | |
167 local clauses = { } | |
168 for key, value in pairs(c.values) do | |
169 if ruleformats[key] and not ruleformats[key].filter then | |
170 table.insert(clauses, ruleformats[key].format) | |
171 end | |
172 end | |
173 if #clauses > 0 then | |
174 local sep = (type == "any") and "][" or "," | |
175 table.insert(rules, format("[%s] %s", table.concat(clauses,sep), state)) | |
176 end | |
177 end | |
178 end | |
179 end | |
180 -- make sure that the default, if any, is last | |
181 if default then | |
182 table.insert(rules, default) | |
183 end | |
184 return table.concat(rules,";") | |
185 end | |
186 | |
187 local function BuildKeybinds( bar, states ) | |
188 for name, state in pairs(states) do | |
189 local type = tfetch(state, "rule", "type") | |
190 if type == "keybind" then | |
191 local key = tfetch(state, "rule", "keybind") | |
192 bar:SetStateKeybind(key, name) | |
193 else | |
194 bar:SetStateKeybind(nil, name) -- this clears an existing keybind | |
195 end | |
196 end | |
197 end | |
198 | |
199 function GetProperty( bar, state, propname ) | 61 function GetProperty( bar, state, propname ) |
200 return tfetch(module.db.profile.bars, bar:GetName(), "states", state, propname) | 62 return tfetch(module.db.profile.bars, bar:GetName(), "states", state, propname) |
201 end | 63 end |
202 | 64 |
203 function SetProperty( bar, state, propname, value ) | 65 function SetProperty( bar, state, propname, value ) |
205 s[propname] = value | 67 s[propname] = value |
206 bar:SetSecureStateData(state, propname, value) | 68 bar:SetSecureStateData(state, propname, value) |
207 end | 69 end |
208 | 70 |
209 function RegisterProperty( propname, snippet ) | 71 function RegisterProperty( propname, snippet ) |
210 properties[propname] = true | |
211 for _, bar in ReAction:IterateBars() do | 72 for _, bar in ReAction:IterateBars() do |
212 local states = tfetch(module.db.profile.bars, bar:GetName(), "states") | |
213 if states then | |
214 for name, s in pairs(states) do | |
215 bar:SetSecureStateData(name, propname, s[propname]) | |
216 end | |
217 bar:SetStateDriver(BuildRule(states)) | |
218 end | |
219 if type(snippet) == "string" then | 73 if type(snippet) == "string" then |
220 bar:SetSecureStateExtension(propname,snippet) | 74 bar:SetSecureStateExtension(propname,snippet) |
221 end | 75 end |
76 ApplyStates(bar) | |
222 end | 77 end |
223 end | 78 end |
224 | 79 |
225 function UnregisterProperty( propname ) | 80 function UnregisterProperty( propname ) |
226 properties[propname] = nil | |
227 for _, bar in ReAction:IterateBars() do | 81 for _, bar in ReAction:IterateBars() do |
228 local states = tfetch(module.db.profile.bars, bar:GetName(), "states") | |
229 if states then | |
230 for name, s in pairs(states) do | |
231 bar:SetSecureStateData(name, propname, nil) | |
232 end | |
233 end | |
234 bar:SetStateDriver(BuildRule(states)) | |
235 bar:SetSecureStateExtension(propname,nil) | 82 bar:SetSecureStateExtension(propname,nil) |
83 ApplyStates(bar) | |
236 end | 84 end |
237 end | 85 end |
238 | 86 |
239 function ApplyStates( bar ) | 87 function ApplyStates( bar ) |
240 local states = tfetch(module.db.profile.bars, bar:GetName(), "states") | 88 local states = tfetch(module.db.profile.bars, bar:GetName(), "states") |
241 if states then | 89 if states then |
242 for propname in pairs(properties) do | 90 bar:SetStateDriver(states) |
243 for name, s in pairs(states) do | |
244 if propname == "anchorFrame" then | |
245 bar:SetFrameRef("anchor-"..name, _G[s.anchorFrame]) | |
246 else | |
247 bar:SetSecureStateData(name, propname, s[propname]) | |
248 end | |
249 end | |
250 end | |
251 BuildKeybinds(bar, states) | |
252 bar:SetStateDriver(BuildRule(states)) | |
253 end | 91 end |
254 end | 92 end |
255 | 93 |
256 function CleanupStates( bar ) | 94 function CleanupStates( bar ) |
257 bar:SetStateDriver(nil) | 95 bar:SetStateDriver(nil) |
288 | 126 |
289 function module:UPDATE_SHAPESHIFT_FORMS() | 127 function module:UPDATE_SHAPESHIFT_FORMS() |
290 -- Re-parse the rules table according to the new form list. | 128 -- Re-parse the rules table according to the new form list. |
291 -- This happens both at initial login (after PLAYER_ENTERING_WORLD) | 129 -- This happens both at initial login (after PLAYER_ENTERING_WORLD) |
292 -- as well as when gaining new abilities. | 130 -- as well as when gaining new abilities. |
293 InitRules() | 131 ReAction.Bar.InitRuleFormats() |
294 for _, bar in ReAction:IterateBars() do | 132 for _, bar in ReAction:IterateBars() do |
295 ApplyStates(bar) | 133 ApplyStates(bar) |
296 end | 134 end |
297 end | 135 end |
298 | 136 |
853 end | 691 end |
854 | 692 |
855 function StateHandler:SetAnchorFrame(info, value) | 693 function StateHandler:SetAnchorFrame(info, value) |
856 local f = _G[self._anchorframes[value]] | 694 local f = _G[self._anchorframes[value]] |
857 if f then | 695 if f then |
858 bar:SetFrameRef("anchor-"..self:GetName(), f) | 696 self.bar:SetFrameRef("anchor-"..self:GetName(), f) |
859 self:SetProp(info, f:GetName()) | 697 self:SetProp(info, f:GetName()) |
860 end | 698 end |
861 end | 699 end |
862 | 700 |
863 function StateHandler:SetAnchorPointProp(info, value) | 701 function StateHandler:SetAnchorPointProp(info, value) |