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: --kb.ChangedBindings = {} Nenue@70: --kb.ActionTypes = {} 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@70: if kb.ProfessionCache[id] then Nenue@70: attributeName = "profession_".. kb.ProfessionCache[id].dynamicIndex .. '_' .. kb.ProfessionCache[id].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@70: return CLICK_KEYBINDER_KEY, tostring(name), id, 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@70: local target, attributeName, attributeValue, button = atype[actionType](id, name) Nenue@70: local command = target .. attributeName Nenue@70: Nenue@70: return attributeName, attributeValue, command, target, button Nenue@70: end Nenue@70: Nenue@70: Nenue@70: Nenue@70: Nenue@70: kb.ApplyTalentBinding = function(talentInfo, cache) Nenue@70: talentInfo.assignedKeys = talentInfo.assignedKeys or {} Nenue@70: for i , key in pairs(talentInfo.assignedKeys) do Nenue@70: local command = CLICK_KEYBINDER_KEY.. talentInfo.actionName Nenue@70: SetBinding(key, command) Nenue@70: cprint(' **', i, '->', command) Nenue@70: tinsert(cache, talentInfo) Nenue@70: end Nenue@70: end Nenue@70: kb.CacheTalentBinding = function(talentInfo, cache) Nenue@70: Nenue@70: local spellID = talentInfo.actionID Nenue@70: cache[spellID] = cache[spellID] or {} Nenue@70: cache[spellID] = talentInfo Nenue@70: cprint(spellID, unpack(kb.TalentBindings[spellID])) Nenue@70: end Nenue@70: Nenue@70: Nenue@70: do 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 Nenue@72: cprint(GetSpellInfo(actionID)) Nenue@72: cprint(GetSpellInfo(name)) Nenue@72: if GetSpellInfo(name) then Nenue@72: isAvailable = true Nenue@70: end Nenue@71: local dynamicInfo = kb.DynamicSpells[name] Nenue@70: if dynamicInfo then Nenue@71: configTable.assignedKeys = configTable.assignedKeys or {GetBindingKey(configTable.command)} 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@70: end Nenue@71: Nenue@70: else Nenue@70: if actionType ~= 'macro' then Nenue@70: actionPrefix = '*macrotext-' Nenue@70: end Nenue@70: Nenue@70: specialButtonType = 'macro' 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@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@71: if version < 310 then Nenue@71: kb.UpgradeProfile(profile) Nenue@71: end Nenue@71: Nenue@71: -- do flat bindings to start Nenue@71: for key, command in pairs(profile.bindings) do Nenue@71: command = command:gsub('KeyBinder', 'SkeletonKey') Nenue@71: profile.bindings[key] = command Nenue@71: cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command) Nenue@71: SetBinding(key, command) Nenue@71: if commandActions[command] and not tContains(commandActions[command], key) then Nenue@71: tinsert(commandActions[command], key) Nenue@71: end Nenue@71: end 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@71: local talent = profile.talents[configTable.actionName] Nenue@71: if talent then Nenue@71: configTable.assignedKeys = talent.assignedKeys Nenue@71: end Nenue@71: if not configTable.assignedKeys then Nenue@71: configTable.assignedKeys = {GetBindingKey(configTable.command) } Nenue@71: end Nenue@71: if configTable.dynamicType then Nenue@71: kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName) Nenue@71: end Nenue@71: end Nenue@71: end Nenue@70: end Nenue@70: Nenue@70: kb.ApplyAllBindings =function () Nenue@70: cprint('|cFF0088FFApplyAllBindings()') Nenue@70: wipe(kb.TalentBindings) 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@70: end Nenue@70: end Nenue@70: Nenue@70: Nenue@70: kb.specInfo = {} 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@70: kb.UpdateTalentInfo = function() Nenue@70: print('|cFFFFFF00kb.UpdateTalentInfo()|r') Nenue@70: if kb.talentsPushed then Nenue@70: return Nenue@70: end Nenue@70: wipe(kb.TalentCache) 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@70: local talentInfo = kb.TalentCache[spellID] or {} Nenue@70: if spellID then Nenue@70: talentInfo.actionType = 'spell' Nenue@70: talentInfo.actionName = talentName Nenue@70: talentInfo.dynamicType = 'talent' Nenue@70: talentInfo.dynamicID = talentID Nenue@70: talentInfo.dynamicIndex = row Nenue@70: talentInfo.dynamicSubIndex = col Nenue@70: talentInfo.actionID = spellID Nenue@70: talentInfo.isAvailable = selected Nenue@70: kb.DynamicSpells[spellID] = talentInfo Nenue@70: kb.DynamicSpells[talentName] = talentInfo Nenue@70: end Nenue@70: Nenue@70: --print('Talent ', row, col, spellID, talentName) 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@70: local id, name, icon, selected, available, spellID, unlocked = GetPvpTalentInfo(row, col, 1) Nenue@70: if spellID then Nenue@70: local talentInfo = kb.TalentCache[spellID] or {} Nenue@70: talentInfo.actionType = 'spell' Nenue@70: talentInfo.actionName = name Nenue@70: talentInfo.dynamicType = 'talent' Nenue@70: talentInfo.dynamicID = id Nenue@70: talentInfo.actionID = spellID Nenue@70: talentInfo.isAvailable = selected Nenue@70: kb.DynamicSpells[spellID] = talentInfo Nenue@70: kb.DynamicSpells[name] = talentInfo Nenue@70: end Nenue@70: end Nenue@70: end Nenue@70: Nenue@70: kb.talentsPushed = true Nenue@70: Nenue@70: kb.UpdateDynamicButtons('talent') Nenue@70: end 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: kb.ProfessionCache[profNum] = kb.ProfessionCache[profNum] or {} 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: statusText = 'Profession ' .. i, 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@70: -- need to check if necessary Nenue@70: uniqueID = 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: kb.ProfessionCache[spellName] = profInfo Nenue@70: kb.ProfessionCache[spellID] = profInfo Nenue@70: Nenue@70: kb.DynamicSpells[spellName] = profInfo Nenue@70: kb.DynamicSpells[spellID] = profInfo Nenue@70: 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@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: Nenue@70: tinsert(kb.pendingAttributes, {target, name, value}) Nenue@70: SkeletonKey:RegisterEvent('PLAYER_REGEN_ENABLED') Nenue@70: Nenue@70: else Nenue@70: 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