diff SkeletonKey/ActionTemplates.lua @ 62:04c23ceaf9e0

- fix taint caused by loading in combat
author Nenue
date Mon, 05 Sep 2016 14:56:38 -0400
parents 9eebce04e69b
children 2409fe9b81e1
line wrap: on
line diff
--- a/SkeletonKey/ActionTemplates.lua	Sun Aug 28 10:06:59 2016 -0400
+++ b/SkeletonKey/ActionTemplates.lua	Mon Sep 05 14:56:38 2016 -0400
@@ -110,19 +110,19 @@
   local command = target .. attributeName
   local baseName, iterative = attributeName, 1
   while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do
-    print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"')
+    --print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"')
     attributeName = baseName .. '_' .. iterative
     iterative = iterative + 1
   end
   if attributeName ~= baseName then
-    print(' * Creating|cFF00FF00', attributeName)
+    --print(' * Creating|cFF00FF00', attributeName)
   else
-    print(' * Re-using|cFF00FF00', attributeName)
+    --print(' * Re-using|cFF00FF00', attributeName)
   end
   kb.macros[attributeName] = {attributeValue, command}
 
 
-  print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName)
+  --print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName)
   return attributeName, attributeValue, command
 end
 
@@ -133,7 +133,7 @@
   for i = 5, #talentInfo do
     local command = CLICK_KEYBINDER_KEY.. talentInfo[2]
     SetBinding(talentInfo[i], command)
-    cprint(' **', talentInfo[i], '->', command)
+    --cprint(' **', talentInfo[i], '->', command)
     tinsert(cache, talentInfo[i])
   end
 end
@@ -151,33 +151,54 @@
   local key, macro = KeyBinderKey, KeyBinderMacro
   kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText )
 
+    local buttonTypeKey, buttonTypeValue = "*type-"..name, actionType
+    local buttonActionKey, buttonActionValue = "*"..actionType.."-"..name, actionID
+    local button = key
     if actionType == 'spell' then
-      key:SetAttribute("*type-"..name, actionType)
-      key:SetAttribute("*"..actionType.."-"..name, name)
+      buttonTypeKey = "*type-"..name
+      buttonTypeValue = actionType
+      buttonActionKey = "*"..actionType.."-"..name
+      buttonActionValue = name
     elseif actionType == 'item' then
-      key:SetAttribute("*type-"..name, actionType)
-      key:SetAttribute("*"..actionType.."-"..name, name)
+      buttonTypeKey = "*type-"..name
+      buttonTypeValue = actionType
+      buttonActionKey = "*"..actionType.."-"..name
+      buttonActionValue = actionID
     elseif actionType == 'macro' then
-      macro:SetAttribute("*macro-"..macroName, actionID)
+      button = macro
+      buttonTypeKey = "*macro-"..macroName
+      buttonTypeValue = actionID
+      buttonActionKey = nil
     else
-      macro:SetAttribute("*macrotext-"..macroName, macroText)
+      button = macro
+      buttonTypeKey = "*macrotext-"..macroName
+      buttonTypeValue = macroText
+      buttonActionKey = nil
     end
+
+    --cprint(actionType, actionID, name)
+    --cprint(button:GetName(), buttonTypeKey,'=', buttonTypeValue)
+    kb.SecureAttribute(button, buttonTypeKey, buttonTypeValue)
+    if buttonActionKey then
+      --cprint(button:GetName(), buttonActionKey,'=', buttonActionValue)
+      kb.SecureAttribute(button, buttonActionKey, buttonActionValue)
+    end
+
     local indexKey = actionType..'_'..actionID
-    cprint('Loading binding', indexKey)
     bindings[indexKey] = bindings[indexKey] or {}
     bindings[command] = bindings[indexKey]
     return bindings[indexKey], actionID
   end
 
   kb.ApplyBindings = function (profile)
-    cprint('binding profile', profile)
+    --cprint('binding profile', profile)
     for slot, data in pairs(profile.buttons) do
       kb.LoadBinding(unpack(data))
     end
 
     for key, command in pairs(profile.bindings) do
 
-      cprint(' *', key, '->', command)
+      --cprint(' *', key, '->', command)
 
       --_G.print('HotKey','loading', key, command)
       SetBinding(key, command)
@@ -191,7 +212,7 @@
       local func = kb.CacheTalentBinding
       local dest = kb.TalentBindings
       if dummy then
-        cprint('|cFFBBFF00Active:|r', dummy)
+        --cprint('|cFFBBFF00Active:|r', dummy)
         local macroName, spellName, actionType, actionID = unpack(talentInfo)
         local indexKey = actionType .. '_' .. actionID
         bindings[indexKey] = {}
@@ -199,7 +220,7 @@
         dest = kb.bindings[indexKey]
       else
 
-        cprint('|cFFFF4400Inactive:|r', talentInfo[2])
+        --cprint('|cFFFF4400Inactive:|r', talentInfo[2])
       end
       func(talentInfo, dest)
     end
@@ -208,7 +229,8 @@
 
   kb.ApplyAllBindings =function ()
     wipe(kb.TalentBindings)
-
+    wipe(kb.bindings)
+    kb:print('Loading binding profile', kb.profileName)
 
     -- reflect action key settings
     if GetCVarBool("ActionButtonUseKeyDown") then
@@ -255,7 +277,7 @@
       talentInfo.spellID = spellID
       kb.TalentCache[spellID] = talentInfo
       kb.TalentCache[talentName] = talentInfo
-      print('Talent ', row, col, spellID, talentName)
+      --print('Talent ', row, col, spellID, talentName)
     end
   end
   kb.talentsPushed = true
@@ -266,18 +288,18 @@
 kb.UpdateProfessionInfo = function()
   wipe(kb.ProfessionCache)
   local profs = {GetProfessions() }
-  print(GetProfessions())
+  --print(GetProfessions())
   local primaryNum = 0
   for i = 1, 6 do
     if profs[i] then
       local index = profs[i]
       local profName, texture, _, _, numSpells, spellOffset = GetProfessionInfo(index)
-      print(i, index, profName, numSpells, spellOffset)
+      --print(i, index, profName, numSpells, spellOffset)
       if not SECONDARY_PROFESSIONS[index] then
         primaryNum = primaryNum + 1
       end
       local profNum = SECONDARY_PROFESSIONS[index] or primaryNum
-      print(i, profNum)
+      --print(i, profNum)
 
 
       kb.ProfessionCache[profNum] = kb.ProfessionCache[profNum] or {}
@@ -301,7 +323,7 @@
         kb.ProfessionCache[i .. '_' .. j] = profInfo
         kb.ProfessionCache[spellName] = profInfo
         kb.ProfessionCache[spellID] = profInfo
-        print('  |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
+        --print('  |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
       end
     end
 
@@ -344,7 +366,7 @@
   end
 
   if PetHasSpellbook() then
-    print('PET SPELLBOOK')
+    --print('PET SPELLBOOK')
     local i = 1
     local specialNum = {}
     repeat
@@ -356,7 +378,7 @@
       if not isPassive then
         if spellName then
           kb.PetCache.spellslot[spellName] = {i, spellName, subText, spellID, texture}
-          print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
+          --print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
 
           if subText then
             -- make sure that pet specialization subtext maps correctly
@@ -378,7 +400,7 @@
                 macrotext = macrotext .. "/cast " .. spellName .. "\n"
               end
               kb.SecureAttribute(KeyBinderMacro, "*macrotext-petaction_"..subText.."_"..specialNum[subText], macrotext)
-              print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID,  texture, specialNum[subText])
+              --print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID,  texture, specialNum[subText])
             end
 
 
@@ -391,7 +413,7 @@
 
           if spellID then
             kb.PetCache.spell[i] = {spellID, spellName, subText}
-            print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
+            --print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
           end
         end
 
@@ -401,13 +423,13 @@
       i = i + 1
     until spellType == nil
   else
-    print('NO PET SPELLBOOK')
+    --print('NO PET SPELLBOOK')
     wipe(kb.PetCache.spell)
     wipe(kb.PetCache.spellslot)
   end
 
   if PetHasActionBar() then
-    print('PET ACTION BAR')
+    --print('PET ACTION BAR')
     for i = 1, 10 do
 
 
@@ -417,10 +439,10 @@
 
 
       end
-      print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
+      --print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
     end
   else
-    print('NO PET ACTION BAR')
+    --print('NO PET ACTION BAR')
     wipe(kb.PetCache.action)
   end
 
@@ -441,7 +463,7 @@
         kb.SystemBindings[key2] = command
       end
     else
-      print('ignoring action button binding', command)
+      --print('ignoring action button binding', command)
     end
   end
 end
@@ -466,7 +488,7 @@
 
   else
 
-    print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
+    --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
     target:SetAttribute(name, value)
   end
 end
@@ -476,7 +498,7 @@
     local args = tremove(kb.pendingAttributes)
     while args do
       local target, name, value = unpack(args)
-      print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
+      --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
       target:SetAttribute(name, value)
       args = tremove(kb.pendingAttributes)
     end
@@ -495,6 +517,6 @@
   local indexKey = actionType .. '_' .. actionID
   kb.bindings[indexKey] = bindings
 
-  print('|cFF00FF00'..indexKey..'|r = {', table.concat(bindings,', '), '}')
+  --print('|cFF00FF00'..indexKey..'|r = {', table.concat(bindings,', '), '}')
   tinsert(kb.ChangedBindings, {actionType, actionID})
 end
\ No newline at end of file