Nenue@70: -- SkeletonKey Nenue@70: -- ActionTemplates.lua Nenue@70: -- Created: 7/29/2016 9:14 PM Nenue@70: -- %file-revision% Nenue@70: -- Code dealing with the implementation of action hotkeys Nenue@70: Nenue@70: local tostring, tonumber, pairs, ipairs = tostring, tonumber, pairs, ipairs Nenue@70: local unpack, SetBinding = unpack, SetBinding Nenue@70: local tinsert, tContains, select, wipe = tinsert, tContains, select, table.wipe Nenue@70: local GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo = GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo Nenue@70: local GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell = GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell Nenue@70: local PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells = PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells Nenue@70: local GetProfessions, GetProfessionInfo, GetTalentInfo = GetProfessions, GetProfessionInfo, GetTalentInfo Nenue@70: local GetNumBindings, GetBinding = GetNumBindings, GetBinding Nenue@70: Nenue@70: local _, kb = ... Nenue@70: local print = (DEVIAN_PNAME == 'SkeletonKey') and function(...) print('SK', ...) end or nop Nenue@70: local cprint = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('Cfg', ...) end or nop Nenue@70: Nenue@70: local CLICK_KEYBINDER_MACRO = "CLICK SkeletonKeyMacro:" Nenue@70: local CLICK_KEYBINDER_KEY = "CLICK SkeletonKeyKey:" Nenue@70: local PET_BASIC_SUBTEXT = 'Basic Attack' Nenue@70: local PET_SPECIAL_SUBTEXT = 'Special Ability' Nenue@70: local PETACTION_SCRIPT = { Nenue@70: [PET_ACTION_MOVE_TO] = {'pet_move_to', SLASH_PET_MOVE_TO1}, Nenue@70: [PET_ACTION_ATTACK] = {'pet_attack', SLASH_PET_ATTACK1}, Nenue@70: [PET_ACTION_FOLLOW] = {'pet_follow', SLASH_PET_FOLLOW1}, Nenue@70: [PET_ACTION_WAIT] = {'pet_stay', SLASH_PET_STAY1 }, Nenue@70: [PET_MODE_AGGRESSIVE] = {'pet_aggressive', SLASH_PET_AGGRESSIVE1 }, Nenue@70: [PET_MODE_DEFENSIVE] = { 'pet_defensive', SLASH_PET_DEFENSIVE1}, Nenue@70: [PET_MODE_PASSIVE] = { 'pet_passive', SLASH_PET_PASSIVE1}, Nenue@70: [PET_MODE_ASSIST] = {'pet_assist', SLASH_PET_ASSIST1}, Nenue@70: } Nenue@70: local SECONDARY_PROFESSIONS = { Nenue@70: [5] = 3, Nenue@70: [7] = 4, Nenue@70: [9] = 5, Nenue@70: [10] = 6 Nenue@70: } Nenue@70: local petSpellCache,petSubtextCache Nenue@70: local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 Nenue@70: Nenue@70: Nenue@70: local atype = kb.ActionTypes Nenue@70: Nenue@70: --- Caps Lock Nenue@70: atype['mount'] = function(id, name) Nenue@70: if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then Nenue@70: return CLICK_KEYBINDER_MACRO, 'mount_random', "/script C_MountJournal.SummonByID(0)", SkeletonKeyMacro Nenue@70: else Nenue@70: return CLICK_KEYBINDER_MACRO, 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", SkeletonKeyMacro Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: atype['macro'] = function(id, name) Nenue@70: local _, _, text = GetMacroInfo(id) Nenue@70: return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), name, SkeletonKeyMacro Nenue@70: end Nenue@70: Nenue@70: atype['equipset'] = function(id, name) Nenue@70: return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")", SkeletonKeyMacro Nenue@70: end Nenue@70: Nenue@70: atype['spell'] = function(id, name) Nenue@70: local attributeName = name Nenue@78: local profInfo = kb.DynamicSpells.profession[id] Nenue@78: if profInfo then Nenue@78: attributeName = "profession_".. profInfo.dynamicIndex .. '_' .. profInfo.dynamicSubIndex Nenue@70: end Nenue@70: return CLICK_KEYBINDER_KEY, attributeName, name, SkeletonKeyKey Nenue@70: end Nenue@70: Nenue@70: atype['petaction'] = function(_, name) Nenue@70: -- ID doesn't exist for basic commands, even though they can be picked up Nenue@70: local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name) Nenue@70: Nenue@70: if not petSpellCache then Nenue@70: kb.UpdatePetInfo() Nenue@70: end Nenue@70: -- Compose a multi-macro for subtext abilities Nenue@70: if petSpellCache[name] then Nenue@70: attributeValue = "" Nenue@70: for spellName, enabled in pairs(petSubtextCache[petSpellCache[name]]) do Nenue@70: attributeValue = attributeValue .. "/cast " .. spellName .. "\n" Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: if PETACTION_SCRIPT[name] then Nenue@70: attributeName, attributeValue = unpack(PETACTION_SCRIPT[name]) Nenue@70: elseif kb.PetCache.special[name] then Nenue@70: attributeName = "petaction_"..kb.PetCache.special[name][3].."_" .. tonumber(kb.PetCache.special[name][6]) Nenue@70: end Nenue@70: return CLICK_KEYBINDER_MACRO, attributeName, attributeValue, SkeletonKeyMacro Nenue@70: end Nenue@70: Nenue@70: atype['battlepet'] = function(id, name) Nenue@70: return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name), SkeletonKeyMacro Nenue@70: end Nenue@70: Nenue@70: atype['item'] = function(id, name) Nenue@75: return CLICK_KEYBINDER_KEY, tostring(name), tostring(name), SkeletonKeyKey Nenue@70: end Nenue@70: Nenue@70: Nenue@70: --- Resolves the SecureActionButton attribute names used for the given action Nenue@70: kb.RegisterAction = function(actionType, id, name) Nenue@70: assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`') Nenue@74: local prefix, attributeName, attributeValue, button = atype[actionType](id, name) Nenue@74: local command = prefix .. attributeName Nenue@74: return attributeName, attributeValue, command, prefix, button Nenue@70: end Nenue@70: Nenue@70: Nenue@74: local spells = {} Nenue@74: local SkeletonKey_GetGenericSpell = function(spellName, spellID, icon) Nenue@74: if not spells[spellID] then Nenue@74: spells[spellID] = {} Nenue@74: spells[spellID].actionType = 'spell' Nenue@74: spells[spellID].actionID = spellID Nenue@74: spells[spellID].actionName = spellName Nenue@74: spells[spellID].iconPath = icon Nenue@74: spells[spellID].statusText = '|cFFBBBBBBSpell|r' Nenue@74: spells[spellID].dynamicType = nil Nenue@74: end Nenue@74: return spells[spellID] Nenue@74: end Nenue@74: Nick@80: -- verifies binding slot data Nenue@74: local dynamicTypes = {['profession'] = 'ProfessionCache', ['talent'] = 'TalentCache', ['petaction'] = 'PetInfoCache'} Nenue@74: kb.ResolveSpellSlot = function(self) Nenue@74: local spellName, spellID, command, icon = self.actionName, self.actionID, self.command, self.iconPath Nick@80: Nenue@74: --print(GetSpellInfo(spellName or spellID)) Nick@80: local internalName, _, internalIcon, _, _, _, _ = GetSpellInfo(spellID) Nick@80: local replacerName, _, _, _, _, _, replacerID = GetSpellInfo(internalName) Nick@80: print('Resolve Slot: id =', spellID, 'nameFromID =', internalName, 'nameFromName =', replacerName) Nenue@74: local isAvailable = internalName and true Nenue@74: Nick@80: -- keep current slotInfo if it's a spell that has been replaced by spec/talent Nick@80: if internalName and (internalName ~= replacerName) then Nick@80: print(' |cFFFF4400spell name is overridden by', replacerName, '(was', internalName,')') Nenue@74: self.statusText = '|cFFFFFF00Spell|r' Nenue@74: self.isAvailable = true Nenue@74: return Nenue@74: end Nenue@74: Nick@80: -- resolve spell name Nick@80: local info = kb.DynamicSpells[spellName] Nenue@74: if not info then Nenue@74: local dynamicType, dynamicIndex, dynamicSubIndex = command:match("(%a+)_(%S+)_(%S+)") Nenue@74: if kb.DynamicSpells[dynamicType] then Nenue@74: print('|cFFFF4400resolving dynamic type index:', internalName, spellName, command) Nenue@74: dynamicIndex = tonumber(dynamicIndex) Nenue@74: dynamicSubIndex = tonumber(dynamicSubIndex) Nenue@74: local cache = kb.DynamicSpells[dynamicType] Nenue@74: print('type:', dynamicType) Nenue@74: if dynamicIndex and cache[dynamicIndex] then Nenue@74: info = kb.DynamicSpells[dynamicType][dynamicIndex] Nenue@74: print('index:', dynamicIndex) Nenue@74: if dynamicSubIndex and info[dynamicSubIndex] then Nenue@74: info = info[dynamicSubIndex] Nenue@74: print('sub-index:', dynamicSubIndex) Nenue@74: end Nenue@74: isAvailable = true Nenue@74: end Nenue@74: end Nenue@74: if not info then Nenue@74: info = SkeletonKey_GetGenericSpell(spellName, spellID, internalIcon or icon) Nenue@74: end Nenue@74: end Nenue@74: info.isAvailable = isAvailable Nenue@74: Nenue@74: print('|cFF00FF88Slot Details:|r', info.actionName, info.actionID, info.dynamicType, info.isAvailable) Nenue@74: for k,v in pairs(info) do Nenue@74: --cprint(' ',k,v) Nenue@74: self[k] = v Nenue@74: end Nenue@74: Nenue@74: return info Nenue@74: end Nenue@70: Nenue@70: do Nenue@76: local PROFILE_VERSION = 320 Nenue@70: local commandActions = {} Nenue@70: local bindings = kb.bindings Nenue@70: local key, macro = SkeletonKeyKey, SkeletonKeyMacro Nenue@70: kb.LoadBinding = function( configTable) Nenue@70: if configTable.command then Nenue@70: configTable.command = configTable.command:gsub('KeyBinder', 'SkeletonKey') Nenue@70: end Nenue@70: Nenue@70: local command, name, icon, actionType, actionID, macroName, macroText = Nenue@70: configTable.command, configTable.actionName, configTable.iconPath, configTable.actionType, Nenue@70: configTable.actionID, configTable.macroName, configTable.macroText Nenue@70: Nenue@70: Nenue@70: local indexKey = actionType..'_'..actionID Nenue@70: local actionPrefix = "*"..actionType.."-" Nenue@70: local button = SkeletonKeyKey Nenue@72: local isAvailable Nenue@70: local specialButtonType Nenue@70: if actionType == 'spell' then Nick@80: local realName, _, _, _, _, _, realID = GetSpellInfo(name) Nick@80: if realName and (realName ~= name) then Nick@80: print(' *** "', name, '" resolves to something else...', realName, realID) Nick@80: --name, actionID = realName, realID Nick@80: indexKey = actionType .. '_'.. realID Nick@80: end Nick@80: Nick@80: Nick@80: Nick@80: local dynamicInfo = kb.DynamicSpells[spellName] Nenue@70: if dynamicInfo then Nenue@76: configTable.assignedKeys = configTable.assignedKeys or {GetBindingKey(configTable.command) } Nenue@76: Nenue@72: cprint('|cFF00FFFFDynamicInfo:|r', dynamicInfo.dynamicType, table.concat(configTable.assignedKeys, ',')) Nenue@70: for k, v in pairs(dynamicInfo) do Nenue@71: --cprint(' --', k, v) Nenue@70: configTable[k] = v Nenue@70: end Nenue@76: isAvailable = configTable.isAvailable Nenue@76: elseif GetSpellInfo(actionID) then Nenue@76: isAvailable = true Nenue@76: Nenue@70: end Nenue@75: elseif actionType == 'item' then Nenue@75: actionID = configTable.actionName Nenue@75: isAvailable = true Nenue@75: else Nenue@71: Nenue@70: if actionType ~= 'macro' then Nenue@70: actionPrefix = '*macrotext-' Nenue@70: end Nenue@70: Nenue@70: specialButtonType = 'macro' Nenue@73: isAvailable = true Nenue@70: end Nenue@70: Nenue@72: if isAvailable then Nenue@70: Nenue@72: local attributeSuffix, attributeValue, command, target, button = kb.RegisterAction(actionType, actionID, name) Nenue@72: local actionKey = actionPrefix .. attributeSuffix Nenue@72: cprint('|cFF00FF88LoadBinding()|r', button:GetName(), "*type-"..attributeSuffix, actionType, '|cFFFFFF00'..actionKey, attributeValue, isAvailable) Nenue@70: Nenue@70: Nenue@70: kb.SecureAttribute(button, "*type-"..attributeSuffix, specialButtonType or actionType) Nenue@70: kb.SecureAttribute(button, actionKey, attributeValue) Nenue@72: Nenue@72: cprint('|cFFFF4400add', name, isAvailable, indexKey, unpack(configTable.assignedKeys)) Nenue@70: kb.bindings[indexKey] = configTable.assignedKeys Nenue@70: commandActions[command] = kb.bindings[indexKey] Nenue@70: return command, kb.bindings[indexKey] Nenue@70: else Nenue@72: if kb.bindings[indexKey] then Nenue@72: cprint('|cFFFF4400remove', name, isAvailable, indexKey, unpack(configTable.assignedKeys)) Nenue@72: kb.bindings[indexKey] = nil Nenue@72: end Nenue@72: Nenue@70: return nil Nenue@70: end Nenue@70: end Nenue@70: Nenue@71: Nenue@70: local usedSlots = {} Nenue@71: kb.UpgradeProfile = function(profile) Nenue@70: wipe(usedSlots) Nenue@70: for slot, configTable in pairs(profile.buttons) do Nenue@70: Nenue@71: -- convert old style table Nenue@70: if #configTable >= 1 then Nenue@70: local command, name, icon, actionType, actionID, macroName, macroText, spellbookSlot, spellbookType = unpack(configTable) Nenue@70: Nenue@70: cprint('|CFFFF4400Fixing pad entry', slot, command, name) Nenue@70: local assignedKeys = {GetBindingKey(command)} Nenue@70: for k,v in pairs(profile.bindings) do Nenue@70: if v == command then Nenue@70: tinsert(assignedKeys, k) Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: configTable = { Nenue@70: command = command, Nenue@70: actionType = actionType, Nenue@70: actionName = name, Nenue@70: actionID = actionID, Nenue@70: macroName = macroName, Nenue@70: macroText = macroText, Nenue@70: iconPath = icon, Nenue@70: spellbookSlot = spellbookSlot, Nenue@70: spellbookType = spellbookType, Nenue@70: assignedKeys = assignedKeys Nenue@70: } Nenue@71: Nenue@71: local dynamic = kb.DynamicSpells[name] Nenue@71: if dynamic then Nenue@71: configTable.dynamicType = dynamic.dynamicType Nenue@71: configTable.dynamicIndex = dynamic.dynamicIndex Nenue@71: configTable.dynamicSubIndex = dynamic.dynamicSubIndex Nenue@71: configTable.dynamicID = dynamic.dynamicID Nenue@71: if configTable.dynamicType == 'talent' then Nenue@71: profile.talents[name] = configTable Nenue@71: end Nenue@71: end Nenue@71: Nenue@71: Nenue@70: kb.currentProfile.buttons[slot] = configTable Nenue@70: end Nenue@70: if not configTable.actionID then Nenue@70: configTable.actionID = configTable.actionName Nenue@70: end Nenue@70: if not configTable.iconPath then Nenue@70: print('corrected missing icon') Nenue@70: configTable.iconPath = GetSpellTexture(configTable.actionName) Nenue@70: end Nenue@70: Nenue@70: usedSlots[configTable.actionName or configTable.actionID] = true Nenue@70: usedSlots[configTable.command] = true Nenue@70: end Nenue@70: Nenue@70: Nenue@71: -- clean up legacy data Nenue@70: for spellName, talentInfo in pairs(profile.talents) do Nenue@70: if not usedSlots[spellName] then Nenue@70: cprint('|cFFFF4400Unslotted talent', spellName) Nenue@70: profile.talents[spellName] = nil Nenue@70: end Nenue@70: end Nenue@70: for command in pairs(profile.bound) do Nenue@70: if not usedSlots[command] then Nenue@70: cprint('|cFFFF4400Unslotted bound entry', command) Nenue@70: profile.bound[command] = nil Nenue@70: profile.commands[command] = nil Nenue@70: end Nenue@70: end Nenue@70: for command in pairs(profile.commands) do Nenue@70: if not usedSlots[command] then Nenue@70: cprint('|cFFFF4400Unslotted command entry', command) Nenue@70: profile.commands[command] = nil Nenue@70: end Nenue@70: end Nenue@76: Nenue@76: if profile.talents then Nenue@76: profile.talents = nil Nenue@76: end Nenue@76: Nenue@76: Nenue@76: profile.versionID = PROFILE_VERSION Nenue@71: end Nenue@70: Nenue@71: kb.ApplyBindings = function (profile) Nenue@71: cprint('|cFF0088FFApplyBindings()') Nenue@71: --cprint('binding profile', profile) Nenue@71: Nenue@71: local version = profile.versionID or 0 Nenue@76: if version < PROFILE_VERSION then Nenue@71: kb.UpgradeProfile(profile) Nenue@71: end Nenue@71: Nenue@71: Nenue@71: -- then buttons Nenue@71: for slot, configTable in pairs(profile.buttons) do Nenue@71: -- convert old style table Nenue@71: if kb.LoadBinding(configTable) then Nenue@76: Nenue@71: if not configTable.assignedKeys then Nenue@75: configTable.assignedKeys = {GetBindingKey(configTable.command)} Nenue@71: end Nenue@75: --if configTable.dynamicType == 'talent' then Nenue@75: -- kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName) Nenue@75: --end Nenue@74: for _, key in pairs(configTable.assignedKeys) do Nenue@76: local command = configTable.command Nenue@76: cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command) Nenue@76: SetBinding(key, command) Nenue@76: if commandActions[command] and not tContains(commandActions[command], key) then Nenue@76: tinsert(commandActions[command], key) Nenue@76: end Nenue@74: end Nenue@74: Nenue@71: end Nenue@71: end Nenue@70: end Nenue@70: Nenue@70: kb.ApplyAllBindings =function () Nenue@74: print('|cFFFFFF00ApplyAllBindings()') Nenue@70: wipe(kb.bindings) Nenue@70: --kb:print('Loading binding profile', kb.profileName) Nenue@70: Nenue@70: -- reflect action key settings Nenue@70: if GetCVarBool("ActionButtonUseKeyDown") then Nenue@70: SkeletonKeyMacro:RegisterForClicks("AnyDown") Nenue@70: SkeletonKeyKey:RegisterForClicks("AnyDown") Nenue@70: else Nenue@70: SkeletonKeyMacro:RegisterForClicks("AnyUp") Nenue@70: SkeletonKeyKey:RegisterForClicks("AnyUp") Nenue@70: end Nenue@70: Nenue@70: for i, profile in ipairs(kb.orderedProfiles) do Nenue@70: kb.ApplyBindings(profile) Nenue@70: end Nenue@70: -- do this after to ensure that profession binds are properly overridden Nenue@70: kb.UpdateProfessionInfo() Nenue@70: Nenue@70: SaveBindings(GetCurrentBindingSet()) Nenue@72: Nenue@75: Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: Nenue@78: local AddSpellInfo = function(id, name, icon, dynamicType, dynamicID, dynamicIndex, dynamicSubIndex, isAvailable) Nenue@78: local spell = kb.DynamicSpells[id] or {} Nenue@78: spell.actionName = name Nenue@78: spell.dynamicType = dynamicType Nenue@78: spell.dynamicID = dynamicID Nenue@78: spell.iconPath = icon Nenue@78: spell.dynamicIndex = dynamicIndex Nenue@78: spell.dynamicSubIndex = dynamicSubIndex Nenue@78: spell.isAvailable = isAvailable Nenue@78: spell.actionType = 'spell' Nenue@78: spell.spellbookType = BOOKTYPE_SPELL Nenue@78: kb.DynamicSpells[name] = spell Nenue@78: Nenue@78: local spellList = dynamicType and kb.DynamicSpells[dynamicType] Nenue@78: if spellList then Nenue@78: spellList[dynamicIndex] = spellList[dynamicIndex] or {} Nenue@78: spellList[dynamicIndex][dynamicSubIndex] = spell Nenue@78: end Nenue@78: Nenue@78: cprint('|cFF00FFFFSpellInfo:|r', name, isAvailable, dynamicType or 'spell') Nenue@78: end Nenue@78: Nenue@70: kb.UpdateSpecInfo = function() Nenue@70: kb.specInfo.id = GetSpecialization() Nenue@70: kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id) Nenue@70: end Nenue@70: Nenue@70: kb.UpdateMacroInfo = function() Nenue@70: print('|cFFFFFF00kb.UpdateMacroInfo()|r') Nenue@70: for index = 1, GetNumMacros() do Nenue@70: local name = GetMacroInfo(index) Nenue@70: kb.SecureAttribute(SkeletonKeyMacro, "*type-macro_"..tostring(name), 'macro') Nenue@70: kb.SecureAttribute(SkeletonKeyMacro, "*macro-macro_"..tostring(name), index) Nenue@70: end Nenue@70: end Nenue@70: Nenue@78: Nenue@70: kb.UpdateTalentInfo = function() Nenue@78: print('|cFFFFFF00kb.UpdateSpells()|r') Nenue@78: cprint('|cFFFFFF00kb.UpdateSpells()|r') Nenue@70: if kb.talentsPushed then Nenue@70: return Nenue@70: end Nenue@70: for row =1, MAX_TALENT_TIERS do Nenue@70: for col = 1, NUM_TALENT_COLUMNS do Nenue@70: local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1) Nenue@78: local talentInfo = kb.DynamicSpells[spellID] or {} Nenue@70: if spellID then Nenue@78: AddSpellInfo(spellID, talentName, icon, 'talent', talentID, row, col, selected) Nenue@70: end Nenue@70: Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: for row = 1, MAX_PVP_TALENT_TIERS do Nenue@70: for col = 1, MAX_PVP_TALENT_COLUMNS do Nenue@78: local talentID, talentName, icon, selected, available, spellID, unlocked = GetPvpTalentInfo(row, col, 1) Nenue@70: if spellID then Nenue@78: AddSpellInfo(spellID, talentName, icon, 'talent', talentID, row, col, selected) Nenue@70: end Nenue@70: end Nenue@70: end Nenue@70: Nenue@78: local numTabs = GetNumSpellTabs() Nenue@78: for i = 1, numTabs do Nenue@78: local name, texture, offset, numSpells = GetSpellTabInfo(i) Nenue@78: for spellLine = offset+1, offset+numSpells do Nenue@78: local skillType, spellID = GetSpellBookItemInfo(spellLine) Nenue@78: if skillType == 'SPELL' then Nenue@78: local name, _, icon = GetSpellInfo(spellID) Nenue@78: AddSpellInfo(spellID, name, icon, nil, nil, nil, nil, true) Nenue@78: elseif skillType == 'FLYOUT' then Nenue@78: local flyoutID = GetFlyoutID(spellLine) Nenue@78: local _, _, numSlots = GetFlyoutInfo(flyoutID) Nenue@78: if numSlots then Nenue@78: for slot = 1, numSlots do Nenue@78: local spellID, isKnown = GetFlyoutSlotInfo(flyoutID, slot) Nenue@78: local name, rank, icon = GetSpellInfo(spellID) Nenue@78: AddSpellInfo(spellID, name, icon, nil, nil, nil, nil, true) Nenue@78: end Nenue@78: end Nenue@78: end Nenue@78: end Nenue@78: end Nenue@78: Nenue@78: Nenue@78: Nenue@70: kb.talentsPushed = true Nenue@70: kb.UpdateDynamicButtons('talent') Nenue@70: end Nenue@78: kb.UpdateSpells = kb.UpdateTalentInfo Nenue@70: Nenue@70: kb.UpdateProfessionInfo = function() Nenue@70: wipe(kb.ProfessionCache) Nenue@70: local profs = {GetProfessions() } Nenue@70: --print(GetProfessions()) Nenue@70: local primaryNum = 0 Nenue@70: for i = 1, 6 do Nenue@70: if profs[i] then Nenue@70: local profID = profs[i] Nenue@70: local profName, texture, _, _, numSpells, spellOffset = GetProfessionInfo(profID) Nenue@70: cprint(i, profID, profName, numSpells, spellOffset) Nenue@70: if not SECONDARY_PROFESSIONS[profID] then Nenue@70: primaryNum = primaryNum + 1 Nenue@70: end Nenue@70: local profNum = SECONDARY_PROFESSIONS[profID] or primaryNum Nenue@70: cprint(i, profNum) Nenue@70: Nenue@70: Nenue@70: for j = 1, numSpells do Nenue@70: local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION) Nenue@70: cprint(j, spellName) Nenue@70: local profInfo = { Nenue@70: actionType = 'spell', Nenue@70: actionName = spellName, Nenue@70: actionID = spellID, Nenue@70: iconPath = icon, Nenue@70: dynamicIndex = i, Nenue@70: dynamicSubIndex = j, Nenue@70: dynamicType = 'profession', Nenue@70: spellbookOffset = (spellOffset+j), Nenue@70: spellbookType = BOOKTYPE_PROFESSION, Nenue@70: isAvailable = true, Nenue@78: dynamicID = profID, Nenue@70: } Nenue@70: Nenue@70: kb.SecureAttribute(SkeletonKeyKey, "*type-profession_"..i .. '_' ..j, "spell") Nenue@70: kb.SecureAttribute(SkeletonKeyKey, "*spell-profession_"..i .. '_' ..j, spellName) Nenue@70: Nenue@70: Nenue@70: kb.DynamicSpells[spellName] = profInfo Nenue@70: kb.DynamicSpells[spellID] = profInfo Nenue@70: Nenue@78: kb.DynamicSpells.profession[spellName] = profInfo Nenue@78: kb.DynamicSpells.profession[spellID] = profInfo Nenue@70: kb.DynamicSpells.profession[i] = kb.DynamicSpells.profession[i] or {} Nenue@70: kb.DynamicSpells.profession[i][j] = profInfo Nenue@70: --print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j) Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: end Nenue@70: Nenue@70: kb.UpdateDynamicButtons('profession') Nenue@70: end Nenue@70: Nenue@70: Nenue@70: Nenue@70: kb.UpdatePetInfo = function() Nenue@70: local hasPetSpells, petType = HasPetSpells() Nenue@70: Nenue@70: -- reconcile saved data if it becomes available Nenue@70: if kb.db then Nenue@70: kb.db.petSpellsDB = kb.db.petSpellsDB or {} Nenue@70: kb.db.petSpellsDB.subtext = kb.db.petSpellsDB.subtext or {} Nenue@70: kb.db.petSpellsDB.spell = kb.db.petSpellsDB.spell or {} Nenue@70: local spellCache = kb.db.petSpellsDB.spell Nenue@70: local subtextCache = kb.db.petSpellsDB.subtext Nenue@70: if petSpellCache then Nenue@70: for k,v in pairs(petSpellCache) do Nenue@70: if not spellCache[k] then Nenue@70: spellCache[k] = v Nenue@70: end Nenue@70: end Nenue@70: end Nenue@70: petSpellCache = spellCache Nenue@70: if petSubtextCache then Nenue@70: for k,v in pairs(petSubtextCache) do Nenue@70: if not subtextCache[k] then Nenue@70: subtextCache[k] = v Nenue@70: end Nenue@70: end Nenue@70: end Nenue@70: petSubtextCache = subtextCache Nenue@70: else Nenue@70: petSpellCache = {} Nenue@70: petSubtextCache = {} Nenue@70: end Nenue@70: Nenue@70: if PetHasSpellbook() then Nenue@70: --print('PET SPELLBOOK') Nenue@70: local spellbookOffset = 1 Nenue@70: local specialNum = {} Nenue@70: local newSubtextItems = false Nenue@70: Nenue@70: repeat Nenue@70: Nenue@70: local spellType, spellID = GetSpellBookItemInfo(spellbookOffset, BOOKTYPE_PET) Nenue@70: local spellName, subText = GetSpellBookItemName(spellbookOffset, BOOKTYPE_PET) Nenue@70: local texture = GetSpellBookItemTexture(spellbookOffset, BOOKTYPE_PET) Nenue@70: if (spellType == 'SPELL') and (not IsPassiveSpell(spellbookOffset, BOOKTYPE_PET)) then Nenue@70: local info = kb.PetCache[spellName] or {} Nenue@70: kb.PetCache.spellslot[spellName] = {spellbookOffset, spellName, subText, spellID, texture} Nenue@70: --print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText) Nenue@70: Nenue@70: if subText then Nenue@70: kb.PetCache.subtext[subText] = kb.PetCache.subtext[subText] or {} Nenue@70: specialNum[subText] = (specialNum[subText] or 0) + 1 Nenue@70: Nenue@70: petSpellCache[spellName] = subText Nenue@70: petSubtextCache[subText] = petSubtextCache[subText] or {} Nenue@70: Nenue@70: -- add to the list Nenue@70: if not petSubtextCache[subText][spellName] then Nenue@70: petSubtextCache[subText][spellName] = true Nenue@70: newSubtextItems = true Nenue@70: --print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID, texture, specialNum[subText]) Nenue@70: end Nenue@70: Nenue@70: Nenue@70: Nenue@70: local entry = {spellbookOffset, spellName, subText, spellID, texture, specialNum[subText] } Nenue@70: Nenue@70: Nenue@70: info.spellbookOffset = spellbookOffset Nenue@70: info.spellbookType = BOOKTYPE_PET Nenue@70: info.actionName = spellName Nenue@70: info.spellID = spellID Nenue@70: info.dynamicType = 'petaction' Nenue@70: info.dynamicID = spellID Nenue@70: info.dynamicIndex = subText Nenue@70: info.dynamicSubIndex = specialNum[subText] Nenue@70: info.isAvailable = true Nenue@70: Nenue@70: kb.PetCache.special[spellName] = info Nenue@70: kb.PetCache.subtext[subText][specialNum[subText]] = info Nenue@78: Nenue@70: kb.DynamicSpells[spellName] = info Nenue@70: kb.DynamicSpells[spellID] = info Nenue@70: Nenue@70: end Nenue@70: Nenue@70: if spellID then Nenue@70: kb.PetCache.spell[spellbookOffset] = {spellID, spellName, subText} Nenue@70: --print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText) Nenue@70: end Nenue@70: Nenue@70: kb.PetCache[spellName] = info Nenue@70: end Nenue@70: Nenue@70: spellbookOffset = spellbookOffset + 1 Nenue@70: until spellType == nil Nenue@70: Nenue@70: if newSubtextItems then Nenue@70: Nenue@70: local macrotext = "" Nenue@70: for subText, spells in pairs(petSubtextCache) do Nenue@70: if specialNum[subText] then Nenue@70: for spellName, enabled in pairs(spells) do Nenue@70: macrotext = macrotext .. "/cast " .. spellName .. "\n" Nenue@70: end Nenue@70: kb.SecureAttribute(SkeletonKeyMacro, "*macrotext-petaction_"..subText.."_"..specialNum[subText], macrotext) Nenue@70: end Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: Nenue@70: else Nenue@70: --print('NO PET SPELLBOOK') Nenue@70: wipe(kb.PetCache.spell) Nenue@70: wipe(kb.PetCache.spellslot) Nenue@70: end Nenue@70: Nenue@70: if PetHasActionBar() then Nenue@70: --print('PET ACTION BAR') Nenue@70: for i = 1, 10 do Nenue@70: Nenue@70: Nenue@70: local name, subtext, texture, isToken, isActive = GetPetActionInfo(i) Nenue@70: if name then Nenue@70: kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive } Nenue@70: Nenue@70: Nenue@70: end Nenue@70: --print('|cFFFFFF00action['..i..']|r', name, subtext, texture) Nenue@70: end Nenue@70: else Nenue@70: --print('NO PET ACTION BAR') Nenue@70: wipe(kb.PetCache.action) Nenue@70: end Nenue@70: Nenue@70: kb.UpdateDynamicButtons('petaction') Nenue@70: Nenue@70: end Nenue@70: Nenue@70: kb.UpdateSystemBinds = function() Nenue@70: wipe(kb.SystemBindings) Nenue@70: local n = GetNumBindings() Nenue@70: for i=1, n do Nenue@70: local command, key1, key2 = GetBinding(i) Nenue@70: if not command:match('ACTION.*%d+') then Nenue@70: if key1 then Nenue@70: kb.SystemBindings[key1] = command Nenue@70: end Nenue@70: if key2 then Nenue@70: kb.SystemBindings[key2] = command Nenue@70: end Nenue@70: else Nenue@70: --print('ignoring action button binding', command) Nenue@70: end Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: kb.UpdateDynamicButtons = function(dynamicType) Nenue@70: for i, button in ipairs(kb.buttons) do Nenue@70: if button.isDynamic == dynamicType then Nenue@70: kb.UpdateSlot(button, true) Nenue@70: end Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: kb.pendingAttributes = {} Nenue@70: kb.SecureAttribute = function(target, name, value) Nenue@70: if InCombatLockdown() then Nenue@70: if #kb.pendingAttributes == 0 then Nenue@70: kb:print(kb.L('Key bindings will be applied when you exit combat.')) Nenue@70: end Nenue@70: tinsert(kb.pendingAttributes, {target, name, value}) Nenue@70: SkeletonKey:RegisterEvent('PLAYER_REGEN_ENABLED') Nenue@70: else Nenue@70: --cprint('|cFFFF4444' .. target:GetName()..'|r.|cFFFFFF00'.. tostring(name)..'|r = "'..tostring(value)..'"') Nenue@70: target:SetAttribute(name, value) Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: kb.PLAYER_REGEN_ENABLED = function() Nenue@70: if #kb.pendingAttributes >= 1 then Nenue@70: local args = tremove(kb.pendingAttributes) Nenue@70: while args do Nenue@70: local target, name, value = unpack(args) Nenue@70: --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"') Nenue@70: cprint('deferred', target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"') Nenue@70: target:SetAttribute(name, value) Nenue@70: args = tremove(kb.pendingAttributes) Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: if #kb.pendingCalls >= 1 then Nenue@70: Nenue@70: local func = tremove(kb.pendingCalls) Nenue@70: while func do Nenue@70: func() Nenue@70: end Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: kb.UpdateBindingsCache = function(actionType, actionID, bindings) Nenue@70: local indexKey = actionType .. '_' .. actionID Nenue@70: kb.bindings[indexKey] = bindings Nenue@70: Nenue@70: cprint('|cFF00FF00'..indexKey..'|r = {'.. table.concat(bindings,', ').. '}') Nenue@70: tinsert(kb.ChangedBindings, {actionType, actionID}) Nenue@70: end