comparison SkeletonKey/Cache.lua @ 15:32d64e42ec9b

- resolve pet bar actions for binding slots - detect type of petaction (can be spell, stance, or 'PETACTION') - keep track of displayed pet ability slots and update them alongside pet cache refreshes
author Nenue
date Fri, 29 Jul 2016 03:27:15 -0400
parents 82170735e67c
children
comparison
equal deleted inserted replaced
14:82170735e67c 15:32d64e42ec9b
3 -- Created: 7/28/2016 3:28 PM 3 -- Created: 7/28/2016 3:28 PM
4 -- %file-revision% 4 -- %file-revision%
5 -- Cached data regarding talent options, pet spells, etc. 5 -- Cached data regarding talent options, pet spells, etc.
6 local kb, print = LibStub('LibKraken').register(KeyBinder, 'PlayerInfo') 6 local kb, print = LibStub('LibKraken').register(KeyBinder, 'PlayerInfo')
7 7
8 local PET_SPECIAL_SUBTEXT = 'Special Ability'
8 local BINDING_TYPE_SPECIALIZATION = 3 9 local BINDING_TYPE_SPECIALIZATION = 3
9 local BINDING_TYPE_CHARACTER = 2 10 local BINDING_TYPE_CHARACTER = 2
10 local BINDING_TYPE_GLOBAL = 1 11 local BINDING_TYPE_GLOBAL = 1
11 local professionMappings = { 12 local professionMappings = {
12 [5] = 3, 13 [5] = 3,
101 end 102 end
102 103
103 end 104 end
104 105
105 106
107
106 kb.UpdatePetInfo = function() 108 kb.UpdatePetInfo = function()
107 109 kb.PetCache.spell = kb.PetCache.spell or {}
108 end 110 kb.PetCache.spellslot = kb.PetCache.spellslot or {}
111 kb.PetCache.action = kb.PetCache.action or {}
112 kb.PetCache.special = kb.PetCache.action or {}
113 local hasPetSpells, petType = HasPetSpells()
114 if PetHasSpellbook() then
115 print('PET SPELLBOOK')
116 local i = 1
117 local specialNum = 0
118 repeat
119
120 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
121 local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
122 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
123 if not isPassive then
124 if spellName then
125 kb.PetCache.spellslot[spellName] = {i, spellName, subText}
126 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
127
128 if subText == PET_SPECIAL_SUBTEXT then
129 specialNum = specialNum + 1
130 kb.PetCache.special[spellName] = {i, specialNum, spellID, subText }
131 print('|cFF00FFFFspecial['..spellName..']|r', '=>', i, specialNum, spellID, subText)
132 end
133
134 if spellID then
135 kb.PetCache.spell[i] = {spellID, spellName, subText}
136 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
137 end
138 end
139
140
141 end
142
143 i = i + 1
144 until spellType == nil
145 else
146 print('NO PET SPELLBOOK')
147 table.wipe(kb.PetCache.spell)
148 table.wipe(kb.PetCache.spellslot)
149 end
150
151 if PetHasActionBar() then
152 print('PET ACTION BAR')
153 for i = 1, 10 do
154
155
156 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
157 if name then
158 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
159
160
161 end
162 print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
163 end
164 else
165 print('NO PET ACTION BAR')
166 table.wipe(kb.PetCache.action)
167 end
168
169 kb.UpdateCacheButtons(kb.petFrames)
170
171 end
172
173 kb.SystemBinds = {}
174 kb.UpdateSystemBinds = function()
175 table.wipe(kb.SystemBinds)
176 local n = GetNumBindings()
177 for i=1, n do
178 local command, key1, key2 = GetBinding(i)
179 if key1 then
180 kb.SystemBinds[key1] = command
181 end
182 if key2 then
183 kb.SystemBinds[key2] = command
184 end
185 end
186
187 end
188
189 do
190 local garbage = {}
191 kb.UpdateCacheButtons = function(pending)
192 for i, button in ipairs(pending) do
193 if button.isDynamic then
194 print('flushing button', button:GetID())
195 kb.UpdateSlot(button, true)
196 end
197 end
198 end
199 end
200
201
202 kb.RemoveCacheButton = function(pending, button)
203 local found
204 for index, frame in ipairs(pending) do
205 if button == frame then
206 found = index
207 break
208 end
209 end
210 if found then
211 print('|cFFFF4400pruning', button:GetName(), 'from update queue')
212 tremove(pending, found)
213 end
214
215 end