Nenue@6: -- KrakTool Nenue@6: -- Cache.lua Nenue@6: -- Created: 7/28/2016 3:28 PM Nenue@6: -- %file-revision% Nenue@6: -- Cached data regarding talent options, pet spells, etc. Nenue@6: local kb, print = LibStub('LibKraken').register(KeyBinder, 'PlayerInfo') Nenue@6: Nenue@15: local PET_SPECIAL_SUBTEXT = 'Special Ability' Nenue@6: local BINDING_TYPE_SPECIALIZATION = 3 Nenue@6: local BINDING_TYPE_CHARACTER = 2 Nenue@6: local BINDING_TYPE_GLOBAL = 1 Nenue@6: local professionMappings = { Nenue@6: [5] = 3, Nenue@6: [7] = 4, Nenue@6: [9] = 5, Nenue@6: [10] = 6 Nenue@6: } Nenue@6: Nenue@6: kb.TalentCache = {} Nenue@6: kb.ProfessionCache = {} Nenue@6: kb.PetCache = {} Nenue@6: kb.specInfo = {} Nenue@6: kb.UpdateSpecInfo = function() Nenue@6: kb.specInfo.id = GetSpecialization() Nenue@6: kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id) Nenue@6: kb.loadedProfiles[BINDING_TYPE_CHARACTER][kb.specInfo.id] = kb.InitProfile(kb.loadedProfiles[BINDING_TYPE_CHARACTER][kb.specInfo.id], { Nenue@6: specID = kb.specInfo.id}) Nenue@6: Nenue@6: kb.configHeaders[BINDING_TYPE_SPECIALIZATION] = kb.configTitle[BINDING_TYPE_SPECIALIZATION]:format(kb.specInfo.name) Nenue@6: kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION] = kb.loadedProfiles[BINDING_TYPE_CHARACTER][kb.specInfo.id] Nenue@14: kb.currentProfile = kb.loadedProfiles[kb.db.bindMode] Nenue@14: print('|cFF00FF00bindMode:|r', kb.db.bindMode) Nenue@6: Nenue@6: kb.profileOrder = {kb.loadedProfiles[BINDING_TYPE_GLOBAL], kb.loadedProfiles[BINDING_TYPE_CHARACTER], kb.loadedProfiles[BINDING_TYPE_SPECIALIZATION]} Nenue@6: Nenue@6: print('|cFF00FF00current spec:|r', kb.specInfo.id, 'of', GetNumSpecializations()) Nenue@6: end Nenue@6: Nenue@6: kb.UpdateTalentInfo = function() Nenue@6: if kb.talentsPushed then Nenue@6: return Nenue@6: end Nenue@6: Nenue@6: Nenue@6: table.wipe(kb.TalentCache) Nenue@6: Nenue@6: for row =1, MAX_TALENT_TIERS do Nenue@6: for col = 1, NUM_TALENT_COLUMNS do Nenue@6: local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1) Nenue@6: local talentInfo = kb.TalentCache[spellID] or {} Nenue@6: talentInfo.row = 1 Nenue@6: talentInfo.col = col Nenue@6: talentInfo.name = talentName Nenue@6: talentInfo.talentID = talentID Nenue@6: talentInfo.selected = selected Nenue@6: talentInfo.available = available Nenue@6: talentInfo.spellID = spellID Nenue@6: kb.TalentCache[spellID] = talentInfo Nenue@13: kb.TalentCache[talentName] = talentInfo Nenue@6: print('Talent ', row, col, spellID, talentName) Nenue@6: end Nenue@6: end Nenue@6: kb.talentsPushed = true Nenue@6: end Nenue@6: Nenue@6: kb.UpdateProfessionInfo = function() Nenue@6: table.wipe(kb.ProfessionCache) Nenue@6: local profs = {GetProfessions() } Nenue@6: local primaryNum = 0 Nenue@6: for i, index in ipairs(profs) do Nenue@6: local profName, texture, rank, maxRank, numSpells, spellOffset = GetProfessionInfo(index) Nenue@6: print(i, index, profName, numSpells, spellOffset) Nenue@6: if not professionMappings[index] then Nenue@6: primaryNum = primaryNum + 1 Nenue@6: end Nenue@6: local profNum = professionMappings[index] or primaryNum Nenue@6: Nenue@6: Nenue@6: kb.ProfessionCache[profNum] = kb.ProfessionCache[i] or {} Nenue@6: Nenue@6: for j = 1, numSpells do Nenue@6: local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION) Nenue@6: Nenue@6: local profInfo = { Nenue@6: spellName = spellName, Nenue@6: spellID = spellID, Nenue@6: icon = icon, Nenue@6: profOffset = i, Nenue@6: profIndex = index, Nenue@6: spellOffset = (spellOffset+j), Nenue@6: spellNum = j Nenue@6: } Nenue@6: KeyBinderKey:SetAttribute("*type-profession_"..i .. '_' ..j, "spell") Nenue@6: KeyBinderKey:SetAttribute("*spell-profession_"..i .. '_' ..j, spellName) Nenue@6: Nenue@6: kb.ProfessionCache[i .. '_' .. j] = profInfo Nenue@6: kb.ProfessionCache[spellName] = profInfo Nenue@6: kb.ProfessionCache[spellID] = profInfo Nenue@6: print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j) Nenue@6: end Nenue@6: Nenue@6: end Nenue@6: Nenue@6: end Nenue@6: Nenue@6: Nenue@15: Nenue@6: kb.UpdatePetInfo = function() Nenue@15: kb.PetCache.spell = kb.PetCache.spell or {} Nenue@15: kb.PetCache.spellslot = kb.PetCache.spellslot or {} Nenue@15: kb.PetCache.action = kb.PetCache.action or {} Nenue@15: kb.PetCache.special = kb.PetCache.action or {} Nenue@15: local hasPetSpells, petType = HasPetSpells() Nenue@15: if PetHasSpellbook() then Nenue@15: print('PET SPELLBOOK') Nenue@15: local i = 1 Nenue@15: local specialNum = 0 Nenue@15: repeat Nenue@15: Nenue@15: local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET) Nenue@15: local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET) Nenue@15: local isPassive = IsPassiveSpell(i, BOOKTYPE_PET) Nenue@15: if not isPassive then Nenue@15: if spellName then Nenue@15: kb.PetCache.spellslot[spellName] = {i, spellName, subText} Nenue@15: print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText) Nenue@15: Nenue@15: if subText == PET_SPECIAL_SUBTEXT then Nenue@15: specialNum = specialNum + 1 Nenue@15: kb.PetCache.special[spellName] = {i, specialNum, spellID, subText } Nenue@15: print('|cFF00FFFFspecial['..spellName..']|r', '=>', i, specialNum, spellID, subText) Nenue@15: end Nenue@15: Nenue@15: if spellID then Nenue@15: kb.PetCache.spell[i] = {spellID, spellName, subText} Nenue@15: print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText) Nenue@15: end Nenue@15: end Nenue@15: Nenue@15: Nenue@15: end Nenue@15: Nenue@15: i = i + 1 Nenue@15: until spellType == nil Nenue@15: else Nenue@15: print('NO PET SPELLBOOK') Nenue@15: table.wipe(kb.PetCache.spell) Nenue@15: table.wipe(kb.PetCache.spellslot) Nenue@15: end Nenue@15: Nenue@15: if PetHasActionBar() then Nenue@15: print('PET ACTION BAR') Nenue@15: for i = 1, 10 do Nenue@15: Nenue@15: Nenue@15: local name, subtext, texture, isToken, isActive = GetPetActionInfo(i) Nenue@15: if name then Nenue@15: kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive } Nenue@15: Nenue@15: Nenue@15: end Nenue@15: print('|cFFFFFF00action['..i..']|r', name, subtext, texture) Nenue@15: end Nenue@15: else Nenue@15: print('NO PET ACTION BAR') Nenue@15: table.wipe(kb.PetCache.action) Nenue@15: end Nenue@15: Nenue@15: kb.UpdateCacheButtons(kb.petFrames) Nenue@15: Nenue@15: end Nenue@15: Nenue@15: kb.SystemBinds = {} Nenue@15: kb.UpdateSystemBinds = function() Nenue@15: table.wipe(kb.SystemBinds) Nenue@15: local n = GetNumBindings() Nenue@15: for i=1, n do Nenue@15: local command, key1, key2 = GetBinding(i) Nenue@15: if key1 then Nenue@15: kb.SystemBinds[key1] = command Nenue@15: end Nenue@15: if key2 then Nenue@15: kb.SystemBinds[key2] = command Nenue@15: end Nenue@15: end Nenue@15: Nenue@15: end Nenue@15: Nenue@15: do Nenue@15: local garbage = {} Nenue@15: kb.UpdateCacheButtons = function(pending) Nenue@15: for i, button in ipairs(pending) do Nenue@15: if button.isDynamic then Nenue@15: print('flushing button', button:GetID()) Nenue@15: kb.UpdateSlot(button, true) Nenue@15: end Nenue@15: end Nenue@15: end Nenue@15: end Nenue@15: Nenue@15: Nenue@15: kb.RemoveCacheButton = function(pending, button) Nenue@15: local found Nenue@15: for index, frame in ipairs(pending) do Nenue@15: if button == frame then Nenue@15: found = index Nenue@15: break Nenue@15: end Nenue@15: end Nenue@15: if found then Nenue@15: print('|cFFFF4400pruning', button:GetName(), 'from update queue') Nenue@15: tremove(pending, found) Nenue@15: end Nenue@6: Nenue@6: end