comparison Turok/Modules/Timer/Status.lua @ 6:a9b8b0866ece

clear out log jam
author Nenue
date Sun, 21 Feb 2016 08:32:53 -0500
parents
children 9400a0ff8540
comparison
equal deleted inserted replaced
5:8a9a6637f082 6:a9b8b0866ece
1 local _G, T = _G, Turok
2 local mod = T.modules.TimerControl
3 local P = mod.prototype
4 local GetInventoryItemID, GetItemInfo, GetInventoryItemTexture = GetInventoryItemID, GetItemInfo, GetInventoryItemTexture
5 local GetSpellDescription, GetSpellInfo, GetSpellCharges = GetSpellDescription, GetSpellInfo, GetSpellCharges
6 local GetTalentRowSelectionInfo = GetTalentRowSelectionInfo
7 local tinsert, type, tonumber, pairs, ipairs, unpack = tinsert, type, tonumber, pairs, ipairs, unpack
8 local UnitGUID = UnitGUID
9 local GetTalentInfo, GetTalentInfoByID, GetItemSpell, PaperDoll_IsEquippedSlot = GetTalentInfo, GetTalentInfoByID, GetItemSpell, PaperDoll_IsEquippedSlot
10 local print = function(...) print('Timer', ...) end
11 print('Peep!', ...)
12
13 --@debug@
14 local DEBUG = true
15 --@end-debug@
16 local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool
17 local print = function(...)
18 if not DEBUG then return end
19 if _G.Devian and _G.DevianDB.workspace ~= 1 then
20 _G.print('Timer', ...)
21 end
22 end
23 ------------------------------------------
24 --- Parameter Prototypes
25
26 local Timer_GetPrintHandler = function(self)
27 return self.trace and function(...)
28 print(...)
29 _G.print('TimerFocus', ...)
30 end or print
31 end
32
33 local Timer_UpdateIndex = function(self, key, value)
34 local print = Timer_GetPrintHandler(self)
35 -- sfk[value] = frame index key-value handle
36 -- mfkv = key-value frame index
37 -- mfkv[sfk[value]] = *frame
38 if self.frames[key] then
39 local sfk = self.frames[key]
40 -- for each unique value
41 for oldValue, index in pairs(sfk) do
42 local mfkv = mod.frames[key][oldValue]
43 -- for each offset after index
44 for i = index+1, #mfkv do
45 mfkv[i-1] = mfkv[i] -- slide it down
46 end
47 sfk[oldValue] = nil
48 print(cText(' *= self.frames')..'['..cKey(key)..']['..cNum(value)..'] =', cNum(self.frames[key][value]))
49 print(cText(' *= mod.frames')..'['..cKey(key)..']['..cNum(value)..']['..cNum(index)..'] =', cNum(self:GetName()))
50 end
51 else
52 self.frames[key] = {}
53 end
54
55 if value then
56 local mfkv = mod.frames[key][value]
57 local sfk = self.frames[key]
58 mfkv[#mfkv+1] = self
59 sfk[value] = #mfkv
60 print(' *= self.frames['..cKey(key)..']['..cNum(value)..'] = ', sfk[value])
61 end
62 end
63
64 --- spellID
65 do
66 local spellID = P.status.spellID
67 spellID.Init = function(self, spellID)
68 local print = Timer_GetPrintHandler(self)
69
70 if type(spellID) == 'table' then
71 spellID = spellID[T.specPage]
72 end
73
74 -- May have changed if invoked through a slot assignment
75 if spellID ~= self.spellID then
76 self.spellID = spellID
77 self.charges, self.maxCharges, self.chargeStart, self.chargeDuration = GetSpellCharges(spellID)
78 self.spellDescription = GetSpellDescription(spellID)
79 self.spellName, self.spellRank, self.spellIcon, self.castingTime, self.minRange, self.maxRange = GetSpellInfo(spellID)
80 --@debug@
81 print(' ', cWord('spellID ='), cKey(self.spellID), cNum(self.spellName), cText(self.spellDescription and '<desc>' or '<empty>'))--@end-debug@
82
83 Timer_UpdateIndex(self, 'spellID', spellID)
84 end
85 end
86 end
87
88 --- spellName
89 do
90 local spellName = P.status.spellName
91 spellName.Init = function(self, spellName)
92 local print = Timer_GetPrintHandler(self)
93 -- attempt to get spell info
94 local exists, _, _, _, _, _, spellID = GetSpellInfo(spellName)
95 if exists then
96 local charges, maxCharges, start, duration = GetSpellCharges(spellID or spellName)
97 Timer_UpdateIndex(self, 'spellName', nil)
98 print(' ', cKey("spellID"), '=', spellID)
99 P.status.spellID.Init(self, spellID)
100 else
101 print(' ', cPink("spellID"), '=', 'not sure')
102 Timer_UpdateIndex(self, 'spellID', nil)
103 Timer_UpdateIndex(self, 'spellName', spellName)
104 end
105 end
106 end
107
108
109 --- talentID
110 do
111 local talentID = P.status.talentID
112 local GetTalentInfoByID = GetTalentInfoByID
113 talentID.type = 'status'
114 talentID.Init = function(self, talentID)
115 local print = Timer_GetPrintHandler(self)
116
117 self.talentID, self.spellName, self.spellIcon, self.talentSelected = GetTalentInfoByID(talentID, T.specGroup)
118
119 if self.talentSelected then
120 print(' ', cKey("spellName"), '=', cWord(self.spellName))
121 P.status.spellName.Init(self, self.spellName)
122 else
123 self.disable = true
124 self.debug_info ('Talent not selected.')
125 end
126
127 print(' ', cKey('talentID ('..cNum(self.talentID)..', '..cNum(T.specGroup)..'):'), self.spellName, self.talentSelected )
128 Timer_UpdateIndex(self, 'talentID', talentID)
129
130 end
131 end
132
133 --- talentRow - use whatever is in that row as data
134 do
135 local talentRow = P.status.talentRow
136 talentRow.Init = function(self, row)
137 local print = Timer_GetPrintHandler(self)
138 self.talentRow = row
139 local noSelect, talentID = GetTalentRowSelectionInfo(row)
140 if noSelect then
141 self.disable = true
142 self.debug_info("No talent selected in target row.")
143 else
144 P.status.talentID.Init(self, talentID)
145 end
146 print(' ', cKey('talentRow ('.. cNum(row).. ') ='), talentID or 'none')
147 Timer_UpdateIndex(self, 'talentRow', row)
148 end
149 end
150
151
152 --- talentOffset
153 do
154 local talentOffset = P.status.talentOffset
155 talentOffset.Init = function(self, coords)
156 local print = Timer_GetPrintHandler(self)
157
158 local tier, column = unpack(coords)
159
160
161 local selected, usable, _
162 self.talentID, self.spellName, self.spellIcon, selected, usable = GetTalentInfo(tier, column, T.specGroup)
163 print(' ', cKey('talentOffset'), '=', cNum(tier), cNum(column), self.spellName, selected, usable)
164 if not (selected and usable) then
165 self.disable = true
166 self.debug_info ((not usable) and 'Unavailable at current level.' or 'Talent not selected.')
167 end
168 Timer_UpdateIndex(self, 'talentID', self.talentID)
169 end
170 end
171
172 --- specPage
173 do
174 local specPage = P.status.specPage
175 specPage.type = 'status'
176 specPage.Init = function(self, specPage)
177 local print = Timer_GetPrintHandler(self)
178 local match
179 if tonumber(specPage) then
180 match = specPage == T.specPage
181 elseif type(specPage) == 'table' then
182 for _, pageID in ipairs(specPage) do
183 if T.specPage == pageID then
184 specPage = pageID
185 match = true
186 break
187 end
188 end
189 else
190 self.disable = true
191 self.debug_info ('Bad value for', '('..cWord(self.timerName)..').'..cKey('specPage'))
192 Timer_UpdateIndex(self,'specPage', nil)
193 end
194
195 if match then
196 print(' ', cKey('specPage'), '=', '['..cNum(specPage)..']')
197 Timer_UpdateIndex(self,'specPage', specPage)
198 else
199 print(' ', cKey('specPage'), '~=', '['..cNum(specPage)..']')
200 self.disable = true
201 self.debug_info('Not active spec.')
202 end
203 end
204 end
205
206 --- itemID
207 do
208 local itemID = P.status.itemID
209 itemID.type = 'status'
210 itemID.Init = function(self, item)
211 local print = Timer_GetPrintHandler(self)
212
213 if not self.dvars.inventoryID then
214 self.itemID = item or self.dvars.itemID
215 self.itemType = self.dvars.itemType
216 else
217 self.itemID = item
218 end
219
220 --@debug@
221 --name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) or GetItemInfo("itemName") or GetItemInfo("itemLink")
222 if not self.itemID then
223 self.disable = true
224 self.debug_info ('bad itemID value')
225 end
226
227 self.spellName = GetItemSpell(self.itemID)
228
229 if not self.spellName then
230 self.disable = true
231 self.debug_info('no spell detected')
232 else
233 if not (self.frames.spellName and self.frames.spellName[self.spellName]) then
234 if not self.frames.spellName then
235 self.frames.spellName = {}
236 end
237
238 Timer_UpdateIndex(self, 'spellName', self.spellName)
239 end
240 end
241 print(' ', cKey('itemID'), cNum(self.itemID), self.isEquipped)--@end-debug@
242 end
243 end
244
245 do
246 local inventoryID = P.status.inventoryID
247 inventoryID.type = 'status'
248 inventoryID.Init = function(self, slot)
249 local print = Timer_GetPrintHandler(self)
250
251 self.inventoryID = slot
252 self.itemID = GetInventoryItemID(self.dvars.unit, slot)
253 local name = GetItemInfo(self.itemID)
254 if not PaperDoll_IsEquippedSlot(slot) then
255 self.disable = true
256 self.debug_info('slot un-equipped')
257 return
258 end
259
260 P.status.itemID.Init(self, self.itemID)
261 self.spellIcon = GetInventoryItemTexture(self.dvars.unit, slot)
262 print(' ', cKey('inventoryID'), '=', '{'..cNum(self.inventoryID).. ' -> '.. cNum(self.itemID or 'no-equip').. '}')
263 end
264 end
265
266
267 --- unit
268 local unit = P.status.unit
269 unit.type = 'status'
270 unit.Init = function(self, unit)
271 local print = Timer_GetPrintHandler(self)
272
273 self.unitGUID = UnitGUID(unit)
274 self.unit = unit
275 print(' ', cWord('unitGUID'), '=', cText(self.unitGUID))
276 tinsert(mod.frames.unit[unit], self)
277 self.frames.unit = #mod.frames.unit[unit]
278 end