Nenue@16: -- SkeletonKey Nenue@16: -- ActionTypes.lua Nenue@16: -- Created: 7/29/2016 9:14 PM Nenue@16: -- %file-revision% Nenue@16: -- Nenue@16: local kb, print, wrap = LibStub('LibKraken').register(KeyBinder) Nenue@17: local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end Nenue@16: Nenue@16: local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 Nenue@17: local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:" Nenue@17: local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:" Nenue@16: Nenue@16: local PETACTION_SCRIPT = { Nenue@16: [PET_ACTION_MOVE_TO] = {SLASH_PET_MOVE_TO1, 'pet_move_to'}, Nenue@16: [PET_ACTION_ATTACK] = {SLASH_PET_ATTACK1, 'pet_attack'}, Nenue@16: [PET_ACTION_FOLLOW] = {SLASH_PET_FOLLOW1, 'pet_follow'}, Nenue@16: [PET_ACTION_WAIT] = {SLASH_PET_STAY1, 'pet_stay'}, Nenue@16: [PET_MODE_AGGRESSIVE] = {SLASH_PET_AGGRESSIVE1, 'pet_aggressive'}, Nenue@16: [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'}, Nenue@16: [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'}, Nenue@16: [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'}, Nenue@16: } Nenue@16: Nenue@17: --- Caps Lock Nenue@16: local ACTION_HANDLERS = {} Nenue@16: ACTION_HANDLERS['mount'] = function(id, name) Nenue@17: if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then Nenue@17: return 'mount_random', "/script C_MountJournal.SummonByID(0)", CLICK_KEYBINDER_MACRO Nenue@17: else Nenue@17: return 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", CLICK_KEYBINDER_MACRO Nenue@17: end Nenue@16: end Nenue@17: ACTION_HANDLERS['macro'] = function(id, name) Nenue@17: return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), id Nenue@17: end Nenue@17: ACTION_HANDLERS['equipset'] = function(id, name) Nenue@17: return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")" Nenue@17: end Nenue@17: ACTION_HANDLERS['spell'] = function(id, name) Nenue@17: local attributeName = name Nenue@17: if kb.ProfessionCache[id] then Nenue@17: attributeName = "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum Nenue@17: end Nenue@17: return CLICK_KEYBINDER_KEY, attributeName, name Nenue@17: end Nenue@17: ACTION_HANDLERS['petaction'] = function(_, name) Nenue@17: -- ID doesn't exist for basic commands, even though they can be picked up Nenue@17: local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name) Nenue@17: if PETACTION_SCRIPT[name] then Nenue@17: attributeValue, attributeName = unpack(PETACTION_SCRIPT[name]) Nenue@17: end Nenue@17: Nenue@17: return CLICK_KEYBINDER_MACRO, attributeName, attributeValue Nenue@16: end Nenue@16: Nenue@17: ACTION_HANDLERS['battlepet'] = function(id, name) Nenue@17: return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name) Nenue@17: end Nenue@17: ACTION_HANDLERS['item'] = function(id, name) Nenue@17: return CLICK_KEYBINDER_KEY, 'item_' .. tostring(name), id Nenue@17: end Nenue@16: Nenue@16: Nenue@17: --- Resolves the SecureActionButton attribute names used for the given action Nenue@16: kb.RegisterAction = function(actionType, id, name) Nenue@16: Nenue@17: assert(ACTION_HANDLERS[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`') Nenue@17: local target, attributeName, attributeValue = ACTION_HANDLERS[actionType](id, name) Nenue@17: Nenue@17: local command = target .. attributeName Nenue@17: local baseName, iterative = attributeName, 1 Nenue@17: while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do Nenue@17: print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"') Nenue@17: attributeName = baseName .. '_' .. iterative Nenue@17: iterative = iterative + 1 Nenue@17: end Nenue@17: if macroName ~= baseName then Nenue@17: print(' * Creating|cFF00FF00', macroName) Nenue@17: else Nenue@17: print(' * Re-using|cFF00FF00', macroName) Nenue@17: end Nenue@17: kb.macros[attributeName] = {attributeValue, command} Nenue@17: Nenue@17: Nenue@17: print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName) Nenue@17: return attributeName, attributeValue, command Nenue@17: end Nenue@17: Nenue@17: Nenue@17: Nenue@17: Nenue@17: kb.inactiveTalentBindings = {} Nenue@17: kb.ApplyTalentBinding = function(talentInfo, cache) Nenue@17: for i = 5, #talentInfo do Nenue@17: local command = CLICK_KEYBINDER_KEY.. talentInfo[2] Nenue@17: SetBinding(talentInfo[i], command) Nenue@17: cprint(' **', talentInfo[i], '->', command) Nenue@17: tinsert(cache, talentInfo[i]) Nenue@17: end Nenue@17: end Nenue@17: kb.CacheTalentBinding = function(talentInfo, cache) Nenue@17: Nenue@17: local spellID = talentInfo[4] Nenue@17: kb.inactiveTalentBindings[spellID] = kb.inactiveTalentBindings[spellID] or {} Nenue@17: kb.inactiveTalentBindings[spellID] = {select(5,unpack(talentInfo)) } Nenue@17: --cprint(spellID, unpack(kb.inactiveTalentBindings[spellID])) Nenue@17: end Nenue@17: Nenue@17: do Nenue@17: local bindings = kb.bindings Nenue@17: local key, macro = KeyBinderKey, KeyBinderMacro Nenue@17: kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText ) Nenue@17: Nenue@17: if actionType == 'spell' then Nenue@17: key:SetAttribute("*type-"..name, actionType) Nenue@17: key:SetAttribute("*"..actionType.."-"..name, name) Nenue@17: elseif actionType == 'item' then Nenue@17: key:SetAttribute("*type-"..name, actionType) Nenue@17: key:SetAttribute("*"..actionType.."-"..name, name) Nenue@17: elseif actionType == 'macro' then Nenue@17: macro:SetAttribute("*macro-"..macroName, actionID) Nenue@16: else Nenue@17: macro:SetAttribute("*macrotext-"..macroName, macroText) Nenue@16: end Nenue@16: Nenue@17: cprint('Loading binding', actionType, actionID) Nenue@17: bindings[actionType] = bindings[actionType] or {} Nenue@17: bindings[actionType][actionID] = bindings[actionType][actionID] or {} Nenue@17: bindings[command] = bindings[actionType][actionID] Nenue@17: return bindings[actionType], actionID Nenue@16: end Nenue@16: Nenue@17: kb.ApplyBindings = function (profile) Nenue@17: cprint('binding profile', profile) Nenue@17: for slot, data in pairs(profile.buttons) do Nenue@17: kb.LoadBinding(unpack(data)) Nenue@17: end Nenue@17: Nenue@17: for key, command in pairs(profile.bindings) do Nenue@17: Nenue@17: cprint(' *', key, '->', command) Nenue@17: Nenue@17: --_G.print('HotKey','loading', key, command) Nenue@17: SetBinding(key, command) Nenue@17: if bindings[command] and not tContains(bindings[command], key) then Nenue@17: tinsert(bindings[command], key) Nenue@17: end Nenue@17: end Nenue@17: Nenue@17: for spellName, talentInfo in pairs(profile.talents) do Nenue@17: local dummy = GetSpellInfo(spellName) Nenue@17: local func = kb.CacheTalentBinding Nenue@17: local dest = kb.inactiveTalentBindings Nenue@17: if dummy then Nenue@17: cprint('|cFFBBFF00Active:|r', dummy) Nenue@17: local macroName, spellName, actionType, actionID = unpack(talentInfo) Nenue@17: bindings[actionType] = bindings[actionType] or {} Nenue@17: bindings[actionType][actionID] = {} Nenue@17: func = kb.ApplyTalentBinding Nenue@17: dest = kb.bindings[actionType][actionID] Nenue@17: else Nenue@17: Nenue@17: cprint('|cFFFF4400Inactive:|r', talentInfo[2]) Nenue@17: end Nenue@17: func(talentInfo, dest) Nenue@17: end Nenue@17: Nenue@17: end Nenue@17: Nenue@17: kb.ApplyAllBindings =function () Nenue@17: table.wipe(kb.inactiveTalentBindings) Nenue@17: Nenue@17: Nenue@17: -- reflect action key settings Nenue@17: if GetCVarBool("ActionButtonUseKeyDown") then Nenue@17: KeyBinderMacro:RegisterForClicks("AnyDown") Nenue@17: KeyBinderKey:RegisterForClicks("AnyDown") Nenue@17: else Nenue@17: KeyBinderMacro:RegisterForClicks("AnyUp") Nenue@17: KeyBinderKey:RegisterForClicks("AnyUp") Nenue@17: end Nenue@17: Nenue@17: for i, profile in ipairs(kb.orderedProfiles) do Nenue@17: kb.ApplyBindings(profile) Nenue@17: end Nenue@17: -- do this after to ensure that profession binds are properly overridden Nenue@17: kb.UpdateProfessionInfo() Nenue@17: Nenue@17: Nenue@17: SaveBindings(GetCurrentBindingSet()) Nenue@17: end Nenue@16: end