comparison ReAction.lua @ 25:bf997ea151ca

yet another attempt to add missing files
author Flick <flickerstreak@gmail.com>
date Fri, 07 Mar 2008 22:19:03 +0000
parents
children f1e838841ce1
comparison
equal deleted inserted replaced
24:9e1984088124 25:bf997ea151ca
1 --[[
2
3 ReAction Add-On main file.
4
5 Performs add-on and library initialization and setup.
6
7 --]]
8
9
10 -- 'ReAction' is exported as a global.
11 ReAction = AceLibrary("AceAddon-2.0"):new(
12 "AceModuleCore-2.0",
13 "AceEvent-2.0",
14 "AceDB-2.0"
15 )
16
17 local ReAction = ReAction
18 local L = AceLibrary("AceLocale-2.2"):new("ReAction")
19 local AceOO = AceLibrary("AceOO-2.0")
20
21
22 ReAction.revision = tonumber(("$Revision: 1 $"):match("%d+"))
23 ReAction.L = L
24
25 -- global variable strings for integration with WoW keybindings dialog (see bindings.xml)
26 BINDING_HEADER_REACTION = L["ReAction"]
27 BINDING_NAME_REACTION_TOGGLELOCK = L["Toggle ReAction Bar Lock"]
28 BINDING_NAME_REACTION_TOGGLEKEYBIND = L["ReAction Keybinding Mode"]
29
30 -- from AceAddon-2.0
31 function ReAction:OnInitialize()
32 self:RegisterDB("ReActionDB")
33 end
34
35 -- from AceAddon-2.0
36 function ReAction:OnEnable()
37
38 end
39
40 -- from AceAddon-2.0
41 function ReAction:OnDisable()
42
43 end
44
45 -- from AceDB-2.0
46 function ReAction:OnProfileEnable()
47
48 end
49
50 -- from AceDB-2.0
51 function ReAction:OnProfileDisable()
52
53 end
54
55 -- from AceModuleCore-2.0
56 function ReAction:OnModuleEnable(module)
57 -- this handles initialization ordering issues with ReAction_Bar
58 local barMod = self:GetModule("Bar")
59 if barMod and module.ApplyToBar then
60 for _, b in pairs(barMod.bars) do
61 if b then
62 module:ApplyToBar(b)
63 end
64 end
65 end
66 end
67
68 -- from AceModuleCore-2.0
69 function ReAction:OnModuleDisable(module)
70 local barMod = self:GetModule("Bar")
71 if barMod and module.RemoveFromBar then
72 for _, b in pairs(barMod.bars) do
73 if b then
74 module:RemoveFromBar(b)
75 end
76 end
77 end
78 end
79
80 --[[
81 Module API (see bar.lua for usage)
82
83 module:ApplyToBar(bar)
84 module:RemoveFromBar(bar)
85 module:RefreshBar(bar)
86 module:ApplyConfigMode(mode,listOfBars)
87 module:GetBarNameModifier(bar)
88 module:EraseBarConfig(barName)
89 ]]--
90
91
92 -- debugging
93 ReAction.debug = true
94 if ReAction.debug then
95 ReAction.print = function(msg)
96 DEFAULT_CHAT_FRAME:AddMessage(msg)
97 end
98 --seterrorhandler(ReAction.print)
99 else
100 ReAction.print = function() end
101 end
102
103
104 -- utility
105 local newTable, recycle, deepCopy, deepDelete, varName
106 do
107 local pool = setmetatable( { }, {__mode="kv"} )
108
109 function newTable(...)
110 local t = table.remove(pool) or { }
111 for i = 1, select('#',...), 2 do
112 local k = select(i,...)
113 local v = select(i+1,...)
114 if k and v then
115 t[k] = v
116 end
117 end
118 return t
119 end
120
121 function recycle(t)
122 if type(t) == "table" then
123 table.insert(pool,t)
124 end
125 end
126
127 function deepCopy( x )
128 if type(x) ~= "table" then
129 return x
130 end
131 local r = newTable()
132 for k,v in pairs(x) do
133 r[k] = deepCopy(v)
134 end
135 return r
136 end
137
138 function deepDelete( x )
139 if type(x) == "table" and x.IsObjectType == nil and not(AceOO.inherits(x,AceOO.Object)) then -- don't want to delete WoW or AceOO objects!
140 for k,v in pairs(x) do
141 x[k] = deepDelete(v)
142 end
143 recycle(x)
144 end
145 end
146
147 function varName(s)
148 return tostring(s):gsub("[^a-zA-Z0-9_]","_")
149 end
150
151 local u = setmetatable( { }, {__newindex = function(self,k,v) rawset(self,#self+1,v) ; rawset(self,k,v) end} )
152 u.deepCopy = deepCopy
153 u.deepDelete = deepDelete
154 u.newTable = newTable
155 u.recycle = recycle
156 u.varName = varName
157
158 ReAction.util = u
159 end
160
161 function ReAction:GetUtilFuncs()
162 return unpack(self.util)
163 end
164