Nenue@6: local _G, T = _G, Turok Nenue@6: local mod = T.modules.TimerControl Nenue@6: local P = mod.prototype Nenue@6: local GetInventoryItemID, GetItemInfo, GetInventoryItemTexture = GetInventoryItemID, GetItemInfo, GetInventoryItemTexture Nenue@6: local GetSpellDescription, GetSpellInfo, GetSpellCharges = GetSpellDescription, GetSpellInfo, GetSpellCharges Nenue@6: local tinsert, type, tonumber, pairs, ipairs, unpack = tinsert, type, tonumber, pairs, ipairs, unpack Nenue@6: local UnitGUID = UnitGUID Nenue@6: local GetTalentInfo, GetTalentInfoByID, GetItemSpell, PaperDoll_IsEquippedSlot = GetTalentInfo, GetTalentInfoByID, GetItemSpell, PaperDoll_IsEquippedSlot Nenue@6: --@debug@ Nenue@6: local DEBUG = true Nenue@6: --@end-debug@ Nenue@6: local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool Nenue@6: local print = function(...) Nenue@6: if not DEBUG then return end Nenue@6: if _G.Devian and _G.DevianDB.workspace ~= 1 then Nenue@6: _G.print('Timer', ...) Nenue@6: end Nenue@6: end Nenue@9: local tfprint = function(...) Nenue@9: if not DEBUG then return end Nenue@9: if _G.Devian and _G.DevianDB.workspace ~= 1 then Nenue@9: _G.print('TimerFocus', ...) Nenue@9: end Nenue@9: end Nenue@6: ------------------------------------------ Nenue@6: --- Parameter Prototypes Nenue@6: Nenue@6: local Timer_GetPrintHandler = function(self) Nenue@6: return self.trace and function(...) Nenue@6: print(...) Nenue@9: tfprint( ...) Nenue@6: end or print Nenue@6: end Nenue@6: Nenue@6: local Timer_UpdateIndex = function(self, key, value) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: -- sfk[value] = frame index key-value handle Nenue@6: -- mfkv = key-value frame index Nenue@6: -- mfkv[sfk[value]] = *frame Nenue@6: if self.frames[key] then Nenue@6: local sfk = self.frames[key] Nenue@6: -- for each unique value Nenue@6: for oldValue, index in pairs(sfk) do Nenue@6: local mfkv = mod.frames[key][oldValue] Nenue@6: -- for each offset after index Nenue@6: for i = index+1, #mfkv do Nenue@6: mfkv[i-1] = mfkv[i] -- slide it down Nenue@6: end Nenue@6: sfk[oldValue] = nil Nenue@6: print(cText(' *= self.frames')..'['..cKey(key)..']['..cNum(value)..'] =', cNum(self.frames[key][value])) Nenue@6: print(cText(' *= mod.frames')..'['..cKey(key)..']['..cNum(value)..']['..cNum(index)..'] =', cNum(self:GetName())) Nenue@6: end Nenue@6: else Nenue@6: self.frames[key] = {} Nenue@6: end Nenue@6: Nenue@6: if value then Nenue@6: local mfkv = mod.frames[key][value] Nenue@6: local sfk = self.frames[key] Nenue@6: mfkv[#mfkv+1] = self Nenue@6: sfk[value] = #mfkv Nenue@6: print(' *= self.frames['..cKey(key)..']['..cNum(value)..'] = ', sfk[value]) Nenue@6: end Nenue@6: end Nenue@6: Nenue@9: --- update conditional cvars (i.e. talentRow(5) pulls up column 3, so cvars.x = args[talentRow][3].x) Nenue@9: local Timer_SetAttributeValues = function(self, key, value) Nenue@9: print(' ', cKey(key), 'sub-value =', cNum(value)) Nenue@9: local sda = self.dvars.args Nenue@9: if sda and sda[key] then Nenue@9: print(cText(' conditional:')) Nenue@9: local dvals = (value and sda[key][value]) and sda[key][value] or sda[key].default Nenue@9: for k, v in pairs(dvals) do Nenue@9: print(cText(' '), 'cvars.'..cKey(k), '=', cWord(v)) Nenue@9: self.cvars[k] = v Nenue@9: end Nenue@9: end Nenue@9: end Nenue@9: Nenue@6: --- spellID Nenue@6: do Nenue@6: local spellID = P.status.spellID Nenue@6: spellID.Init = function(self, spellID) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: Nenue@6: if type(spellID) == 'table' then Nenue@6: spellID = spellID[T.specPage] Nenue@6: end Nenue@6: Nenue@6: -- May have changed if invoked through a slot assignment Nenue@6: if spellID ~= self.spellID then Nenue@6: self.spellID = spellID Nenue@6: self.charges, self.maxCharges, self.chargeStart, self.chargeDuration = GetSpellCharges(spellID) Nenue@6: self.spellDescription = GetSpellDescription(spellID) Nenue@6: self.spellName, self.spellRank, self.spellIcon, self.castingTime, self.minRange, self.maxRange = GetSpellInfo(spellID) Nenue@6: --@debug@ Nenue@6: print(' ', cWord('spellID ='), cKey(self.spellID), cNum(self.spellName), cText(self.spellDescription and '' or ''))--@end-debug@ Nenue@6: Nenue@6: Timer_UpdateIndex(self, 'spellID', spellID) Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: --- spellName Nenue@6: do Nenue@6: local spellName = P.status.spellName Nenue@6: spellName.Init = function(self, spellName) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: -- attempt to get spell info Nenue@6: local exists, _, _, _, _, _, spellID = GetSpellInfo(spellName) Nenue@6: if exists then Nenue@6: local charges, maxCharges, start, duration = GetSpellCharges(spellID or spellName) Nenue@6: Timer_UpdateIndex(self, 'spellName', nil) Nenue@6: print(' ', cKey("spellID"), '=', spellID) Nenue@6: P.status.spellID.Init(self, spellID) Nenue@6: else Nenue@6: print(' ', cPink("spellID"), '=', 'not sure') Nenue@6: Timer_UpdateIndex(self, 'spellID', nil) Nenue@6: Timer_UpdateIndex(self, 'spellName', spellName) Nenue@6: end Nenue@9: Timer_SetAttributeValues(self, 'spellName', spellID) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: Nenue@6: --- talentID Nenue@6: do Nenue@6: local talentID = P.status.talentID Nenue@6: local GetTalentInfoByID = GetTalentInfoByID Nenue@6: talentID.type = 'status' Nenue@6: talentID.Init = function(self, talentID) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: Nenue@6: self.talentID, self.spellName, self.spellIcon, self.talentSelected = GetTalentInfoByID(talentID, T.specGroup) Nenue@6: Nenue@6: if self.talentSelected then Nenue@6: print(' ', cKey("spellName"), '=', cWord(self.spellName)) Nenue@6: P.status.spellName.Init(self, self.spellName) Nenue@6: else Nenue@6: self.disable = true Nenue@6: self.debug_info ('Talent not selected.') Nenue@6: end Nenue@6: Nenue@6: print(' ', cKey('talentID ('..cNum(self.talentID)..', '..cNum(T.specGroup)..'):'), self.spellName, self.talentSelected ) Nenue@6: Timer_UpdateIndex(self, 'talentID', talentID) Nenue@9: Timer_SetAttributeValues(self, 'talentID', self.talentSelected and 1 or 'default') Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: --- talentRow - use whatever is in that row as data Nenue@6: do Nenue@6: local talentRow = P.status.talentRow Nenue@6: talentRow.Init = function(self, row) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: self.talentRow = row Nenue@9: local match Nenue@9: for i = 1, 3 do Nenue@9: local talentID, _, _, selected = GetTalentInfo(row, i, T.specGroup) Nenue@9: if selected then Nenue@9: P.status.talentID.Init(self, talentID) Nenue@9: match = i Nenue@9: end Nenue@9: end Nenue@9: Nenue@9: if not match then Nenue@6: self.disable = true Nenue@6: self.debug_info("No talent selected in target row.") Nenue@6: end Nenue@6: Timer_UpdateIndex(self, 'talentRow', row) Nenue@9: Timer_SetAttributeValues(self, 'talentRow', match) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: Nenue@6: --- talentOffset Nenue@6: do Nenue@6: local talentOffset = P.status.talentOffset Nenue@6: talentOffset.Init = function(self, coords) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: Nenue@6: local tier, column = unpack(coords) Nenue@6: Nenue@6: Nenue@6: local selected, usable, _ Nenue@6: self.talentID, self.spellName, self.spellIcon, selected, usable = GetTalentInfo(tier, column, T.specGroup) Nenue@6: print(' ', cKey('talentOffset'), '=', cNum(tier), cNum(column), self.spellName, selected, usable) Nenue@6: if not (selected and usable) then Nenue@6: self.disable = true Nenue@6: self.debug_info ((not usable) and 'Unavailable at current level.' or 'Talent not selected.') Nenue@6: end Nenue@6: Timer_UpdateIndex(self, 'talentID', self.talentID) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: --- specPage Nenue@6: do Nenue@6: local specPage = P.status.specPage Nenue@6: specPage.type = 'status' Nenue@6: specPage.Init = function(self, specPage) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: local match Nenue@6: if tonumber(specPage) then Nenue@6: match = specPage == T.specPage Nenue@6: elseif type(specPage) == 'table' then Nenue@6: for _, pageID in ipairs(specPage) do Nenue@6: if T.specPage == pageID then Nenue@6: specPage = pageID Nenue@6: match = true Nenue@6: break Nenue@6: end Nenue@6: end Nenue@6: else Nenue@6: self.disable = true Nenue@6: self.debug_info ('Bad value for', '('..cWord(self.timerName)..').'..cKey('specPage')) Nenue@6: Timer_UpdateIndex(self,'specPage', nil) Nenue@6: end Nenue@6: Nenue@6: if match then Nenue@6: print(' ', cKey('specPage'), '=', '['..cNum(specPage)..']') Nenue@6: Timer_UpdateIndex(self,'specPage', specPage) Nenue@6: else Nenue@6: print(' ', cKey('specPage'), '~=', '['..cNum(specPage)..']') Nenue@6: self.disable = true Nenue@6: self.debug_info('Not active spec.') Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: --- itemID Nenue@6: do Nenue@6: local itemID = P.status.itemID Nenue@6: itemID.type = 'status' Nenue@6: itemID.Init = function(self, item) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: Nenue@6: if not self.dvars.inventoryID then Nenue@6: self.itemID = item or self.dvars.itemID Nenue@6: self.itemType = self.dvars.itemType Nenue@6: else Nenue@6: self.itemID = item Nenue@6: end Nenue@6: Nenue@6: --@debug@ Nenue@6: --name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) or GetItemInfo("itemName") or GetItemInfo("itemLink") Nenue@6: if not self.itemID then Nenue@6: self.disable = true Nenue@6: self.debug_info ('bad itemID value') Nenue@6: end Nenue@6: Nenue@9: local spellName = GetItemSpell(self.itemID) Nenue@6: Nenue@9: if not spellName then Nenue@6: self.disable = true Nenue@9: self.debug_info('no spell detected') Nenue@9: if self.spellName then Nenue@9: self.spellName = nil Nenue@6: end Nenue@6: end Nenue@9: Nenue@9: Timer_UpdateIndex(self, 'spellName', spellName) Nenue@9: Timer_SetAttributeValues(self, 'itemID', spellName) Nenue@9: Nenue@6: print(' ', cKey('itemID'), cNum(self.itemID), self.isEquipped)--@end-debug@ Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: do Nenue@6: local inventoryID = P.status.inventoryID Nenue@6: inventoryID.type = 'status' Nenue@6: inventoryID.Init = function(self, slot) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: Nenue@6: self.inventoryID = slot Nenue@9: local itemID = GetInventoryItemID(self.dvars.unit, slot) Nenue@9: local name = GetItemInfo(itemID) Nenue@6: if not PaperDoll_IsEquippedSlot(slot) then Nenue@6: self.disable = true Nenue@6: self.debug_info('slot un-equipped') Nenue@6: return Nenue@6: end Nenue@6: Nenue@9: Timer_SetAttributeValues(self, 'inventoryID', itemID) Nenue@9: P.status.itemID.Init(self, itemID) Nenue@6: self.spellIcon = GetInventoryItemTexture(self.dvars.unit, slot) Nenue@6: print(' ', cKey('inventoryID'), '=', '{'..cNum(self.inventoryID).. ' -> '.. cNum(self.itemID or 'no-equip').. '}') Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: Nenue@6: --- unit Nenue@6: local unit = P.status.unit Nenue@6: unit.type = 'status' Nenue@6: unit.Init = function(self, unit) Nenue@6: local print = Timer_GetPrintHandler(self) Nenue@6: Nenue@6: self.unitGUID = UnitGUID(unit) Nenue@6: self.unit = unit Nenue@6: print(' ', cWord('unitGUID'), '=', cText(self.unitGUID)) Nenue@6: tinsert(mod.frames.unit[unit], self) Nenue@6: self.frames.unit = #mod.frames.unit[unit] Nenue@6: end