comparison Turok/Init.lua @ 6:a9b8b0866ece

clear out log jam
author Nenue
date Sun, 21 Feb 2016 08:32:53 -0500
parents
children
comparison
equal deleted inserted replaced
5:8a9a6637f082 6:a9b8b0866ece
1 --- ${PACKAGE_NAME}
2 -- @file-author@
3 -- @project-revision@ @project-hash@
4 -- @file-revision@ @file-hash@
5 -- Created: 12/28/2015 6:40 AM
6 --- Core load sequence goes here.
7 --@debug@
8 local ADDON, TurokEnv = ...
9 local _G = _G
10 --@end-debug@
11 --GLOBALS: Turok, LibStub, GetAddOnMetadata
12 local setmetatable, rawset, rawget, pairs, type, unpack, tostring, tinsert = setmetatable, rawset, rawget, pairs, type, unpack, tostring, table.insert
13 Turok = LibStub("AceAddon-3.0"):NewAddon('Turok', 'AceEvent-3.0', 'AceTimer-3.0', 'AceConsole-3.0')
14 Turok:SetDefaultModuleState(true)
15 TurokEnv.Addon = Turok
16 TurokEnv.LSM = LibStub("LibSharedMedia-3.0")
17 TurokEnv.LGIST = LibStub("LibGroupInSpecT-1.1")
18 local T = Turok
19 --@debug@
20 local print = function(...)
21 if _G.Devian and _G.DevianDB.workspace ~= 1 then
22 _G.print('DB', ...)
23 end
24 end
25 local cTypes = { ['function'] = 'FF9922', ['table'] = '00FFAA', ['number'] = '77FF00', ['string'] = '00AAFF', ['hl'] = 'FF0088', ['field'] = '00FFFF',
26 ['boolean'] = 'CC88FF', ['false'] = 'FF7700', ['true'] = '44FF66', ['nil'] = 'FFFF00',}
27
28 local Debuggers = {
29 cType = function(s) return '|cFF' .. tostring(cTypes[type(s)]) .. tostring(s) .. '|r' end,
30 cText = function(s) return '|cFF'..cTypes.string..tostring(s)..'|r' end,
31 cNum = function(n) return '|cFF'..cTypes.number .. tostring(n) .. '|r' end,
32 cWord = function(w) return '|cFF'..cTypes.table .. tostring(w) .. '|r' end,
33 cKey = function(k) return '|cFF'..cTypes.field .. tostring(k) .. '|r' end,
34 cPink = function(s) return '|cFF'..cTypes.hl .. tostring(s) .. '|r' end,
35 cBool = function(s) return '|cFF'..cTypes[tostring((not not s))] .. tostring(s) .. '|r' end,
36 }
37 for fname, func in pairs(Debuggers) do
38 _G[fname] = func
39 end
40 local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool
41 --@end-debug@
42
43 T.db = {}
44 T.versionString = GetAddOnMetadata("Turok", "Version")
45
46 function T:OnModuleCreated(mod)
47 if mod.events then
48 print('Module', unpack(mod.events))
49 end
50 end
51 --- RegisterEvent embedded to module tables
52 function T:RegisterCallback(event, func, ...)
53 if not T.dispatchQueue[event] then
54 T.dispatchQueue[event] = {}
55 end
56
57 if not T.dispatchQueue[event][T.ID] then
58 T.dispatchQueue[event][T.ID] = T:GetName()
59 end
60
61 if (type(func) == 'function') then
62 if type(T[event]) == 'function' then
63 local oldfunc = T[event]
64 T[event] = function(...)
65 oldfunc(...)
66 return func(...)
67 end
68 else
69 T[event] = func
70 end
71 end
72 --@debug@
73 print(cText('Adding listener for'), cKey(self:GetName()), cText('on'), cKey(event))--@end-debug@
74 end
75
76 --- Default settings base
77 T.defaults = {
78 char = {},
79
80 lefttext = {
81 parent = 2, -- in an overlay frame
82 anchor = 'LEFT',
83 anchorTo = 'LEFT',
84 size = 18,
85 x = 5, y = 0,
86 justifyH = 'LEFT',
87 justifyV = 'MIDDLE',
88 },
89
90 righttext = {
91 parent = 2, -- in an overlay frame
92 anchor = 'RIGHT',
93 anchorTo = 'RIGHT',
94 x = -5,
95 y = 0,
96 size = 18,
97 justifyH = 'RIGHT',
98 justifyV = 'MIDDLE',
99 },
100
101 alpha = 1,
102 alpha_ooc = 1,
103 alpha_fade_in = 0.2,
104 alpha_fade_out = 0.2,
105 border_color = {0,0,0,1},
106
107 background_color = {0,.0,0,1},
108 background_blend = 'BLEND',
109
110 foreground_texture = [[Interface\Addons\Turok\Media\statusbar\Minimalist.tga]],
111 foreground_color = {0,.475,.95,1},
112 foreground_blend = 'BLEND',
113
114 foreground_inset = 0,
115 padding = 2,
116 spacing = 0,
117 fill_direction = 'RIGHT',
118
119 anchor = 'CENTER', parent = 'UIParent', anchorTo = 'CENTER',
120 x = 0, y = 0,
121 inset = -3,
122 width = 250,
123 height = 100,
124 strata = 'LOW',
125 font = "Interface\\Addons\\Turok\\Media\\font\\ArchivoNarrow-Regular.ttf",
126 size = 14,
127 text_color = {1, 1, 1, 1},
128 justifyH = 'LEFT',
129 outline = 'OUTLINE',
130 combatFade = true,
131
132 battle_noise_start = [[Interface\Addons\Turok\Media\sound\Low_Beep-Public_D-136_hifi.mp3]],
133 battle_noise_end = [[Interface\Addons\Turok\Media\sound\Electro_-S_Bainbr-7955_hifi.mp3]],
134 }
135
136
137 T.events = {
138 'PLAY_MOVIE',
139 'PLAYER_TARGET_CHANGED',
140 'PLAYER_FOCUS_CHANGED',
141 'PLAYER_EQUIPMENT_CHANGED',
142 'PLAYER_REGEN_DISABLED',
143 'PLAYER_REGEN_ENABLED',
144 'SPELL_UDPATE_COOLDOWN',
145 'SPELL_UPDATE_USABLE',
146 'UNIT_AURA',
147 'UNIT_PET',
148 'UNIT_POWER_FREQUENT',
149 'UNIT_SPELL_HASTE',
150 'UNIT_SPELLCAST_SENT',
151 'UNIT_SPELLCAST_START',
152 'UNIT_SPELLCAST_DELAYED',
153 'UNIT_SPELLCAST_STOP',
154 'UNIT_SPELLCAST_CHANNEL_START',
155 'UNIT_SPELLCAST_CHANNEL_UPDATE',
156 'UNIT_SPELLCAST_CHANNEL_STOP',
157 'UNIT_SPELLCAST_FAILED',
158 'UNIT_SPELLCAST_INTERRUPTED',
159 'UNIT_SPELLCAST_INTERRUPTIBLE',
160 'UNIT_SPELLCAST_SUCCEEDED',
161 'UNIT_SPELLCAST_UNINTERRUPTIBLE',
162 }
163 T.previousSpec = {}
164 T.talents = { {}, {}}
165 T.changedTalents = {{}, {} }
166 T.talentInfo = {}
167 T.auras = {}
168 T.spells = {}
169 T.spellevent = {}
170 T.channeling = {}
171 T.casting = {}
172 T.sent = {}
173 T.prototype = {}
174 T.spellBook = {}
175 T.equipped = {}
176
177 --- player-restricted unit info and text representations
178 T.player = {}
179 T.playertext = {}
180 T.pet = {}
181
182 --- holds non-restricted unit information
183 T.unit = {
184 player = {},
185 target = {},
186 focus = {},
187 pet = {},
188 }
189
190 -- index of frames with conditional visual properties
191 T.control_regions = {}
192
193 -- index of frames generated by the lua
194 T.frames = {}
195
196 -- units
197 T.units = {}
198 T.unitsBySlot = {}
199 setmetatable(T.unitsBySlot, {__mode="v"})
200
201
202
203 T.TrueVal = function (self,k)
204 return rawget(self,k)
205 end
206 --- Sets an index hierarchy for db vars and propagates config dialog info
207 T.LinkTable = function (over, under, pname, cname)
208 local mt = {
209 __index = function(t,k)
210 if type(over[k]) ~= nil then
211 --t[k] = over[k]
212 --@debug@
213 --print('up-referencing '.. STACK_COLOR2 .. pname ..'|r.'.. STACK_COLOR3.. tostring(k)..'|r -> '.. STACK_COLOR3.. pname ..'.' .. cname .. '|r.'..STACK_COLORN.. tostring(k) ..'|r', over[k])--@end-debug@
214 end
215 return over[k]
216 end,
217 __newindex = function (t, k, v)
218 rawset(t,k,v)
219 if type(v) == 'table' then
220 --@debug@
221 --print('parenting '.. STACK_COLOR2.. pname ..'|r to created table '.. STACK_COLOR3.. cname ..'|r')--@end-debug@
222 T.LinkTable(under, v, pname, k)
223 end
224 end
225 }
226 --under.TrueVal = T.TrueVal
227 setmetatable(under, mt)
228 for k, v in pairs(under) do
229 if type(v) == 'table' then
230 --@debug@
231 --print('linking '..STACK_COLOR1.. pname ..'|r to '..STACK_COLOR2.. cname ..'|r')--@end-debug@
232 T.LinkTable(under, v, pname ..'.'.. cname, k)
233 end
234 end
235 end
236
237
238 --- Merges values of table B into table A, and copies over nested values of tables matching the keywords list
239 local masked = {name = true, virtual = true}
240 T.Config_Push = function(cvars, push , root, rkey)
241 local results = {}
242 root = root or cvars
243 for k, v in pairs(push) do
244 if not masked[k] then
245 if type(v) == 'table' and v ~= root then
246 cvars[k] = {}
247 T.Config_Push(cvars[k], v, root)
248 else
249 print(' |cFFFF0088B|r ', tostring(rkey)..'.'..cKey(k))
250 cvars[k] = v
251 tinsert(results, ' |cFFFF0088B|r '.. tostring(rkey)..'.'..cKey(k))
252 end
253 end
254 end
255 return cvars, results
256 end
257 T.Config_Merge = function(cvars, merge, root, rkey)
258 local diff = {}
259 root = root or cvars
260 rkey = rkey or '0'
261 for k, v in pairs(merge) do
262 if masked[k] or cvars[k] then
263 tinsert(diff, ' |cFF00FF00A|r '.. tostring(rkey)..'.'..cWord(k))
264 print(' |cFF00FF00A|r ', tostring(rkey)..'.'..cText(k), '=', cvars[k])
265 --cvars[k] = cvars[k]
266 else
267 if type(v) == 'table' then
268 if type(cvars[k]) == 'nil' then
269 cvars[k] = {}
270 end
271 if type(cvars[k]) == 'table' then
272 print(' |cFFFFFF00A+B|r '.. tostring(rkey)..'.'..cWord(k))
273 cvars[k] = T.Config_Merge(cvars[k], v, root, tostring(rkey)..'.'..tostring(k))
274 end
275 elseif cvars[k] == nil then
276 tinsert(diff, ' |cFFFF0088B|r '.. tostring(rkey)..'.'..cKey(k))
277 print(' |cFFFF0088B|r ', tostring(rkey)..'.'..cKey(k))
278 cvars[k] = v
279 else
280 tinsert(diff, ' |cFF00FF00A|r '.. tostring(rkey)..'.'..cWord(k))
281 print(' |cFF00FF00A|r ', tostring(rkey)..'.'..cWord(k))
282 --cvars[k] = cvars[k]
283 end
284 end
285 end
286 return cvars, diff
287 end