annotate ActionTemplates.lua @ 73:68365bda5ab5

oops macros broke again
author Nenue
date Sat, 07 Jan 2017 12:52:05 -0500
parents c48913c5924c
children 9824d524a661
rev   line source
Nenue@70 1 -- SkeletonKey
Nenue@70 2 -- ActionTemplates.lua
Nenue@70 3 -- Created: 7/29/2016 9:14 PM
Nenue@70 4 -- %file-revision%
Nenue@70 5 -- Code dealing with the implementation of action hotkeys
Nenue@70 6
Nenue@70 7 local tostring, tonumber, pairs, ipairs = tostring, tonumber, pairs, ipairs
Nenue@70 8 local unpack, SetBinding = unpack, SetBinding
Nenue@70 9 local tinsert, tContains, select, wipe = tinsert, tContains, select, table.wipe
Nenue@70 10 local GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo = GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo
Nenue@70 11 local GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell = GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell
Nenue@70 12 local PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells = PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells
Nenue@70 13 local GetProfessions, GetProfessionInfo, GetTalentInfo = GetProfessions, GetProfessionInfo, GetTalentInfo
Nenue@70 14 local GetNumBindings, GetBinding = GetNumBindings, GetBinding
Nenue@70 15
Nenue@70 16 local _, kb = ...
Nenue@70 17 local print = (DEVIAN_PNAME == 'SkeletonKey') and function(...) print('SK', ...) end or nop
Nenue@70 18 local cprint = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('Cfg', ...) end or nop
Nenue@70 19
Nenue@70 20 local CLICK_KEYBINDER_MACRO = "CLICK SkeletonKeyMacro:"
Nenue@70 21 local CLICK_KEYBINDER_KEY = "CLICK SkeletonKeyKey:"
Nenue@70 22 local PET_BASIC_SUBTEXT = 'Basic Attack'
Nenue@70 23 local PET_SPECIAL_SUBTEXT = 'Special Ability'
Nenue@70 24 local PETACTION_SCRIPT = {
Nenue@70 25 [PET_ACTION_MOVE_TO] = {'pet_move_to', SLASH_PET_MOVE_TO1},
Nenue@70 26 [PET_ACTION_ATTACK] = {'pet_attack', SLASH_PET_ATTACK1},
Nenue@70 27 [PET_ACTION_FOLLOW] = {'pet_follow', SLASH_PET_FOLLOW1},
Nenue@70 28 [PET_ACTION_WAIT] = {'pet_stay', SLASH_PET_STAY1 },
Nenue@70 29 [PET_MODE_AGGRESSIVE] = {'pet_aggressive', SLASH_PET_AGGRESSIVE1 },
Nenue@70 30 [PET_MODE_DEFENSIVE] = { 'pet_defensive', SLASH_PET_DEFENSIVE1},
Nenue@70 31 [PET_MODE_PASSIVE] = { 'pet_passive', SLASH_PET_PASSIVE1},
Nenue@70 32 [PET_MODE_ASSIST] = {'pet_assist', SLASH_PET_ASSIST1},
Nenue@70 33 }
Nenue@70 34 local SECONDARY_PROFESSIONS = {
Nenue@70 35 [5] = 3,
Nenue@70 36 [7] = 4,
Nenue@70 37 [9] = 5,
Nenue@70 38 [10] = 6
Nenue@70 39 }
Nenue@70 40 local petSpellCache,petSubtextCache
Nenue@70 41 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
Nenue@70 42
Nenue@70 43 --kb.ChangedBindings = {}
Nenue@70 44 --kb.ActionTypes = {}
Nenue@70 45
Nenue@70 46 local atype = kb.ActionTypes
Nenue@70 47
Nenue@70 48 --- Caps Lock
Nenue@70 49 atype['mount'] = function(id, name)
Nenue@70 50 if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then
Nenue@70 51 return CLICK_KEYBINDER_MACRO, 'mount_random', "/script C_MountJournal.SummonByID(0)", SkeletonKeyMacro
Nenue@70 52 else
Nenue@70 53 return CLICK_KEYBINDER_MACRO, 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", SkeletonKeyMacro
Nenue@70 54 end
Nenue@70 55 end
Nenue@70 56
Nenue@70 57 atype['macro'] = function(id, name)
Nenue@70 58 local _, _, text = GetMacroInfo(id)
Nenue@70 59 return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), name, SkeletonKeyMacro
Nenue@70 60 end
Nenue@70 61
Nenue@70 62 atype['equipset'] = function(id, name)
Nenue@70 63 return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")", SkeletonKeyMacro
Nenue@70 64 end
Nenue@70 65
Nenue@70 66 atype['spell'] = function(id, name)
Nenue@70 67 local attributeName = name
Nenue@70 68 if kb.ProfessionCache[id] then
Nenue@70 69 attributeName = "profession_".. kb.ProfessionCache[id].dynamicIndex .. '_' .. kb.ProfessionCache[id].dynamicSubIndex
Nenue@70 70 end
Nenue@70 71 return CLICK_KEYBINDER_KEY, attributeName, name, SkeletonKeyKey
Nenue@70 72 end
Nenue@70 73
Nenue@70 74 atype['petaction'] = function(_, name)
Nenue@70 75 -- ID doesn't exist for basic commands, even though they can be picked up
Nenue@70 76 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name)
Nenue@70 77
Nenue@70 78 if not petSpellCache then
Nenue@70 79 kb.UpdatePetInfo()
Nenue@70 80 end
Nenue@70 81 -- Compose a multi-macro for subtext abilities
Nenue@70 82 if petSpellCache[name] then
Nenue@70 83 attributeValue = ""
Nenue@70 84 for spellName, enabled in pairs(petSubtextCache[petSpellCache[name]]) do
Nenue@70 85 attributeValue = attributeValue .. "/cast " .. spellName .. "\n"
Nenue@70 86 end
Nenue@70 87 end
Nenue@70 88
Nenue@70 89 if PETACTION_SCRIPT[name] then
Nenue@70 90 attributeName, attributeValue = unpack(PETACTION_SCRIPT[name])
Nenue@70 91 elseif kb.PetCache.special[name] then
Nenue@70 92 attributeName = "petaction_"..kb.PetCache.special[name][3].."_" .. tonumber(kb.PetCache.special[name][6])
Nenue@70 93 end
Nenue@70 94 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue, SkeletonKeyMacro
Nenue@70 95 end
Nenue@70 96
Nenue@70 97 atype['battlepet'] = function(id, name)
Nenue@70 98 return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name), SkeletonKeyMacro
Nenue@70 99 end
Nenue@70 100
Nenue@70 101 atype['item'] = function(id, name)
Nenue@70 102 return CLICK_KEYBINDER_KEY, tostring(name), id, SkeletonKeyKey
Nenue@70 103 end
Nenue@70 104
Nenue@70 105
Nenue@70 106 --- Resolves the SecureActionButton attribute names used for the given action
Nenue@70 107 kb.RegisterAction = function(actionType, id, name)
Nenue@70 108 assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`')
Nenue@70 109 local target, attributeName, attributeValue, button = atype[actionType](id, name)
Nenue@70 110 local command = target .. attributeName
Nenue@70 111
Nenue@70 112 return attributeName, attributeValue, command, target, button
Nenue@70 113 end
Nenue@70 114
Nenue@70 115
Nenue@70 116
Nenue@70 117
Nenue@70 118 kb.ApplyTalentBinding = function(talentInfo, cache)
Nenue@70 119 talentInfo.assignedKeys = talentInfo.assignedKeys or {}
Nenue@70 120 for i , key in pairs(talentInfo.assignedKeys) do
Nenue@70 121 local command = CLICK_KEYBINDER_KEY.. talentInfo.actionName
Nenue@70 122 SetBinding(key, command)
Nenue@70 123 cprint(' **', i, '->', command)
Nenue@70 124 tinsert(cache, talentInfo)
Nenue@70 125 end
Nenue@70 126 end
Nenue@70 127 kb.CacheTalentBinding = function(talentInfo, cache)
Nenue@70 128
Nenue@70 129 local spellID = talentInfo.actionID
Nenue@70 130 cache[spellID] = cache[spellID] or {}
Nenue@70 131 cache[spellID] = talentInfo
Nenue@70 132 cprint(spellID, unpack(kb.TalentBindings[spellID]))
Nenue@70 133 end
Nenue@70 134
Nenue@70 135
Nenue@70 136 do
Nenue@70 137 local commandActions = {}
Nenue@70 138 local bindings = kb.bindings
Nenue@70 139 local key, macro = SkeletonKeyKey, SkeletonKeyMacro
Nenue@70 140 kb.LoadBinding = function( configTable)
Nenue@70 141 if configTable.command then
Nenue@70 142 configTable.command = configTable.command:gsub('KeyBinder', 'SkeletonKey')
Nenue@70 143 end
Nenue@70 144
Nenue@70 145 local command, name, icon, actionType, actionID, macroName, macroText =
Nenue@70 146 configTable.command, configTable.actionName, configTable.iconPath, configTable.actionType,
Nenue@70 147 configTable.actionID, configTable.macroName, configTable.macroText
Nenue@70 148
Nenue@70 149
Nenue@70 150 local indexKey = actionType..'_'..actionID
Nenue@70 151 local actionPrefix = "*"..actionType.."-"
Nenue@70 152 local button = SkeletonKeyKey
Nenue@72 153 local isAvailable
Nenue@70 154 local specialButtonType
Nenue@70 155 if actionType == 'spell' then
Nenue@72 156 cprint(GetSpellInfo(actionID))
Nenue@72 157 cprint(GetSpellInfo(name))
Nenue@72 158 if GetSpellInfo(name) then
Nenue@72 159 isAvailable = true
Nenue@70 160 end
Nenue@71 161 local dynamicInfo = kb.DynamicSpells[name]
Nenue@70 162 if dynamicInfo then
Nenue@71 163 configTable.assignedKeys = configTable.assignedKeys or {GetBindingKey(configTable.command)}
Nenue@72 164 cprint('|cFF00FFFFDynamicInfo:|r', dynamicInfo.dynamicType, table.concat(configTable.assignedKeys, ','))
Nenue@70 165 for k, v in pairs(dynamicInfo) do
Nenue@71 166 --cprint(' --', k, v)
Nenue@70 167 configTable[k] = v
Nenue@70 168 end
Nenue@70 169 end
Nenue@71 170
Nenue@70 171 else
Nenue@70 172 if actionType ~= 'macro' then
Nenue@70 173 actionPrefix = '*macrotext-'
Nenue@70 174 end
Nenue@70 175
Nenue@70 176 specialButtonType = 'macro'
Nenue@73 177 isAvailable = true
Nenue@70 178 end
Nenue@70 179
Nenue@72 180 if isAvailable then
Nenue@70 181
Nenue@72 182 local attributeSuffix, attributeValue, command, target, button = kb.RegisterAction(actionType, actionID, name)
Nenue@72 183 local actionKey = actionPrefix .. attributeSuffix
Nenue@72 184 cprint('|cFF00FF88LoadBinding()|r', button:GetName(), "*type-"..attributeSuffix, actionType, '|cFFFFFF00'..actionKey, attributeValue, isAvailable)
Nenue@70 185
Nenue@70 186
Nenue@70 187 kb.SecureAttribute(button, "*type-"..attributeSuffix, specialButtonType or actionType)
Nenue@70 188 kb.SecureAttribute(button, actionKey, attributeValue)
Nenue@72 189
Nenue@72 190 cprint('|cFFFF4400add', name, isAvailable, indexKey, unpack(configTable.assignedKeys))
Nenue@70 191 kb.bindings[indexKey] = configTable.assignedKeys
Nenue@70 192 commandActions[command] = kb.bindings[indexKey]
Nenue@70 193 return command, kb.bindings[indexKey]
Nenue@70 194 else
Nenue@72 195 if kb.bindings[indexKey] then
Nenue@72 196 cprint('|cFFFF4400remove', name, isAvailable, indexKey, unpack(configTable.assignedKeys))
Nenue@72 197 kb.bindings[indexKey] = nil
Nenue@72 198 end
Nenue@72 199
Nenue@70 200 return nil
Nenue@70 201 end
Nenue@70 202 end
Nenue@70 203
Nenue@71 204
Nenue@70 205 local usedSlots = {}
Nenue@71 206 kb.UpgradeProfile = function(profile)
Nenue@70 207 wipe(usedSlots)
Nenue@70 208 for slot, configTable in pairs(profile.buttons) do
Nenue@70 209
Nenue@71 210 -- convert old style table
Nenue@70 211 if #configTable >= 1 then
Nenue@70 212 local command, name, icon, actionType, actionID, macroName, macroText, spellbookSlot, spellbookType = unpack(configTable)
Nenue@70 213
Nenue@70 214 cprint('|CFFFF4400Fixing pad entry', slot, command, name)
Nenue@70 215 local assignedKeys = {GetBindingKey(command)}
Nenue@70 216 for k,v in pairs(profile.bindings) do
Nenue@70 217 if v == command then
Nenue@70 218 tinsert(assignedKeys, k)
Nenue@70 219 end
Nenue@70 220 end
Nenue@70 221
Nenue@70 222 configTable = {
Nenue@70 223 command = command,
Nenue@70 224 actionType = actionType,
Nenue@70 225 actionName = name,
Nenue@70 226 actionID = actionID,
Nenue@70 227 macroName = macroName,
Nenue@70 228 macroText = macroText,
Nenue@70 229 iconPath = icon,
Nenue@70 230 spellbookSlot = spellbookSlot,
Nenue@70 231 spellbookType = spellbookType,
Nenue@70 232 assignedKeys = assignedKeys
Nenue@70 233 }
Nenue@71 234
Nenue@71 235 local dynamic = kb.DynamicSpells[name]
Nenue@71 236 if dynamic then
Nenue@71 237 configTable.dynamicType = dynamic.dynamicType
Nenue@71 238 configTable.dynamicIndex = dynamic.dynamicIndex
Nenue@71 239 configTable.dynamicSubIndex = dynamic.dynamicSubIndex
Nenue@71 240 configTable.dynamicID = dynamic.dynamicID
Nenue@71 241 if configTable.dynamicType == 'talent' then
Nenue@71 242 profile.talents[name] = configTable
Nenue@71 243 end
Nenue@71 244 end
Nenue@71 245
Nenue@71 246
Nenue@70 247 kb.currentProfile.buttons[slot] = configTable
Nenue@70 248 end
Nenue@70 249 if not configTable.actionID then
Nenue@70 250 configTable.actionID = configTable.actionName
Nenue@70 251 end
Nenue@70 252 if not configTable.iconPath then
Nenue@70 253 print('corrected missing icon')
Nenue@70 254 configTable.iconPath = GetSpellTexture(configTable.actionName)
Nenue@70 255 end
Nenue@70 256
Nenue@70 257 usedSlots[configTable.actionName or configTable.actionID] = true
Nenue@70 258 usedSlots[configTable.command] = true
Nenue@70 259 end
Nenue@70 260
Nenue@70 261
Nenue@71 262 -- clean up legacy data
Nenue@70 263 for spellName, talentInfo in pairs(profile.talents) do
Nenue@70 264 if not usedSlots[spellName] then
Nenue@70 265 cprint('|cFFFF4400Unslotted talent', spellName)
Nenue@70 266 profile.talents[spellName] = nil
Nenue@70 267 end
Nenue@70 268 end
Nenue@70 269 for command in pairs(profile.bound) do
Nenue@70 270 if not usedSlots[command] then
Nenue@70 271 cprint('|cFFFF4400Unslotted bound entry', command)
Nenue@70 272 profile.bound[command] = nil
Nenue@70 273 profile.commands[command] = nil
Nenue@70 274 end
Nenue@70 275 end
Nenue@70 276 for command in pairs(profile.commands) do
Nenue@70 277 if not usedSlots[command] then
Nenue@70 278 cprint('|cFFFF4400Unslotted command entry', command)
Nenue@70 279 profile.commands[command] = nil
Nenue@70 280 end
Nenue@70 281 end
Nenue@71 282 end
Nenue@70 283
Nenue@71 284 kb.ApplyBindings = function (profile)
Nenue@71 285 cprint('|cFF0088FFApplyBindings()')
Nenue@71 286 --cprint('binding profile', profile)
Nenue@71 287
Nenue@71 288 local version = profile.versionID or 0
Nenue@71 289 if version < 310 then
Nenue@71 290 kb.UpgradeProfile(profile)
Nenue@71 291 end
Nenue@71 292
Nenue@71 293 -- do flat bindings to start
Nenue@71 294 for key, command in pairs(profile.bindings) do
Nenue@71 295 command = command:gsub('KeyBinder', 'SkeletonKey')
Nenue@71 296 profile.bindings[key] = command
Nenue@71 297 cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command)
Nenue@71 298 SetBinding(key, command)
Nenue@71 299 if commandActions[command] and not tContains(commandActions[command], key) then
Nenue@71 300 tinsert(commandActions[command], key)
Nenue@71 301 end
Nenue@71 302 end
Nenue@71 303
Nenue@71 304 -- then buttons
Nenue@71 305 for slot, configTable in pairs(profile.buttons) do
Nenue@71 306 -- convert old style table
Nenue@71 307 if kb.LoadBinding(configTable) then
Nenue@71 308 local talent = profile.talents[configTable.actionName]
Nenue@71 309 if talent then
Nenue@71 310 configTable.assignedKeys = talent.assignedKeys
Nenue@71 311 end
Nenue@71 312 if not configTable.assignedKeys then
Nenue@71 313 configTable.assignedKeys = {GetBindingKey(configTable.command) }
Nenue@71 314 end
Nenue@71 315 if configTable.dynamicType then
Nenue@71 316 kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName)
Nenue@71 317 end
Nenue@71 318 end
Nenue@71 319 end
Nenue@70 320 end
Nenue@70 321
Nenue@70 322 kb.ApplyAllBindings =function ()
Nenue@70 323 cprint('|cFF0088FFApplyAllBindings()')
Nenue@70 324 wipe(kb.TalentBindings)
Nenue@70 325 wipe(kb.bindings)
Nenue@70 326 --kb:print('Loading binding profile', kb.profileName)
Nenue@70 327
Nenue@70 328 -- reflect action key settings
Nenue@70 329 if GetCVarBool("ActionButtonUseKeyDown") then
Nenue@70 330 SkeletonKeyMacro:RegisterForClicks("AnyDown")
Nenue@70 331 SkeletonKeyKey:RegisterForClicks("AnyDown")
Nenue@70 332 else
Nenue@70 333 SkeletonKeyMacro:RegisterForClicks("AnyUp")
Nenue@70 334 SkeletonKeyKey:RegisterForClicks("AnyUp")
Nenue@70 335 end
Nenue@70 336
Nenue@70 337 for i, profile in ipairs(kb.orderedProfiles) do
Nenue@70 338 kb.ApplyBindings(profile)
Nenue@70 339 end
Nenue@70 340 -- do this after to ensure that profession binds are properly overridden
Nenue@70 341 kb.UpdateProfessionInfo()
Nenue@70 342
Nenue@70 343 SaveBindings(GetCurrentBindingSet())
Nenue@72 344
Nenue@70 345 end
Nenue@70 346 end
Nenue@70 347
Nenue@70 348
Nenue@70 349 kb.specInfo = {}
Nenue@70 350 kb.UpdateSpecInfo = function()
Nenue@70 351 kb.specInfo.id = GetSpecialization()
Nenue@70 352 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
Nenue@70 353 end
Nenue@70 354
Nenue@70 355 kb.UpdateMacroInfo = function()
Nenue@70 356 print('|cFFFFFF00kb.UpdateMacroInfo()|r')
Nenue@70 357 for index = 1, GetNumMacros() do
Nenue@70 358 local name = GetMacroInfo(index)
Nenue@70 359 kb.SecureAttribute(SkeletonKeyMacro, "*type-macro_"..tostring(name), 'macro')
Nenue@70 360 kb.SecureAttribute(SkeletonKeyMacro, "*macro-macro_"..tostring(name), index)
Nenue@70 361 end
Nenue@70 362 end
Nenue@70 363
Nenue@70 364 kb.UpdateTalentInfo = function()
Nenue@70 365 print('|cFFFFFF00kb.UpdateTalentInfo()|r')
Nenue@70 366 if kb.talentsPushed then
Nenue@70 367 return
Nenue@70 368 end
Nenue@70 369 wipe(kb.TalentCache)
Nenue@70 370 for row =1, MAX_TALENT_TIERS do
Nenue@70 371 for col = 1, NUM_TALENT_COLUMNS do
Nenue@70 372 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
Nenue@70 373 local talentInfo = kb.TalentCache[spellID] or {}
Nenue@70 374 if spellID then
Nenue@70 375 talentInfo.actionType = 'spell'
Nenue@70 376 talentInfo.actionName = talentName
Nenue@70 377 talentInfo.dynamicType = 'talent'
Nenue@70 378 talentInfo.dynamicID = talentID
Nenue@70 379 talentInfo.dynamicIndex = row
Nenue@70 380 talentInfo.dynamicSubIndex = col
Nenue@70 381 talentInfo.actionID = spellID
Nenue@70 382 talentInfo.isAvailable = selected
Nenue@70 383 kb.DynamicSpells[spellID] = talentInfo
Nenue@70 384 kb.DynamicSpells[talentName] = talentInfo
Nenue@70 385 end
Nenue@70 386
Nenue@70 387 --print('Talent ', row, col, spellID, talentName)
Nenue@70 388 end
Nenue@70 389 end
Nenue@70 390
Nenue@70 391 for row = 1, MAX_PVP_TALENT_TIERS do
Nenue@70 392 for col = 1, MAX_PVP_TALENT_COLUMNS do
Nenue@70 393 local id, name, icon, selected, available, spellID, unlocked = GetPvpTalentInfo(row, col, 1)
Nenue@70 394 if spellID then
Nenue@70 395 local talentInfo = kb.TalentCache[spellID] or {}
Nenue@70 396 talentInfo.actionType = 'spell'
Nenue@70 397 talentInfo.actionName = name
Nenue@70 398 talentInfo.dynamicType = 'talent'
Nenue@70 399 talentInfo.dynamicID = id
Nenue@70 400 talentInfo.actionID = spellID
Nenue@70 401 talentInfo.isAvailable = selected
Nenue@70 402 kb.DynamicSpells[spellID] = talentInfo
Nenue@70 403 kb.DynamicSpells[name] = talentInfo
Nenue@70 404 end
Nenue@70 405 end
Nenue@70 406 end
Nenue@70 407
Nenue@70 408 kb.talentsPushed = true
Nenue@70 409
Nenue@70 410 kb.UpdateDynamicButtons('talent')
Nenue@70 411 end
Nenue@70 412
Nenue@70 413 kb.UpdateProfessionInfo = function()
Nenue@70 414 wipe(kb.ProfessionCache)
Nenue@70 415 local profs = {GetProfessions() }
Nenue@70 416 --print(GetProfessions())
Nenue@70 417 local primaryNum = 0
Nenue@70 418 for i = 1, 6 do
Nenue@70 419 if profs[i] then
Nenue@70 420 local profID = profs[i]
Nenue@70 421 local profName, texture, _, _, numSpells, spellOffset = GetProfessionInfo(profID)
Nenue@70 422 cprint(i, profID, profName, numSpells, spellOffset)
Nenue@70 423 if not SECONDARY_PROFESSIONS[profID] then
Nenue@70 424 primaryNum = primaryNum + 1
Nenue@70 425 end
Nenue@70 426 local profNum = SECONDARY_PROFESSIONS[profID] or primaryNum
Nenue@70 427 cprint(i, profNum)
Nenue@70 428
Nenue@70 429
Nenue@70 430 kb.ProfessionCache[profNum] = kb.ProfessionCache[profNum] or {}
Nenue@70 431
Nenue@70 432 for j = 1, numSpells do
Nenue@70 433 local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION)
Nenue@70 434 cprint(j, spellName)
Nenue@70 435 local profInfo = {
Nenue@70 436 actionType = 'spell',
Nenue@70 437 actionName = spellName,
Nenue@70 438 statusText = 'Profession ' .. i,
Nenue@70 439 actionID = spellID,
Nenue@70 440 iconPath = icon,
Nenue@70 441 dynamicIndex = i,
Nenue@70 442 dynamicSubIndex = j,
Nenue@70 443 dynamicType = 'profession',
Nenue@70 444 spellbookOffset = (spellOffset+j),
Nenue@70 445 spellbookType = BOOKTYPE_PROFESSION,
Nenue@70 446 isAvailable = true,
Nenue@70 447 -- need to check if necessary
Nenue@70 448 uniqueID = profID,
Nenue@70 449 }
Nenue@70 450
Nenue@70 451 kb.SecureAttribute(SkeletonKeyKey, "*type-profession_"..i .. '_' ..j, "spell")
Nenue@70 452 kb.SecureAttribute(SkeletonKeyKey, "*spell-profession_"..i .. '_' ..j, spellName)
Nenue@70 453
Nenue@70 454 kb.ProfessionCache[spellName] = profInfo
Nenue@70 455 kb.ProfessionCache[spellID] = profInfo
Nenue@70 456
Nenue@70 457 kb.DynamicSpells[spellName] = profInfo
Nenue@70 458 kb.DynamicSpells[spellID] = profInfo
Nenue@70 459
Nenue@70 460 kb.DynamicSpells.profession[i] = kb.DynamicSpells.profession[i] or {}
Nenue@70 461 kb.DynamicSpells.profession[i][j] = profInfo
Nenue@70 462 --print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
Nenue@70 463 end
Nenue@70 464 end
Nenue@70 465
Nenue@70 466 end
Nenue@70 467
Nenue@70 468 kb.UpdateDynamicButtons('profession')
Nenue@70 469 end
Nenue@70 470
Nenue@70 471
Nenue@70 472
Nenue@70 473 kb.UpdatePetInfo = function()
Nenue@70 474 local hasPetSpells, petType = HasPetSpells()
Nenue@70 475
Nenue@70 476 -- reconcile saved data if it becomes available
Nenue@70 477 if kb.db then
Nenue@70 478 kb.db.petSpellsDB = kb.db.petSpellsDB or {}
Nenue@70 479 kb.db.petSpellsDB.subtext = kb.db.petSpellsDB.subtext or {}
Nenue@70 480 kb.db.petSpellsDB.spell = kb.db.petSpellsDB.spell or {}
Nenue@70 481 local spellCache = kb.db.petSpellsDB.spell
Nenue@70 482 local subtextCache = kb.db.petSpellsDB.subtext
Nenue@70 483 if petSpellCache then
Nenue@70 484 for k,v in pairs(petSpellCache) do
Nenue@70 485 if not spellCache[k] then
Nenue@70 486 spellCache[k] = v
Nenue@70 487 end
Nenue@70 488 end
Nenue@70 489 end
Nenue@70 490 petSpellCache = spellCache
Nenue@70 491 if petSubtextCache then
Nenue@70 492 for k,v in pairs(petSubtextCache) do
Nenue@70 493 if not subtextCache[k] then
Nenue@70 494 subtextCache[k] = v
Nenue@70 495 end
Nenue@70 496 end
Nenue@70 497 end
Nenue@70 498 petSubtextCache = subtextCache
Nenue@70 499 else
Nenue@70 500 petSpellCache = {}
Nenue@70 501 petSubtextCache = {}
Nenue@70 502 end
Nenue@70 503
Nenue@70 504 if PetHasSpellbook() then
Nenue@70 505 --print('PET SPELLBOOK')
Nenue@70 506 local spellbookOffset = 1
Nenue@70 507 local specialNum = {}
Nenue@70 508 local newSubtextItems = false
Nenue@70 509
Nenue@70 510 repeat
Nenue@70 511
Nenue@70 512 local spellType, spellID = GetSpellBookItemInfo(spellbookOffset, BOOKTYPE_PET)
Nenue@70 513 local spellName, subText = GetSpellBookItemName(spellbookOffset, BOOKTYPE_PET)
Nenue@70 514 local texture = GetSpellBookItemTexture(spellbookOffset, BOOKTYPE_PET)
Nenue@70 515 if (spellType == 'SPELL') and (not IsPassiveSpell(spellbookOffset, BOOKTYPE_PET)) then
Nenue@70 516 local info = kb.PetCache[spellName] or {}
Nenue@70 517 kb.PetCache.spellslot[spellName] = {spellbookOffset, spellName, subText, spellID, texture}
Nenue@70 518 --print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
Nenue@70 519
Nenue@70 520 if subText then
Nenue@70 521 kb.PetCache.subtext[subText] = kb.PetCache.subtext[subText] or {}
Nenue@70 522 specialNum[subText] = (specialNum[subText] or 0) + 1
Nenue@70 523
Nenue@70 524 petSpellCache[spellName] = subText
Nenue@70 525 petSubtextCache[subText] = petSubtextCache[subText] or {}
Nenue@70 526
Nenue@70 527 -- add to the list
Nenue@70 528 if not petSubtextCache[subText][spellName] then
Nenue@70 529 petSubtextCache[subText][spellName] = true
Nenue@70 530 newSubtextItems = true
Nenue@70 531 --print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID, texture, specialNum[subText])
Nenue@70 532 end
Nenue@70 533
Nenue@70 534
Nenue@70 535
Nenue@70 536 local entry = {spellbookOffset, spellName, subText, spellID, texture, specialNum[subText] }
Nenue@70 537
Nenue@70 538
Nenue@70 539 info.spellbookOffset = spellbookOffset
Nenue@70 540 info.spellbookType = BOOKTYPE_PET
Nenue@70 541 info.actionName = spellName
Nenue@70 542 info.spellID = spellID
Nenue@70 543 info.dynamicType = 'petaction'
Nenue@70 544 info.dynamicID = spellID
Nenue@70 545 info.dynamicIndex = subText
Nenue@70 546 info.dynamicSubIndex = specialNum[subText]
Nenue@70 547 info.isAvailable = true
Nenue@70 548
Nenue@70 549 kb.PetCache.special[spellName] = info
Nenue@70 550 kb.PetCache.subtext[subText][specialNum[subText]] = info
Nenue@70 551 kb.DynamicSpells[spellName] = info
Nenue@70 552 kb.DynamicSpells[spellID] = info
Nenue@70 553
Nenue@70 554 end
Nenue@70 555
Nenue@70 556 if spellID then
Nenue@70 557 kb.PetCache.spell[spellbookOffset] = {spellID, spellName, subText}
Nenue@70 558 --print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
Nenue@70 559 end
Nenue@70 560
Nenue@70 561 kb.PetCache[spellName] = info
Nenue@70 562 end
Nenue@70 563
Nenue@70 564 spellbookOffset = spellbookOffset + 1
Nenue@70 565 until spellType == nil
Nenue@70 566
Nenue@70 567 if newSubtextItems then
Nenue@70 568
Nenue@70 569 local macrotext = ""
Nenue@70 570 for subText, spells in pairs(petSubtextCache) do
Nenue@70 571 if specialNum[subText] then
Nenue@70 572 for spellName, enabled in pairs(spells) do
Nenue@70 573 macrotext = macrotext .. "/cast " .. spellName .. "\n"
Nenue@70 574 end
Nenue@70 575 kb.SecureAttribute(SkeletonKeyMacro, "*macrotext-petaction_"..subText.."_"..specialNum[subText], macrotext)
Nenue@70 576 end
Nenue@70 577 end
Nenue@70 578 end
Nenue@70 579
Nenue@70 580
Nenue@70 581 else
Nenue@70 582 --print('NO PET SPELLBOOK')
Nenue@70 583 wipe(kb.PetCache.spell)
Nenue@70 584 wipe(kb.PetCache.spellslot)
Nenue@70 585 end
Nenue@70 586
Nenue@70 587 if PetHasActionBar() then
Nenue@70 588 --print('PET ACTION BAR')
Nenue@70 589 for i = 1, 10 do
Nenue@70 590
Nenue@70 591
Nenue@70 592 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
Nenue@70 593 if name then
Nenue@70 594 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
Nenue@70 595
Nenue@70 596
Nenue@70 597 end
Nenue@70 598 --print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
Nenue@70 599 end
Nenue@70 600 else
Nenue@70 601 --print('NO PET ACTION BAR')
Nenue@70 602 wipe(kb.PetCache.action)
Nenue@70 603 end
Nenue@70 604
Nenue@70 605 kb.UpdateDynamicButtons('petaction')
Nenue@70 606
Nenue@70 607 end
Nenue@70 608
Nenue@70 609 kb.UpdateSystemBinds = function()
Nenue@70 610 wipe(kb.SystemBindings)
Nenue@70 611 local n = GetNumBindings()
Nenue@70 612 for i=1, n do
Nenue@70 613 local command, key1, key2 = GetBinding(i)
Nenue@70 614 if not command:match('ACTION.*%d+') then
Nenue@70 615 if key1 then
Nenue@70 616 kb.SystemBindings[key1] = command
Nenue@70 617 end
Nenue@70 618 if key2 then
Nenue@70 619 kb.SystemBindings[key2] = command
Nenue@70 620 end
Nenue@70 621 else
Nenue@70 622 --print('ignoring action button binding', command)
Nenue@70 623 end
Nenue@70 624 end
Nenue@70 625 end
Nenue@70 626
Nenue@70 627 kb.UpdateDynamicButtons = function(dynamicType)
Nenue@70 628 for i, button in ipairs(kb.buttons) do
Nenue@70 629 if button.isDynamic == dynamicType then
Nenue@70 630 kb.UpdateSlot(button, true)
Nenue@70 631 end
Nenue@70 632 end
Nenue@70 633 end
Nenue@70 634
Nenue@70 635 kb.pendingAttributes = {}
Nenue@70 636 kb.SecureAttribute = function(target, name, value)
Nenue@70 637 if InCombatLockdown() then
Nenue@70 638 if #kb.pendingAttributes == 0 then
Nenue@70 639 kb:print(kb.L('Key bindings will be applied when you exit combat.'))
Nenue@70 640 end
Nenue@70 641
Nenue@70 642 tinsert(kb.pendingAttributes, {target, name, value})
Nenue@70 643 SkeletonKey:RegisterEvent('PLAYER_REGEN_ENABLED')
Nenue@70 644
Nenue@70 645 else
Nenue@70 646
Nenue@70 647 --cprint('|cFFFF4444' .. target:GetName()..'|r.|cFFFFFF00'.. tostring(name)..'|r = "'..tostring(value)..'"')
Nenue@70 648 target:SetAttribute(name, value)
Nenue@70 649 end
Nenue@70 650 end
Nenue@70 651
Nenue@70 652 kb.PLAYER_REGEN_ENABLED = function()
Nenue@70 653 if #kb.pendingAttributes >= 1 then
Nenue@70 654 local args = tremove(kb.pendingAttributes)
Nenue@70 655 while args do
Nenue@70 656 local target, name, value = unpack(args)
Nenue@70 657 --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
Nenue@70 658 cprint('deferred', target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
Nenue@70 659 target:SetAttribute(name, value)
Nenue@70 660 args = tremove(kb.pendingAttributes)
Nenue@70 661 end
Nenue@70 662 end
Nenue@70 663
Nenue@70 664 if #kb.pendingCalls >= 1 then
Nenue@70 665
Nenue@70 666 local func = tremove(kb.pendingCalls)
Nenue@70 667 while func do
Nenue@70 668 func()
Nenue@70 669 end
Nenue@70 670 end
Nenue@70 671 end
Nenue@70 672
Nenue@70 673 kb.UpdateBindingsCache = function(actionType, actionID, bindings)
Nenue@70 674 local indexKey = actionType .. '_' .. actionID
Nenue@70 675 kb.bindings[indexKey] = bindings
Nenue@70 676
Nenue@70 677 cprint('|cFF00FF00'..indexKey..'|r = {'.. table.concat(bindings,', ').. '}')
Nenue@70 678 tinsert(kb.ChangedBindings, {actionType, actionID})
Nenue@70 679 end