diff ActionTemplates.lua @ 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
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