annotate SkeletonKey/ActionTypes.lua @ 17:500f9b2bd9ac

- for RegisterAction, use a function table instead of that if/then rats nest - consequently pet bar actions work now - unlocalize bindings data - activate keyslot input manually instead of on mouse over - activate checkbox to keep input mode active - dynamic buttons update in real time for petaction/talent/profession spells
author Nenue
date Sat, 30 Jul 2016 00:08:00 -0400
parents cdd387d39137
children 67db6b712bf3
rev   line source
Nenue@16 1 -- SkeletonKey
Nenue@16 2 -- ActionTypes.lua
Nenue@16 3 -- Created: 7/29/2016 9:14 PM
Nenue@16 4 -- %file-revision%
Nenue@16 5 --
Nenue@16 6 local kb, print, wrap = LibStub('LibKraken').register(KeyBinder)
Nenue@17 7 local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end
Nenue@16 8
Nenue@16 9 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
Nenue@17 10 local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:"
Nenue@17 11 local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:"
Nenue@16 12
Nenue@16 13 local PETACTION_SCRIPT = {
Nenue@16 14 [PET_ACTION_MOVE_TO] = {SLASH_PET_MOVE_TO1, 'pet_move_to'},
Nenue@16 15 [PET_ACTION_ATTACK] = {SLASH_PET_ATTACK1, 'pet_attack'},
Nenue@16 16 [PET_ACTION_FOLLOW] = {SLASH_PET_FOLLOW1, 'pet_follow'},
Nenue@16 17 [PET_ACTION_WAIT] = {SLASH_PET_STAY1, 'pet_stay'},
Nenue@16 18 [PET_MODE_AGGRESSIVE] = {SLASH_PET_AGGRESSIVE1, 'pet_aggressive'},
Nenue@16 19 [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'},
Nenue@16 20 [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'},
Nenue@16 21 [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'},
Nenue@16 22 }
Nenue@16 23
Nenue@17 24 --- Caps Lock
Nenue@16 25 local ACTION_HANDLERS = {}
Nenue@16 26 ACTION_HANDLERS['mount'] = function(id, name)
Nenue@17 27 if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then
Nenue@17 28 return 'mount_random', "/script C_MountJournal.SummonByID(0)", CLICK_KEYBINDER_MACRO
Nenue@17 29 else
Nenue@17 30 return 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", CLICK_KEYBINDER_MACRO
Nenue@17 31 end
Nenue@16 32 end
Nenue@17 33 ACTION_HANDLERS['macro'] = function(id, name)
Nenue@17 34 return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), id
Nenue@17 35 end
Nenue@17 36 ACTION_HANDLERS['equipset'] = function(id, name)
Nenue@17 37 return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")"
Nenue@17 38 end
Nenue@17 39 ACTION_HANDLERS['spell'] = function(id, name)
Nenue@17 40 local attributeName = name
Nenue@17 41 if kb.ProfessionCache[id] then
Nenue@17 42 attributeName = "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum
Nenue@17 43 end
Nenue@17 44 return CLICK_KEYBINDER_KEY, attributeName, name
Nenue@17 45 end
Nenue@17 46 ACTION_HANDLERS['petaction'] = function(_, name)
Nenue@17 47 -- ID doesn't exist for basic commands, even though they can be picked up
Nenue@17 48 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name)
Nenue@17 49 if PETACTION_SCRIPT[name] then
Nenue@17 50 attributeValue, attributeName = unpack(PETACTION_SCRIPT[name])
Nenue@17 51 end
Nenue@17 52
Nenue@17 53 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue
Nenue@16 54 end
Nenue@16 55
Nenue@17 56 ACTION_HANDLERS['battlepet'] = function(id, name)
Nenue@17 57 return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name)
Nenue@17 58 end
Nenue@17 59 ACTION_HANDLERS['item'] = function(id, name)
Nenue@17 60 return CLICK_KEYBINDER_KEY, 'item_' .. tostring(name), id
Nenue@17 61 end
Nenue@16 62
Nenue@16 63
Nenue@17 64 --- Resolves the SecureActionButton attribute names used for the given action
Nenue@16 65 kb.RegisterAction = function(actionType, id, name)
Nenue@16 66
Nenue@17 67 assert(ACTION_HANDLERS[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`')
Nenue@17 68 local target, attributeName, attributeValue = ACTION_HANDLERS[actionType](id, name)
Nenue@17 69
Nenue@17 70 local command = target .. attributeName
Nenue@17 71 local baseName, iterative = attributeName, 1
Nenue@17 72 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do
Nenue@17 73 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"')
Nenue@17 74 attributeName = baseName .. '_' .. iterative
Nenue@17 75 iterative = iterative + 1
Nenue@17 76 end
Nenue@17 77 if macroName ~= baseName then
Nenue@17 78 print(' * Creating|cFF00FF00', macroName)
Nenue@17 79 else
Nenue@17 80 print(' * Re-using|cFF00FF00', macroName)
Nenue@17 81 end
Nenue@17 82 kb.macros[attributeName] = {attributeValue, command}
Nenue@17 83
Nenue@17 84
Nenue@17 85 print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName)
Nenue@17 86 return attributeName, attributeValue, command
Nenue@17 87 end
Nenue@17 88
Nenue@17 89
Nenue@17 90
Nenue@17 91
Nenue@17 92 kb.inactiveTalentBindings = {}
Nenue@17 93 kb.ApplyTalentBinding = function(talentInfo, cache)
Nenue@17 94 for i = 5, #talentInfo do
Nenue@17 95 local command = CLICK_KEYBINDER_KEY.. talentInfo[2]
Nenue@17 96 SetBinding(talentInfo[i], command)
Nenue@17 97 cprint(' **', talentInfo[i], '->', command)
Nenue@17 98 tinsert(cache, talentInfo[i])
Nenue@17 99 end
Nenue@17 100 end
Nenue@17 101 kb.CacheTalentBinding = function(talentInfo, cache)
Nenue@17 102
Nenue@17 103 local spellID = talentInfo[4]
Nenue@17 104 kb.inactiveTalentBindings[spellID] = kb.inactiveTalentBindings[spellID] or {}
Nenue@17 105 kb.inactiveTalentBindings[spellID] = {select(5,unpack(talentInfo)) }
Nenue@17 106 --cprint(spellID, unpack(kb.inactiveTalentBindings[spellID]))
Nenue@17 107 end
Nenue@17 108
Nenue@17 109 do
Nenue@17 110 local bindings = kb.bindings
Nenue@17 111 local key, macro = KeyBinderKey, KeyBinderMacro
Nenue@17 112 kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText )
Nenue@17 113
Nenue@17 114 if actionType == 'spell' then
Nenue@17 115 key:SetAttribute("*type-"..name, actionType)
Nenue@17 116 key:SetAttribute("*"..actionType.."-"..name, name)
Nenue@17 117 elseif actionType == 'item' then
Nenue@17 118 key:SetAttribute("*type-"..name, actionType)
Nenue@17 119 key:SetAttribute("*"..actionType.."-"..name, name)
Nenue@17 120 elseif actionType == 'macro' then
Nenue@17 121 macro:SetAttribute("*macro-"..macroName, actionID)
Nenue@16 122 else
Nenue@17 123 macro:SetAttribute("*macrotext-"..macroName, macroText)
Nenue@16 124 end
Nenue@16 125
Nenue@17 126 cprint('Loading binding', actionType, actionID)
Nenue@17 127 bindings[actionType] = bindings[actionType] or {}
Nenue@17 128 bindings[actionType][actionID] = bindings[actionType][actionID] or {}
Nenue@17 129 bindings[command] = bindings[actionType][actionID]
Nenue@17 130 return bindings[actionType], actionID
Nenue@16 131 end
Nenue@16 132
Nenue@17 133 kb.ApplyBindings = function (profile)
Nenue@17 134 cprint('binding profile', profile)
Nenue@17 135 for slot, data in pairs(profile.buttons) do
Nenue@17 136 kb.LoadBinding(unpack(data))
Nenue@17 137 end
Nenue@17 138
Nenue@17 139 for key, command in pairs(profile.bindings) do
Nenue@17 140
Nenue@17 141 cprint(' *', key, '->', command)
Nenue@17 142
Nenue@17 143 --_G.print('HotKey','loading', key, command)
Nenue@17 144 SetBinding(key, command)
Nenue@17 145 if bindings[command] and not tContains(bindings[command], key) then
Nenue@17 146 tinsert(bindings[command], key)
Nenue@17 147 end
Nenue@17 148 end
Nenue@17 149
Nenue@17 150 for spellName, talentInfo in pairs(profile.talents) do
Nenue@17 151 local dummy = GetSpellInfo(spellName)
Nenue@17 152 local func = kb.CacheTalentBinding
Nenue@17 153 local dest = kb.inactiveTalentBindings
Nenue@17 154 if dummy then
Nenue@17 155 cprint('|cFFBBFF00Active:|r', dummy)
Nenue@17 156 local macroName, spellName, actionType, actionID = unpack(talentInfo)
Nenue@17 157 bindings[actionType] = bindings[actionType] or {}
Nenue@17 158 bindings[actionType][actionID] = {}
Nenue@17 159 func = kb.ApplyTalentBinding
Nenue@17 160 dest = kb.bindings[actionType][actionID]
Nenue@17 161 else
Nenue@17 162
Nenue@17 163 cprint('|cFFFF4400Inactive:|r', talentInfo[2])
Nenue@17 164 end
Nenue@17 165 func(talentInfo, dest)
Nenue@17 166 end
Nenue@17 167
Nenue@17 168 end
Nenue@17 169
Nenue@17 170 kb.ApplyAllBindings =function ()
Nenue@17 171 table.wipe(kb.inactiveTalentBindings)
Nenue@17 172
Nenue@17 173
Nenue@17 174 -- reflect action key settings
Nenue@17 175 if GetCVarBool("ActionButtonUseKeyDown") then
Nenue@17 176 KeyBinderMacro:RegisterForClicks("AnyDown")
Nenue@17 177 KeyBinderKey:RegisterForClicks("AnyDown")
Nenue@17 178 else
Nenue@17 179 KeyBinderMacro:RegisterForClicks("AnyUp")
Nenue@17 180 KeyBinderKey:RegisterForClicks("AnyUp")
Nenue@17 181 end
Nenue@17 182
Nenue@17 183 for i, profile in ipairs(kb.orderedProfiles) do
Nenue@17 184 kb.ApplyBindings(profile)
Nenue@17 185 end
Nenue@17 186 -- do this after to ensure that profession binds are properly overridden
Nenue@17 187 kb.UpdateProfessionInfo()
Nenue@17 188
Nenue@17 189
Nenue@17 190 SaveBindings(GetCurrentBindingSet())
Nenue@17 191 end
Nenue@16 192 end