diff 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
line wrap: on
line diff
--- a/SkeletonKey/Cache.lua	Thu Jul 28 23:58:53 2016 -0400
+++ b/SkeletonKey/Cache.lua	Fri Jul 29 03:27:15 2016 -0400
@@ -5,6 +5,7 @@
 -- Cached data regarding talent options, pet spells, etc.
 local kb, print = LibStub('LibKraken').register(KeyBinder, 'PlayerInfo')
 
+local PET_SPECIAL_SUBTEXT = 'Special Ability'
 local BINDING_TYPE_SPECIALIZATION = 3
 local BINDING_TYPE_CHARACTER = 2
 local BINDING_TYPE_GLOBAL = 1
@@ -103,6 +104,112 @@
 end
 
 
+
 kb.UpdatePetInfo = function()
+  kb.PetCache.spell = kb.PetCache.spell or {}
+  kb.PetCache.spellslot = kb.PetCache.spellslot or {}
+  kb.PetCache.action = kb.PetCache.action or {}
+  kb.PetCache.special = kb.PetCache.action or {}
+  local hasPetSpells, petType = HasPetSpells()
+  if PetHasSpellbook() then
+    print('PET SPELLBOOK')
+    local i = 1
+    local specialNum = 0
+    repeat
+
+      local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
+      local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
+      local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
+      if not isPassive then
+        if spellName then
+          kb.PetCache.spellslot[spellName] = {i, spellName, subText}
+          print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
+
+          if subText == PET_SPECIAL_SUBTEXT then
+            specialNum = specialNum + 1
+            kb.PetCache.special[spellName] = {i, specialNum, spellID, subText }
+            print('|cFF00FFFFspecial['..spellName..']|r', '=>', i, specialNum, spellID, subText)
+          end
+
+          if spellID then
+            kb.PetCache.spell[i] = {spellID, spellName, subText}
+            print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
+          end
+        end
+
+
+      end
+
+      i = i + 1
+    until spellType == nil
+  else
+    print('NO PET SPELLBOOK')
+    table.wipe(kb.PetCache.spell)
+    table.wipe(kb.PetCache.spellslot)
+  end
+
+  if PetHasActionBar() then
+    print('PET ACTION BAR')
+    for i = 1, 10 do
+
+
+      local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
+      if name then
+        kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
+
+
+      end
+      print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
+    end
+  else
+    print('NO PET ACTION BAR')
+    table.wipe(kb.PetCache.action)
+  end
+
+  kb.UpdateCacheButtons(kb.petFrames)
+
+end
+
+kb.SystemBinds = {}
+kb.UpdateSystemBinds = function()
+  table.wipe(kb.SystemBinds)
+  local n = GetNumBindings()
+  for i=1, n do
+    local command, key1, key2 = GetBinding(i)
+    if key1 then
+      kb.SystemBinds[key1] = command
+    end
+    if key2 then
+      kb.SystemBinds[key2] = command
+    end
+  end
+
+end
+
+do
+  local garbage = {}
+  kb.UpdateCacheButtons = function(pending)
+    for i, button in ipairs(pending) do
+      if button.isDynamic then
+        print('flushing button', button:GetID())
+          kb.UpdateSlot(button, true)
+      end
+    end
+  end
+end
+
+
+kb.RemoveCacheButton = function(pending, button)
+  local found
+  for index, frame in ipairs(pending) do
+    if button == frame then
+      found = index
+      break
+    end
+  end
+  if found then
+    print('|cFFFF4400pruning', button:GetName(), 'from update queue')
+    tremove(pending, found)
+  end
 
 end
\ No newline at end of file