annotate SkeletonKey/DynamicTypes.lua @ 17:500f9b2bd9ac

- for RegisterAction, use a function table instead of that if/then rats nest - consequently pet bar actions work now - unlocalize bindings data - activate keyslot input manually instead of on mouse over - activate checkbox to keep input mode active - dynamic buttons update in real time for petaction/talent/profession spells
author Nenue
date Sat, 30 Jul 2016 00:08:00 -0400
parents cdd387d39137
children 67db6b712bf3
rev   line source
Nenue@6 1 -- KrakTool
Nenue@16 2 -- DynamicTypes.lua
Nenue@6 3 -- Created: 7/28/2016 3:28 PM
Nenue@6 4 -- %file-revision%
Nenue@16 5 -- Logic related to dynamic handlers
Nenue@6 6 local kb, print = LibStub('LibKraken').register(KeyBinder, 'PlayerInfo')
Nenue@6 7
Nenue@15 8 local PET_SPECIAL_SUBTEXT = 'Special Ability'
Nenue@17 9 local SECONDARY_PROFESSIONS = {
Nenue@6 10 [5] = 3,
Nenue@6 11 [7] = 4,
Nenue@6 12 [9] = 5,
Nenue@6 13 [10] = 6
Nenue@6 14 }
Nenue@6 15
Nenue@6 16 kb.TalentCache = {}
Nenue@6 17 kb.ProfessionCache = {}
Nenue@6 18 kb.PetCache = {}
Nenue@6 19 kb.specInfo = {}
Nenue@6 20 kb.UpdateSpecInfo = function()
Nenue@6 21 kb.specInfo.id = GetSpecialization()
Nenue@6 22 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
Nenue@6 23 print('|cFF00FF00current spec:|r', kb.specInfo.id, 'of', GetNumSpecializations())
Nenue@6 24 end
Nenue@6 25
Nenue@6 26 kb.UpdateTalentInfo = function()
Nenue@6 27 if kb.talentsPushed then
Nenue@6 28 return
Nenue@6 29 end
Nenue@6 30 table.wipe(kb.TalentCache)
Nenue@6 31 for row =1, MAX_TALENT_TIERS do
Nenue@6 32 for col = 1, NUM_TALENT_COLUMNS do
Nenue@6 33 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
Nenue@6 34 local talentInfo = kb.TalentCache[spellID] or {}
Nenue@6 35 talentInfo.row = 1
Nenue@6 36 talentInfo.col = col
Nenue@6 37 talentInfo.name = talentName
Nenue@6 38 talentInfo.talentID = talentID
Nenue@6 39 talentInfo.selected = selected
Nenue@6 40 talentInfo.available = available
Nenue@6 41 talentInfo.spellID = spellID
Nenue@6 42 kb.TalentCache[spellID] = talentInfo
Nenue@13 43 kb.TalentCache[talentName] = talentInfo
Nenue@6 44 print('Talent ', row, col, spellID, talentName)
Nenue@6 45 end
Nenue@6 46 end
Nenue@6 47 kb.talentsPushed = true
Nenue@17 48
Nenue@17 49 kb.UpdateDynamicButtons('talent')
Nenue@6 50 end
Nenue@6 51
Nenue@6 52 kb.UpdateProfessionInfo = function()
Nenue@6 53 table.wipe(kb.ProfessionCache)
Nenue@6 54 local profs = {GetProfessions() }
Nenue@6 55 local primaryNum = 0
Nenue@6 56 for i, index in ipairs(profs) do
Nenue@6 57 local profName, texture, rank, maxRank, numSpells, spellOffset = GetProfessionInfo(index)
Nenue@6 58 print(i, index, profName, numSpells, spellOffset)
Nenue@17 59 if not SECONDARY_PROFESSIONS[index] then
Nenue@6 60 primaryNum = primaryNum + 1
Nenue@6 61 end
Nenue@17 62 local profNum = SECONDARY_PROFESSIONS[index] or primaryNum
Nenue@6 63
Nenue@6 64
Nenue@6 65 kb.ProfessionCache[profNum] = kb.ProfessionCache[i] or {}
Nenue@6 66
Nenue@6 67 for j = 1, numSpells do
Nenue@6 68 local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION)
Nenue@6 69
Nenue@6 70 local profInfo = {
Nenue@6 71 spellName = spellName,
Nenue@6 72 spellID = spellID,
Nenue@6 73 icon = icon,
Nenue@6 74 profOffset = i,
Nenue@6 75 profIndex = index,
Nenue@6 76 spellOffset = (spellOffset+j),
Nenue@6 77 spellNum = j
Nenue@6 78 }
Nenue@6 79 KeyBinderKey:SetAttribute("*type-profession_"..i .. '_' ..j, "spell")
Nenue@6 80 KeyBinderKey:SetAttribute("*spell-profession_"..i .. '_' ..j, spellName)
Nenue@6 81
Nenue@6 82 kb.ProfessionCache[i .. '_' .. j] = profInfo
Nenue@6 83 kb.ProfessionCache[spellName] = profInfo
Nenue@6 84 kb.ProfessionCache[spellID] = profInfo
Nenue@6 85 print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
Nenue@6 86 end
Nenue@6 87
Nenue@6 88 end
Nenue@6 89
Nenue@17 90 kb.UpdateDynamicButtons('profession')
Nenue@6 91 end
Nenue@6 92
Nenue@6 93
Nenue@15 94
Nenue@6 95 kb.UpdatePetInfo = function()
Nenue@15 96 kb.PetCache.spell = kb.PetCache.spell or {}
Nenue@15 97 kb.PetCache.spellslot = kb.PetCache.spellslot or {}
Nenue@15 98 kb.PetCache.action = kb.PetCache.action or {}
Nenue@15 99 kb.PetCache.special = kb.PetCache.action or {}
Nenue@15 100 local hasPetSpells, petType = HasPetSpells()
Nenue@15 101 if PetHasSpellbook() then
Nenue@15 102 print('PET SPELLBOOK')
Nenue@15 103 local i = 1
Nenue@15 104 local specialNum = 0
Nenue@15 105 repeat
Nenue@15 106
Nenue@15 107 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
Nenue@15 108 local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
Nenue@15 109 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
Nenue@15 110 if not isPassive then
Nenue@15 111 if spellName then
Nenue@15 112 kb.PetCache.spellslot[spellName] = {i, spellName, subText}
Nenue@15 113 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
Nenue@15 114
Nenue@15 115 if subText == PET_SPECIAL_SUBTEXT then
Nenue@15 116 specialNum = specialNum + 1
Nenue@15 117 kb.PetCache.special[spellName] = {i, specialNum, spellID, subText }
Nenue@15 118 print('|cFF00FFFFspecial['..spellName..']|r', '=>', i, specialNum, spellID, subText)
Nenue@15 119 end
Nenue@15 120
Nenue@15 121 if spellID then
Nenue@15 122 kb.PetCache.spell[i] = {spellID, spellName, subText}
Nenue@15 123 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
Nenue@15 124 end
Nenue@15 125 end
Nenue@15 126
Nenue@15 127
Nenue@15 128 end
Nenue@15 129
Nenue@15 130 i = i + 1
Nenue@15 131 until spellType == nil
Nenue@15 132 else
Nenue@15 133 print('NO PET SPELLBOOK')
Nenue@15 134 table.wipe(kb.PetCache.spell)
Nenue@15 135 table.wipe(kb.PetCache.spellslot)
Nenue@15 136 end
Nenue@15 137
Nenue@15 138 if PetHasActionBar() then
Nenue@15 139 print('PET ACTION BAR')
Nenue@15 140 for i = 1, 10 do
Nenue@15 141
Nenue@15 142
Nenue@15 143 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
Nenue@15 144 if name then
Nenue@15 145 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
Nenue@15 146
Nenue@15 147
Nenue@15 148 end
Nenue@15 149 print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
Nenue@15 150 end
Nenue@15 151 else
Nenue@15 152 print('NO PET ACTION BAR')
Nenue@15 153 table.wipe(kb.PetCache.action)
Nenue@15 154 end
Nenue@15 155
Nenue@17 156 kb.UpdateDynamicButtons('petaction')
Nenue@15 157
Nenue@15 158 end
Nenue@15 159
Nenue@15 160 kb.SystemBinds = {}
Nenue@15 161 kb.UpdateSystemBinds = function()
Nenue@15 162 table.wipe(kb.SystemBinds)
Nenue@15 163 local n = GetNumBindings()
Nenue@15 164 for i=1, n do
Nenue@15 165 local command, key1, key2 = GetBinding(i)
Nenue@15 166 if key1 then
Nenue@15 167 kb.SystemBinds[key1] = command
Nenue@15 168 end
Nenue@15 169 if key2 then
Nenue@15 170 kb.SystemBinds[key2] = command
Nenue@15 171 end
Nenue@15 172 end
Nenue@15 173
Nenue@15 174 end
Nenue@15 175
Nenue@17 176 kb.UpdateDynamicButtons = function(dynamicType)
Nenue@17 177 for i, button in ipairs(kb.buttons) do
Nenue@17 178 if button.isDynamic == dynamicType then
Nenue@17 179 kb.UpdateSlot(button, true)
Nenue@15 180 end
Nenue@15 181 end
Nenue@6 182 end