Nenue@6: -- KrakTool Nenue@16: -- DynamicTypes.lua Nenue@6: -- Created: 7/28/2016 3:28 PM Nenue@6: -- %file-revision% Nenue@16: -- Logic related to dynamic handlers Nenue@6: local kb, print = LibStub('LibKraken').register(KeyBinder, 'PlayerInfo') Nenue@6: Nenue@15: local PET_SPECIAL_SUBTEXT = 'Special Ability' Nenue@17: local SECONDARY_PROFESSIONS = { 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: 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: table.wipe(kb.TalentCache) 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@17: Nenue@17: kb.UpdateDynamicButtons('talent') 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@17: if not SECONDARY_PROFESSIONS[index] then Nenue@6: primaryNum = primaryNum + 1 Nenue@6: end Nenue@17: local profNum = SECONDARY_PROFESSIONS[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@17: kb.UpdateDynamicButtons('profession') 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@17: kb.UpdateDynamicButtons('petaction') 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@17: kb.UpdateDynamicButtons = function(dynamicType) Nenue@17: for i, button in ipairs(kb.buttons) do Nenue@17: if button.isDynamic == dynamicType then Nenue@17: kb.UpdateSlot(button, true) Nenue@15: end Nenue@15: end Nenue@6: end