changeset 71:ca3118127e5e

- Talent change detection - Use stored assignments for inactive talent slots
author Nenue
date Fri, 06 Jan 2017 16:21:49 -0500
parents 131d9190db6b
children c48913c5924c
files ActionTemplates.lua BindingsFrame.lua KeyButton.lua
diffstat 3 files changed, 91 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/ActionTemplates.lua	Wed Dec 28 16:31:15 2016 -0500
+++ b/ActionTemplates.lua	Fri Jan 06 16:21:49 2017 -0500
@@ -156,14 +156,17 @@
       if not GetSpellInfo(actionID) then
         isAvailable = nil
       end
-      local dynamicInfo = kb.TalentCache[name] or kb.ProfessionCache[name]
+      local dynamicInfo = kb.DynamicSpells[name]
       if dynamicInfo then
-        cprint('|cFF00FFFFDynamicInfo:|r', name)
+        configTable.assignedKeys = configTable.assignedKeys or {GetBindingKey(configTable.command)}
+        cprint('|cFF00FFFFDynamicInfo:|r', dynamicInfo.dynamicType, table.concat(configTable.assignedKeys or {}, ','))
         for k, v in pairs(dynamicInfo) do
-          cprint(' --', k, v)
+          --cprint(' --', k, v)
           configTable[k] = v
         end
       end
+
+
     else
       if actionType ~= 'macro' then
         actionPrefix = '*macrotext-'
@@ -178,6 +181,7 @@
 
 
 
+
     if isAvailable then
       kb.SecureAttribute(button, "*type-"..attributeSuffix, specialButtonType or actionType)
       kb.SecureAttribute(button, actionKey, attributeValue)
@@ -189,15 +193,13 @@
     end
   end
 
+
   local usedSlots = {}
-  kb.ApplyBindings = function (profile)
-    cprint('|cFF0088FFApplyBindings()')
-    --cprint('binding profile', profile)
-
+  kb.UpgradeProfile = function(profile)
     wipe(usedSlots)
     for slot, configTable in pairs(profile.buttons) do
 
-
+      -- convert old style table
       if #configTable >= 1 then
         local command, name, icon, actionType, actionID, macroName, macroText, spellbookSlot, spellbookType = unpack(configTable)
 
@@ -221,6 +223,19 @@
           spellbookType = spellbookType,
           assignedKeys = assignedKeys
         }
+
+        local dynamic = kb.DynamicSpells[name]
+        if dynamic then
+          configTable.dynamicType = dynamic.dynamicType
+          configTable.dynamicIndex = dynamic.dynamicIndex
+          configTable.dynamicSubIndex = dynamic.dynamicSubIndex
+          configTable.dynamicID = dynamic.dynamicID
+          if configTable.dynamicType == 'talent' then
+            profile.talents[name] = configTable
+          end
+        end
+
+
         kb.currentProfile.buttons[slot] = configTable
       end
       if not configTable.actionID then
@@ -233,23 +248,10 @@
 
       usedSlots[configTable.actionName or configTable.actionID] = true
       usedSlots[configTable.command] = true
-
-      if kb.LoadBinding(configTable) then
-        configTable.isAvailable = true
-      end
     end
 
-    for key, command in pairs(profile.bindings) do
-      command = command:gsub('KeyBinder', 'SkeletonKey')
-      profile.bindings[key] = command
-      cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command)
-      SetBinding(key, command)
 
-      if commandActions[command] and not tContains(commandActions[command], key) then
-        tinsert(commandActions[command], key)
-      end
-    end
-
+    -- clean up legacy data
     for spellName, talentInfo in pairs(profile.talents) do
       if not usedSlots[spellName] then
         cprint('|cFFFF4400Unslotted talent', spellName)
@@ -269,7 +271,46 @@
         profile.commands[command] = nil
       end
     end
+  end
 
+  kb.ApplyBindings = function (profile)
+    cprint('|cFF0088FFApplyBindings()')
+    --cprint('binding profile', profile)
+
+    local version = profile.versionID or 0
+    if version < 310 then
+      kb.UpgradeProfile(profile)
+    end
+
+    -- do flat bindings to start
+    for key, command in pairs(profile.bindings) do
+      command = command:gsub('KeyBinder', 'SkeletonKey')
+      profile.bindings[key] = command
+      cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command)
+      SetBinding(key, command)
+      if commandActions[command] and not tContains(commandActions[command], key) then
+        tinsert(commandActions[command], key)
+      end
+    end
+
+    -- then buttons
+    for slot, configTable in pairs(profile.buttons) do
+      -- convert old style table
+      if kb.LoadBinding(configTable) then
+        local talent = profile.talents[configTable.actionName]
+        if talent then
+          configTable.assignedKeys = talent.assignedKeys
+        end
+        if not configTable.assignedKeys then
+          configTable.assignedKeys = {GetBindingKey(configTable.command) }
+        end
+        configTable.isAvailable = true
+        if configTable.dynamicType then
+          kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName)
+        end
+
+      end
+    end
   end
 
   kb.ApplyAllBindings =function ()
@@ -332,8 +373,6 @@
         talentInfo.dynamicSubIndex = col
         talentInfo.actionID = spellID
         talentInfo.isAvailable = selected
-        kb.TalentCache[spellID] = talentInfo
-        kb.TalentCache[talentName] = talentInfo
         kb.DynamicSpells[spellID] = talentInfo
         kb.DynamicSpells[talentName] = talentInfo
       end
@@ -353,8 +392,6 @@
         talentInfo.dynamicID = id
         talentInfo.actionID = spellID
         talentInfo.isAvailable = selected
-        kb.TalentCache[spellID] = talentInfo
-        kb.TalentCache[name] = talentInfo
         kb.DynamicSpells[spellID] = talentInfo
         kb.DynamicSpells[name] = talentInfo
       end
--- a/BindingsFrame.lua	Wed Dec 28 16:31:15 2016 -0500
+++ b/BindingsFrame.lua	Fri Jan 06 16:21:49 2017 -0500
@@ -510,17 +510,19 @@
     tinsert(self.assignedKeys, 1, binding)
   end
 
-  local talentInfo
-  if spellName and kb.TalentCache[spellName] then
+  local talentInfo = kb.DynamicSpells[spellName]
+  if spellName and talentInfo then
     print('store dynamicType talent')
-    talentInfo = {
-      macroName = self.macroName,
-      actionName = self.actionName,
-      actionType = self.actionType,
-      actionID = self.actionID,
-      assignedKeys = self.assignedKeys
-    }
-    kb.currentProfile.talents[spellName] = talentInfo
+    if talentInfo.dynamicType == 'talent' then
+      talentInfo = {
+        macroName = self.macroName,
+        actionName = self.actionName,
+        actionType = self.actionType,
+        actionID = self.actionID,
+        assignedKeys = self.assignedKeys
+      }
+      kb.currentProfile.talents[spellName] = talentInfo
+    end
   end
 
   for _, key in ipairs(self.assignedKeys) do
--- a/KeyButton.lua	Wed Dec 28 16:31:15 2016 -0500
+++ b/KeyButton.lua	Fri Jan 06 16:21:49 2017 -0500
@@ -356,16 +356,14 @@
         self.bindingText ='?'
       end
     elseif self.dynamicType == 'talent' then
-
       self.statusText = '|cFF00FFFF'.. TALENT .. '|r'
       if self.isAvailable then
         self.bindingText = kb.BindingString(GetBindingKey(self.command))
       else
-        if kb.TalentBindings[self.actionID] then
-          print(self.actionID, #kb.TalentBindings[self.actionID])
-          self.bindingText= kb.BindingString(unpack(kb.TalentBindings[self.actionID]))
-        end
 
+        print('|cFFFF4400', self.actionName, #self.assignedKeys, self.assignedKeys)
+        print(self.actionID)
+        self.bindingText= kb.BindingString(self.assignedKeys)
       end
     elseif self.dynamicType == 'petaction' then
       self.bindingText = kb.BindingString(GetBindingKey(self.command))
@@ -534,9 +532,9 @@
   end
   info.isAvailable = isAvailable
 
-  cprint('|cFF00FF88SpellDetails:|r', info.actionName, info.actionID, info.dynamicType)
+  cprint('|cFF00FF88SpellDetails:|r', info.actionName, info.actionID, info.dynamicType, info.isAvailable)
   for k,v in pairs(info) do
-    cprint(' ',k,v)
+    --cprint(' ',k,v)
     self[k] = v
   end
 
@@ -565,7 +563,7 @@
     if actionType == 'spell' then
       local info = SkeletonKey_GetSpellDetails(self)
       name, icon, actionType, actionID, macroName, macroText, pickupSlot, pickupBook = self.actionName, self.iconPath, self.actionType, self.actionID, self.macroName, self.macroText, self.spellbookSlot, self.spellbookType
-
+      self.isAvailable = info and info.isAvailable
     elseif actionType == 'petaction' then
       self.dynamicType = 'petaction'
       local specialType, specialNum = command:match(actionType..'_([%a%s]+)_(%d)')
@@ -642,6 +640,10 @@
     self:EnableKeyboard(true)
 
     -- this is done to keep legacy key-values from breaking algorithm assumptions
+    print(slotInfo.assignedKeys)
+    print(GetBindingKey(command))
+    self.assignedKeys = slotInfo.assignedKeys or {GetBindingKey(command)}
+
     local slotInfo = {
       command = command,
       actionName = name,
@@ -652,7 +654,11 @@
       macroText = macroText,
       spellbookSlot = pickupSlot,
       spellbookType = pickupBook,
-      assignedKeys = {GetBindingKey(command)}
+      assignedKeys = slotInfo.assignedKeys,
+      dynamicType = self.dynamicType,
+      dynamicID = self.dynamicID,
+      dynamicIndex = self.dynamicIndex,
+      dynamicSubIndex = self.dynamicSubIndex
     }
     kb.currentProfile.buttons[slot] = slotInfo
 
@@ -681,8 +687,7 @@
     kb.currentProfile.commands[command] = slot
   end
 
-
-
+  --self.assignedKeys = slotInfo.assignedKeys
   self.isBound = isBound
   self.pickupSlot = pickupSlot
   self.pickupBook = pickupBook