Mercurial > wow > reaction
comparison modules/State.lua @ 228:ad40cd3fc7e9
pull states config out of namespace
author | Flick |
---|---|
date | Mon, 21 Mar 2011 11:33:15 -0700 |
parents | 2e2abdaad2e5 |
children | b4c100011c75 |
comparison
equal
deleted
inserted
replaced
227:741c4f9b251e | 228:ad40cd3fc7e9 |
---|---|
56 local ApplyStates, CleanupStates, SetProperty, GetProperty, RegisterProperty | 56 local ApplyStates, CleanupStates, SetProperty, GetProperty, RegisterProperty |
57 | 57 |
58 -- PRIVATE -- | 58 -- PRIVATE -- |
59 do | 59 do |
60 function GetProperty( bar, state, propname ) | 60 function GetProperty( bar, state, propname ) |
61 return tfetch(module.db.profile.bars, bar:GetName(), "states", state, propname) | 61 return tfetch(bar:GetConfig(), "states", state, propname) |
62 end | 62 end |
63 | 63 |
64 function SetProperty( bar, state, propname, value ) | 64 function SetProperty( bar, state, propname, value ) |
65 local s = tbuild(module.db.profile.bars, bar:GetName(), "states", state) | 65 local s = tbuild(bar:GetConfig(), "states", state) |
66 s[propname] = value | 66 s[propname] = value |
67 bar:SetSecureStateData(state, propname, value) | 67 bar:SetSecureStateData(state, propname, value) |
68 end | 68 end |
69 | 69 |
70 function RegisterProperty( propname, snippet ) | 70 function RegisterProperty( propname, snippet ) |
82 ApplyStates(bar) | 82 ApplyStates(bar) |
83 end | 83 end |
84 end | 84 end |
85 | 85 |
86 function ApplyStates( bar ) | 86 function ApplyStates( bar ) |
87 local states = tfetch(module.db.profile.bars, bar:GetName(), "states") | 87 local states = tfetch(bar:GetConfig(), "states") |
88 if states then | 88 if states then |
89 bar:SetStateDriver(states) | 89 bar:SetStateDriver(states) |
90 end | 90 end |
91 end | 91 end |
92 | 92 |
113 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") | 113 ReAction:RegisterBarOptionGenerator(self, "GetBarOptions") |
114 | 114 |
115 ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar") | 115 ReAction.RegisterCallback(self, "OnCreateBar","OnRefreshBar") |
116 ReAction.RegisterCallback(self, "OnDestroyBar") | 116 ReAction.RegisterCallback(self, "OnDestroyBar") |
117 ReAction.RegisterCallback(self, "OnRefreshBar") | 117 ReAction.RegisterCallback(self, "OnRefreshBar") |
118 ReAction.RegisterCallback(self, "OnEraseBar") | |
119 ReAction.RegisterCallback(self, "OnRenameBar") | |
120 end | 118 end |
121 | 119 |
122 function module:OnEnable() | 120 function module:OnEnable() |
123 self:UPDATE_SHAPESHIFT_FORMS() -- it doesn't fire on a /reloadui | 121 self:UPDATE_SHAPESHIFT_FORMS() -- it doesn't fire on a /reloadui |
124 end | 122 end |
132 ApplyStates(bar) | 130 ApplyStates(bar) |
133 end | 131 end |
134 end | 132 end |
135 | 133 |
136 function module:OnRefreshBar(event, bar, name) | 134 function module:OnRefreshBar(event, bar, name) |
137 local c = self.db.profile.bars[name] | 135 ApplyStates(bar) |
138 if c then | |
139 ApplyStates(bar) | |
140 end | |
141 end | 136 end |
142 | 137 |
143 function module:OnDestroyBar(event, bar, name) | 138 function module:OnDestroyBar(event, bar, name) |
144 CleanupStates(bar) | 139 CleanupStates(bar) |
145 end | 140 end |
146 | 141 |
147 function module:OnEraseBar(event, bar, name) | |
148 self.db.profile.bars[name] = nil | |
149 end | |
150 | |
151 function module:OnRenameBar(event, bar, oldname, newname) | |
152 local bars = self.db.profile.bars | |
153 bars[newname], bars[oldname] = bars[oldname], nil | |
154 end | |
155 | 142 |
156 | 143 |
157 | 144 |
158 -- Options -- | 145 -- Options -- |
159 | 146 |
523 return opts.order | 510 return opts.order |
524 end | 511 end |
525 | 512 |
526 -- get reference to states table: even if the bar | 513 -- get reference to states table: even if the bar |
527 -- name changes the states table ref won't | 514 -- name changes the states table ref won't |
528 self.states = tbuild(module.db.profile.bars, bar:GetName(), "states") | 515 self.states = tbuild(bar:GetConfig(), "states") |
529 self.state = tbuild(self.states, opts.name) | 516 self.state = tbuild(self.states, opts.name) |
530 | 517 |
531 opts.order = self:GetRuleField("order") | 518 opts.order = self:GetRuleField("order") |
532 if opts.order == nil then | 519 if opts.order == nil then |
533 -- add after the highest | 520 -- add after the highest |
822 return opts | 809 return opts |
823 end | 810 end |
824 | 811 |
825 function module:GetBarOptions(bar) | 812 function module:GetBarOptions(bar) |
826 local private = { } | 813 local private = { } |
827 local states = tbuild(module.db.profile.bars, bar:GetName(), "states") | 814 local states = tbuild(bar:GetConfig(), "states") |
828 local options = { | 815 local options = { |
829 name = L["Dynamic State"], | 816 name = L["Dynamic State"], |
830 type = "group", | 817 type = "group", |
831 order = -1, | 818 order = -1, |
832 childGroups = "tree", | 819 childGroups = "tree", |