Mercurial > wow > skeletonkey
diff 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 |
line wrap: on
line diff
--- a/SkeletonKey/ActionTypes.lua Fri Jul 29 21:18:15 2016 -0400 +++ b/SkeletonKey/ActionTypes.lua Sat Jul 30 00:08:00 2016 -0400 @@ -4,8 +4,11 @@ -- %file-revision% -- local kb, print, wrap = LibStub('LibKraken').register(KeyBinder) +local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 +local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:" +local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:" local PETACTION_SCRIPT = { [PET_ACTION_MOVE_TO] = {SLASH_PET_MOVE_TO1, 'pet_move_to'}, @@ -18,62 +21,172 @@ [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'}, } ---- Caps Lock derivatives +--- Caps Lock local ACTION_HANDLERS = {} ACTION_HANDLERS['mount'] = function(id, name) - return "/script C_MountJournal.SummonByID("..id..")" + if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then + return 'mount_random', "/script C_MountJournal.SummonByID(0)", CLICK_KEYBINDER_MACRO + else + return 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", CLICK_KEYBINDER_MACRO + end end -ACTION_HANDLERS['macro'] = "%s" -ACTION_HANDLERS['equipset'] = "/script UseEquipmentSet(%d)" -ACTION_HANDLERS['spell'] = "/cast %s" -ACTION_HANDLERS['petaction'] = function(id, name) - return PETACTION_SCRIPT[name] or "/cast ".. name +ACTION_HANDLERS['macro'] = function(id, name) + return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), id +end +ACTION_HANDLERS['equipset'] = function(id, name) + return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")" +end +ACTION_HANDLERS['spell'] = function(id, name) + local attributeName = name + if kb.ProfessionCache[id] then + attributeName = "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum + end + return CLICK_KEYBINDER_KEY, attributeName, name +end +ACTION_HANDLERS['petaction'] = function(_, name) + -- ID doesn't exist for basic commands, even though they can be picked up + local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name) + if PETACTION_SCRIPT[name] then + attributeValue, attributeName = unpack(PETACTION_SCRIPT[name]) + end + + return CLICK_KEYBINDER_MACRO, attributeName, attributeValue end -ACTION_HANDLERS['battlepet'] = SLASH_SUMMON_BATTLE_PET1 .. " %s" -ACTION_HANDLERS['item'] = "/use %s" -local professionMappings = { - [5] = 3, - [7] = 4, - [9] = 5, - [10] = 6 -} +ACTION_HANDLERS['battlepet'] = function(id, name) + return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name) +end +ACTION_HANDLERS['item'] = function(id, name) + return CLICK_KEYBINDER_KEY, 'item_' .. tostring(name), id +end ---- Generates the command strings needed to assign different abilities +--- Resolves the SecureActionButton attribute names used for the given action kb.RegisterAction = function(actionType, id, name) - local macroText, macroName, command = '', '', '' - if actionType == 'spell' then - if kb.ProfessionCache[id] then - command = CLICK_KEYBINDER_KEY .. "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum + assert(ACTION_HANDLERS[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`') + local target, attributeName, attributeValue = ACTION_HANDLERS[actionType](id, name) + + 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]) .. '"') + attributeName = baseName .. '_' .. iterative + iterative = iterative + 1 + end + if macroName ~= baseName then + print(' * Creating|cFF00FF00', macroName) + else + print(' * Re-using|cFF00FF00', macroName) + end + kb.macros[attributeName] = {attributeValue, command} + + + print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName) + return attributeName, attributeValue, command +end + + + + +kb.inactiveTalentBindings = {} +kb.ApplyTalentBinding = function(talentInfo, cache) + for i = 5, #talentInfo do + local command = CLICK_KEYBINDER_KEY.. talentInfo[2] + SetBinding(talentInfo[i], command) + cprint(' **', talentInfo[i], '->', command) + tinsert(cache, talentInfo[i]) + end +end +kb.CacheTalentBinding = function(talentInfo, cache) + + local spellID = talentInfo[4] + kb.inactiveTalentBindings[spellID] = kb.inactiveTalentBindings[spellID] or {} + kb.inactiveTalentBindings[spellID] = {select(5,unpack(talentInfo)) } + --cprint(spellID, unpack(kb.inactiveTalentBindings[spellID])) +end + +do + local bindings = kb.bindings + local key, macro = KeyBinderKey, KeyBinderMacro + kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText ) + + if actionType == 'spell' then + key:SetAttribute("*type-"..name, actionType) + key:SetAttribute("*"..actionType.."-"..name, name) + elseif actionType == 'item' then + key:SetAttribute("*type-"..name, actionType) + key:SetAttribute("*"..actionType.."-"..name, name) + elseif actionType == 'macro' then + macro:SetAttribute("*macro-"..macroName, actionID) else - command = CLICK_KEYBINDER_KEY ..name - end - else - - if type(ACTION_SCRIPT[actionType]) == 'function' then - macroName, macroText = ACTION_SCRIPT[actionType](id, name) - else - macroName = actionType .. ' ' .. name - macroText = ACTION_SCRIPT[actionType]:format(name) + macro:SetAttribute("*macrotext-"..macroName, macroText) end - local baseName, iterative = macroName, 1 - while (macros[macroName] and macros[macroName][1] ~= macroText) do - print(' * cannot use|cFF00FF00', macroName, '|r"'.. (macros[macroName][1] or '') .. '"') - macroName = baseName .. '_' .. iterative - iterative = iterative + 1 - end - if macroName ~= baseName then - print(' * Creating|cFF00FF00', macroName) - else - print(' * Re-using|cFF00FF00', macroName) - end - command = 'CLICK KeyBinderMacro:'.. macroName - macros[macroName] = {macroText, command } + cprint('Loading binding', actionType, actionID) + bindings[actionType] = bindings[actionType] or {} + bindings[actionType][actionID] = bindings[actionType][actionID] or {} + bindings[command] = bindings[actionType][actionID] + return bindings[actionType], actionID end - print('RegisterAction', actionType, id, '->', command , macroText) - return macroName, macroText, command + kb.ApplyBindings = function (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) + + --_G.print('HotKey','loading', key, command) + SetBinding(key, command) + if bindings[command] and not tContains(bindings[command], key) then + tinsert(bindings[command], key) + end + end + + for spellName, talentInfo in pairs(profile.talents) do + local dummy = GetSpellInfo(spellName) + local func = kb.CacheTalentBinding + local dest = kb.inactiveTalentBindings + if dummy then + cprint('|cFFBBFF00Active:|r', dummy) + local macroName, spellName, actionType, actionID = unpack(talentInfo) + bindings[actionType] = bindings[actionType] or {} + bindings[actionType][actionID] = {} + func = kb.ApplyTalentBinding + dest = kb.bindings[actionType][actionID] + else + + cprint('|cFFFF4400Inactive:|r', talentInfo[2]) + end + func(talentInfo, dest) + end + + end + + kb.ApplyAllBindings =function () + table.wipe(kb.inactiveTalentBindings) + + + -- reflect action key settings + if GetCVarBool("ActionButtonUseKeyDown") then + KeyBinderMacro:RegisterForClicks("AnyDown") + KeyBinderKey:RegisterForClicks("AnyDown") + else + KeyBinderMacro:RegisterForClicks("AnyUp") + KeyBinderKey:RegisterForClicks("AnyUp") + end + + for i, profile in ipairs(kb.orderedProfiles) do + kb.ApplyBindings(profile) + end + -- do this after to ensure that profession binds are properly overridden + kb.UpdateProfessionInfo() + + + SaveBindings(GetCurrentBindingSet()) + end end \ No newline at end of file