Mercurial > wow > turok
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Turok/Modules/Timer/Status.lua Sun Feb 21 08:32:53 2016 -0500 @@ -0,0 +1,278 @@ +local _G, T = _G, Turok +local mod = T.modules.TimerControl +local P = mod.prototype +local GetInventoryItemID, GetItemInfo, GetInventoryItemTexture = GetInventoryItemID, GetItemInfo, GetInventoryItemTexture +local GetSpellDescription, GetSpellInfo, GetSpellCharges = GetSpellDescription, GetSpellInfo, GetSpellCharges +local GetTalentRowSelectionInfo = GetTalentRowSelectionInfo +local tinsert, type, tonumber, pairs, ipairs, unpack = tinsert, type, tonumber, pairs, ipairs, unpack +local UnitGUID = UnitGUID +local GetTalentInfo, GetTalentInfoByID, GetItemSpell, PaperDoll_IsEquippedSlot = GetTalentInfo, GetTalentInfoByID, GetItemSpell, PaperDoll_IsEquippedSlot +local print = function(...) print('Timer', ...) end +print('Peep!', ...) + +--@debug@ +local DEBUG = true +--@end-debug@ +local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool +local print = function(...) + if not DEBUG then return end + if _G.Devian and _G.DevianDB.workspace ~= 1 then + _G.print('Timer', ...) + end +end +------------------------------------------ +--- Parameter Prototypes + +local Timer_GetPrintHandler = function(self) + return self.trace and function(...) + print(...) + _G.print('TimerFocus', ...) + end or print +end + +local Timer_UpdateIndex = function(self, key, value) + local print = Timer_GetPrintHandler(self) + -- sfk[value] = frame index key-value handle + -- mfkv = key-value frame index + -- mfkv[sfk[value]] = *frame + if self.frames[key] then + local sfk = self.frames[key] + -- for each unique value + for oldValue, index in pairs(sfk) do + local mfkv = mod.frames[key][oldValue] + -- for each offset after index + for i = index+1, #mfkv do + mfkv[i-1] = mfkv[i] -- slide it down + end + sfk[oldValue] = nil + print(cText(' *= self.frames')..'['..cKey(key)..']['..cNum(value)..'] =', cNum(self.frames[key][value])) + print(cText(' *= mod.frames')..'['..cKey(key)..']['..cNum(value)..']['..cNum(index)..'] =', cNum(self:GetName())) + end + else + self.frames[key] = {} + end + + if value then + local mfkv = mod.frames[key][value] + local sfk = self.frames[key] + mfkv[#mfkv+1] = self + sfk[value] = #mfkv + print(' *= self.frames['..cKey(key)..']['..cNum(value)..'] = ', sfk[value]) + end +end + +--- spellID +do + local spellID = P.status.spellID + spellID.Init = function(self, spellID) + local print = Timer_GetPrintHandler(self) + + if type(spellID) == 'table' then + spellID = spellID[T.specPage] + end + + -- May have changed if invoked through a slot assignment + if spellID ~= self.spellID then + self.spellID = spellID + self.charges, self.maxCharges, self.chargeStart, self.chargeDuration = GetSpellCharges(spellID) + self.spellDescription = GetSpellDescription(spellID) + self.spellName, self.spellRank, self.spellIcon, self.castingTime, self.minRange, self.maxRange = GetSpellInfo(spellID) + --@debug@ + print(' ', cWord('spellID ='), cKey(self.spellID), cNum(self.spellName), cText(self.spellDescription and '<desc>' or '<empty>'))--@end-debug@ + + Timer_UpdateIndex(self, 'spellID', spellID) + end + end +end + +--- spellName +do + local spellName = P.status.spellName + spellName.Init = function(self, spellName) + local print = Timer_GetPrintHandler(self) + -- attempt to get spell info + local exists, _, _, _, _, _, spellID = GetSpellInfo(spellName) + if exists then + local charges, maxCharges, start, duration = GetSpellCharges(spellID or spellName) + Timer_UpdateIndex(self, 'spellName', nil) + print(' ', cKey("spellID"), '=', spellID) + P.status.spellID.Init(self, spellID) + else + print(' ', cPink("spellID"), '=', 'not sure') + Timer_UpdateIndex(self, 'spellID', nil) + Timer_UpdateIndex(self, 'spellName', spellName) + end + end +end + + +--- talentID +do + local talentID = P.status.talentID + local GetTalentInfoByID = GetTalentInfoByID + talentID.type = 'status' + talentID.Init = function(self, talentID) + local print = Timer_GetPrintHandler(self) + + self.talentID, self.spellName, self.spellIcon, self.talentSelected = GetTalentInfoByID(talentID, T.specGroup) + + if self.talentSelected then + print(' ', cKey("spellName"), '=', cWord(self.spellName)) + P.status.spellName.Init(self, self.spellName) + else + self.disable = true + self.debug_info ('Talent not selected.') + end + + print(' ', cKey('talentID ('..cNum(self.talentID)..', '..cNum(T.specGroup)..'):'), self.spellName, self.talentSelected ) + Timer_UpdateIndex(self, 'talentID', talentID) + + end +end + +--- talentRow - use whatever is in that row as data +do + local talentRow = P.status.talentRow + talentRow.Init = function(self, row) + local print = Timer_GetPrintHandler(self) + self.talentRow = row + local noSelect, talentID = GetTalentRowSelectionInfo(row) + if noSelect then + self.disable = true + self.debug_info("No talent selected in target row.") + else + P.status.talentID.Init(self, talentID) + end + print(' ', cKey('talentRow ('.. cNum(row).. ') ='), talentID or 'none') + Timer_UpdateIndex(self, 'talentRow', row) + end +end + + +--- talentOffset +do + local talentOffset = P.status.talentOffset + talentOffset.Init = function(self, coords) + local print = Timer_GetPrintHandler(self) + + local tier, column = unpack(coords) + + + local selected, usable, _ + self.talentID, self.spellName, self.spellIcon, selected, usable = GetTalentInfo(tier, column, T.specGroup) + print(' ', cKey('talentOffset'), '=', cNum(tier), cNum(column), self.spellName, selected, usable) + if not (selected and usable) then + self.disable = true + self.debug_info ((not usable) and 'Unavailable at current level.' or 'Talent not selected.') + end + Timer_UpdateIndex(self, 'talentID', self.talentID) + end +end + +--- specPage +do + local specPage = P.status.specPage + specPage.type = 'status' + specPage.Init = function(self, specPage) + local print = Timer_GetPrintHandler(self) + local match + if tonumber(specPage) then + match = specPage == T.specPage + elseif type(specPage) == 'table' then + for _, pageID in ipairs(specPage) do + if T.specPage == pageID then + specPage = pageID + match = true + break + end + end + else + self.disable = true + self.debug_info ('Bad value for', '('..cWord(self.timerName)..').'..cKey('specPage')) + Timer_UpdateIndex(self,'specPage', nil) + end + + if match then + print(' ', cKey('specPage'), '=', '['..cNum(specPage)..']') + Timer_UpdateIndex(self,'specPage', specPage) + else + print(' ', cKey('specPage'), '~=', '['..cNum(specPage)..']') + self.disable = true + self.debug_info('Not active spec.') + end + end +end + +--- itemID +do + local itemID = P.status.itemID + itemID.type = 'status' + itemID.Init = function(self, item) + local print = Timer_GetPrintHandler(self) + + if not self.dvars.inventoryID then + self.itemID = item or self.dvars.itemID + self.itemType = self.dvars.itemType + else + self.itemID = item + end + + --@debug@ + --name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) or GetItemInfo("itemName") or GetItemInfo("itemLink") + if not self.itemID then + self.disable = true + self.debug_info ('bad itemID value') + end + + self.spellName = GetItemSpell(self.itemID) + + if not self.spellName then + self.disable = true + self.debug_info('no spell detected') + else + if not (self.frames.spellName and self.frames.spellName[self.spellName]) then + if not self.frames.spellName then + self.frames.spellName = {} + end + + Timer_UpdateIndex(self, 'spellName', self.spellName) + end + end + print(' ', cKey('itemID'), cNum(self.itemID), self.isEquipped)--@end-debug@ + end +end + +do + local inventoryID = P.status.inventoryID + inventoryID.type = 'status' + inventoryID.Init = function(self, slot) + local print = Timer_GetPrintHandler(self) + + self.inventoryID = slot + self.itemID = GetInventoryItemID(self.dvars.unit, slot) + local name = GetItemInfo(self.itemID) + if not PaperDoll_IsEquippedSlot(slot) then + self.disable = true + self.debug_info('slot un-equipped') + return + end + + P.status.itemID.Init(self, self.itemID) + self.spellIcon = GetInventoryItemTexture(self.dvars.unit, slot) + print(' ', cKey('inventoryID'), '=', '{'..cNum(self.inventoryID).. ' -> '.. cNum(self.itemID or 'no-equip').. '}') + end +end + + +--- unit +local unit = P.status.unit +unit.type = 'status' +unit.Init = function(self, unit) + local print = Timer_GetPrintHandler(self) + + self.unitGUID = UnitGUID(unit) + self.unit = unit + print(' ', cWord('unitGUID'), '=', cText(self.unitGUID)) + tinsert(mod.frames.unit[unit], self) + self.frames.unit = #mod.frames.unit[unit] +end \ No newline at end of file