changeset 62:04c23ceaf9e0

- fix taint caused by loading in combat
author Nenue
date Mon, 05 Sep 2016 14:56:38 -0400
parents b7be92f62b05
children 2409fe9b81e1
files LibKraken/LibKraken.lua SkeletonKey/ActionTemplates.lua SkeletonKey/Events.lua SkeletonKey/HotKey.lua SkeletonKey/KeyButton.lua
diffstat 5 files changed, 122 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/LibKraken/LibKraken.lua	Sun Aug 28 10:06:59 2016 -0400
+++ b/LibKraken/LibKraken.lua	Mon Sep 05 14:56:38 2016 -0400
@@ -68,6 +68,7 @@
 local Embed = function (target, template)
   for k,v in pairs(template) do
     if not target[k] then
+      print(tostring(target),'<-', k)
       target[k] = template[k]
     end
   end
@@ -287,61 +288,44 @@
 
 --- default OnEvent
 
-  local processing = false
+  local EmbedEventScript = function (handler)
+    if not handler.SetScript then
+       return
+    end
+    print('|cFF00FF88binding', handler:GetName())
+    -- enclose so .event can be overridden post-register
+    handler:SetScript('OnEvent', function(self, event,...)
+      print('|cFFFF4400' .. tostring(self) .. '|r', event, ...)
+      print(self.event)
+      print(self[event])
+      self.event(self, event, ...)
+    end)
+    handler.unhandled = 0
+    handler.missed = 0
+    handler.handled = 0
+    handler.firstEvent = false
+  end
+
+
   local isHandled = false
   local nodebug = false
-  defaultAddon.event = function (addon, event, ...)
-    if processing then
-      local args = {...}
-      C_Timer.After(0, function() LibKT_OnEvent(addon, event, unpack(args)) end)
-      return
-    else
-
-    end
+  defaultAddon.event = function (self, event, ...)
+    print('what')
     --- reset state
-    processing = true
-    isHandled = false
-    nodebug = false
-
-
-    if addon.event then
-      nodebug = addon.event(addon, event, ...)
-    elseif addon[event] then
-      nodebug = addon[event](addon, event, ...) or nodebug
-      addon.missed = 0
-      addon.handled = addon.handled + 1
+    if self[event] then
+      print('|cFFFFFF00'.. tostring(self) .. '|r', event)
+      print(self.debug)
+      self.debug(event, ...)
+      self[event](self, event, ...)
+      self.missed = 0
+      self.handled = self.handled + 1
       isHandled = true
     else
-      addon.firstEvent = false
-      addon.unhandled = addon.unhandled + 1
-      addon.missed = addon.missed + 1
+      self.firstEvent = false
+      self.unhandled = self.unhandled + 1
+      self.missed = self.missed + 1
     end
-
-    if addon.modules then
-      for i, module in ipairs(addon.modules) do
-        --print(i, module, event)
-        if module.event then
-          module.event(module, event, ...)
-        elseif module[event] then
-          nodebug = module[event](addon, event, ...) or nodebug
-          addon.missed = 0
-          addon.handled = addon.handled + 1
-          isHandled = true
-        else
-          addon.firstEvent = false
-          addon.unhandled = addon.unhandled + 1
-          addon.missed = addon.missed + 1
-        end
-      end
-    end
-    --if nodebug then
-    processing = false
     return
-    --else
-    --  KT.UpdateEventStatus(addon, event, ...)
-    --  processing = false
-    --end
-
   end
   defaultAddon.wrap = function(addon, module, name)
     local moduleName = name or tostring(module)
@@ -357,6 +341,11 @@
     else
       debuggers[module] = noFunc
     end
+    module.debug = debuggers[module]
+
+    Embed(module, defaultAddon)
+    EmbedEventScript(module)
+
     return debuggers[module]
   end
 
@@ -408,12 +397,12 @@
     name = tostring(handler)
     registeredHandles[handler] = name
     if handler.SetScript then
-      handler:SetScript('OnEvent', handler.event)
+      handler:SetScript('OnEvent', function(...) handler.event(...) end)
+      handler.unhandled = 0
+      handler.missed = 0
+      handler.handled = 0
+      handler.firstEvent = false
     end
-    handler.unhandled = 0
-    handler.missed = 0
-    handler.handled = 0
-    handler.firstEvent = false
     handler.modules = {}
     tinsert(KT.initStack, handler)
 
@@ -433,6 +422,8 @@
     debuggers[debugID] = debuggers[debugID] or function(...) _G.print(name, ...) end
     debugFunc = debuggers[debugID]
   end
+
+  handler.debug = debugFunc
   --@end-debug@
   return handler, debugFunc
 end
--- 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
--- a/SkeletonKey/Events.lua	Sun Aug 28 10:06:59 2016 -0400
+++ b/SkeletonKey/Events.lua	Mon Sep 05 14:56:38 2016 -0400
@@ -18,12 +18,6 @@
   kb:RegisterEvent('PLAYER_REGEN_ENABLED')
 end
 
-kb.event = function(event, ...)
-  if kb[event] then
-    kb[event](kb, event, ...)
-  end
-end
-
 kb.PLAYER_REGEN_DISABLED = function()
   kb:Hide()
 end
@@ -38,7 +32,7 @@
   kb.ui()
 end
 
-kb.PLAYER_SPECIALIZATION_CHANGED =  function()
+kb.PLAYER_SPECIALIZATION_CHANGED =  function(...)
   kb.UpdateSpecInfo()
   kb.UpdateTalentInfo()
   kb.SelectProfileSet(kb.profileName)
--- a/SkeletonKey/HotKey.lua	Sun Aug 28 10:06:59 2016 -0400
+++ b/SkeletonKey/HotKey.lua	Mon Sep 05 14:56:38 2016 -0400
@@ -31,11 +31,13 @@
   ["ACTIONBAR_SLOT_CHANGED"] = {"actionslot"},
   ["PLAYER_ENTERING_WORLD"] = {"world","all"},
   ["PET_UI_UPDATE"] = {"pet"},
+  ["PLAYER_SPECIALIZATION_CHANGED"] = {"player"},
+  ["PLAYER_TALENTS_UPDATED"] = {"player"},
 }
 
 
 hotkey.wrapEvent = function(event, ...)
-  kb:RegisterEvent(event)
+  hotkey:RegisterEvent(event)
   hotkeyEvents[event] = {...}
   hotkey[event] = hotkey.UpdateFromEvent
 end
@@ -63,7 +65,7 @@
     for i, func  in ipairs(hotkeyEvents[event]) do
 
       if hotkey[func] then
-        --print(' ', func)
+        print('->|cFF88FF00', func)
         hotkey[func](self, event, ...)
       end
     end
@@ -75,7 +77,8 @@
   print('variables')
   bindings = kb.GetBindings()
   for event, manifest in pairs(hotkeyEvents) do
-    kb:RegisterEvent(event)
+    print('-', event, table.concat(manifest, ', '))
+    hotkey:RegisterEvent(event)
     hotkey[event] = hotkey.UpdateFromEvent
   end
   hotkey.wrapEvent('UNIT_PET', 'pet')
@@ -90,40 +93,39 @@
 end
 
 hotkey.ui = function()
-  print('ui')
-  --hotkey.player()
-  --hotkey.pet()
+  hotkey.player()
+  hotkey.pet()
 end
 
 
 hotkey.world = function()
-  print('world')
+  -- needs to be delayed so it isn't fired 50 times at login
   hotkeyEvents["UPDATE_BINDINGS"] = {"binding"}
   hotkey.UPDATE_BINDINGS = hotkey.UpdateFromEvent
   hotkey:RegisterEvent("UPDATE_BINDINGS")
 
   hotkey.player()
   hotkey.pet()
-
 end
 
 -- requires all these arguments since non-actionbar buttons don't have all of said methods
+local kprint = (DEVIAN_WORKSPACE and function(...) _G.print('HotKeyUpdate', ...) end) or function() end
 hotkey.UpdateHotKey = function(frame, actionType, actionID, hasAction)
   bindings = kb.GetBindings()
 
   local indexKey = kb.FormatActionID(actionType, actionID)
-  print('|cFF00FFFFUpdate|r', frame, indexKey, hasAction)
+  --kprint(frame:GetName(), '|cFF88FF00'..indexKey..'|r',  hasAction)
 
 
   if bindings[indexKey] then
-    print('|cFFFFFF00'..frame:GetName(), actionType, actionID, hasAction)
+    kprint(' |cFFFF0088', actionType ..'|r', actionID, hasAction)
     local binds = bindings[indexKey]
     if binds and (not frame.HotKey:IsVisible()) then
       if hasAction then
         local bindingsText = kb.BindingString(unpack(binds))
 
         if not hotkeyText[frame] then
-          print('-new hotkey element')
+          kprint('-new hotkey element')
           hotkeyText[frame] = frame:CreateFontString(frame:GetName()..'SkeletonKey', 'OVERLAY')
           hotkeyText[frame]:SetFont(frame.HotKey:GetFont())
           hotkeyText[frame]:SetTextColor(frame.HotKey:GetTextColor())
@@ -136,7 +138,7 @@
 
         hotkeyText[frame]:SetText(bindingsText)
         hotkeyText[frame]:Show()
-        print('|cFF00FFFFUpdate text for', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r')
+        kprint('   |cFF00FFFF', frame:GetName(), '|cFFFFFF00'..tostring(bindingsText)..'|r')
 
         return
       end
@@ -145,7 +147,7 @@
 
   if hotkeyText[frame] then
     hotkeyText[frame]:SetText(nil)
-    --print('|cFFFF4400cleared text from', frame:GetName())
+    print('|cFFFF4400' .. frame:GetName() .. '|r', 'remove text')
   end
 end
 
@@ -160,6 +162,7 @@
       local actionType, actionID = GetActionInfo(slot)
       local hasAction = HasAction(slot)
       local indexKey = kb.FormatActionID(actionType, actionID)
+
       actionSlots[slot] = frame
       actionFrames[indexKey] = actionFrames[indexKey] or {}
       if not tContains(actionFrames[indexKey]) then
@@ -174,10 +177,14 @@
 
 hotkey.actionslot = function(self, event, slot)
   print(actionSlots[slot], event, slot, GetActionInfo(slot))
-  --print(GetActionButtonForID(slot))
   local atype, aid = GetActionInfo(slot)
   local indexKey = kb.FormatActionID(atype, aid)
   local frame = actionSlots[slot]
+  actionFrames[indexKey] = actionFrames[indexKey] or {}
+  if not tContains(actionFrames[indexKey]) then
+    tinsert(actionFrames[indexKey], frame)
+    actionIndex[slot] = indexKey
+  end
   if frame then
     hotkey.UpdateHotKey(frame, atype, aid, HasAction(slot))
   end
--- a/SkeletonKey/KeyButton.lua	Sun Aug 28 10:06:59 2016 -0400
+++ b/SkeletonKey/KeyButton.lua	Mon Sep 05 14:56:38 2016 -0400
@@ -143,7 +143,6 @@
     elseif actionType == 'item' then
       name = GetItemInfo(actionID)
       icon = GetItemIcon(actionID)
-      actionID = name
     elseif actionType == 'battlepet' then
 
       local speciesID, customName, level, xp, maxXp, displayID, isFavorite, petName, petIcon, petType, creatureID = GetPetInfoByPetID(actionID)