annotate SkeletonKey/ActionTypes.lua @ 22:f6dd297cb812

- fix pet stance/actioni bindings - fix pet action availability check
author Nenue
date Sat, 30 Jul 2016 20:44:03 -0400
parents 564015ef0317
children 4804892802fe
rev   line source
Nenue@16 1 -- SkeletonKey
Nenue@16 2 -- ActionTypes.lua
Nenue@16 3 -- Created: 7/29/2016 9:14 PM
Nenue@16 4 -- %file-revision%
Nenue@16 5 --
Nenue@21 6 local tostring, tonumber, pairs, ipairs = tostring, tonumber, pairs, ipairs
Nenue@21 7 local unpack, SetBinding = unpack, SetBinding
Nenue@21 8 local tinsert, tContains, select, wipe = tinsert, tContains, select, table.wipe
Nenue@21 9 local GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo = GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo
Nenue@21 10 local GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell = GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell
Nenue@21 11 local PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells = PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells
Nenue@21 12 local GetProfessions, GetProfessionInfo, GetTalentInfo = GetProfessions, GetProfessionInfo, GetTalentInfo
Nenue@21 13 local GetNumBindings, GetBinding = GetNumBindings, GetBinding
Nenue@21 14
Nenue@21 15 local kb, print, wrap = LibStub('LibKraken').register(KeyBinder, 'Info')
Nenue@17 16 local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end
Nenue@16 17
Nenue@17 18 local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:"
Nenue@17 19 local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:"
Nenue@21 20 local PET_BASIC_SUBTEXT = 'Basic Attack'
Nenue@21 21 local PET_SPECIAL_SUBTEXT = 'Special Ability'
Nenue@16 22 local PETACTION_SCRIPT = {
Nenue@22 23 [PET_ACTION_MOVE_TO] = {'pet_move_to', SLASH_PET_MOVE_TO1},
Nenue@22 24 [PET_ACTION_ATTACK] = {'pet_attack', SLASH_PET_ATTACK1},
Nenue@22 25 [PET_ACTION_FOLLOW] = {'pet_follow', SLASH_PET_FOLLOW1},
Nenue@22 26 [PET_ACTION_WAIT] = {'pet_stay', SLASH_PET_STAY1 },
Nenue@22 27 [PET_MODE_AGGRESSIVE] = {'pet_aggressive', SLASH_PET_AGGRESSIVE1 },
Nenue@22 28 [PET_MODE_DEFENSIVE] = { 'pet_defensive', SLASH_PET_DEFENSIVE1},
Nenue@22 29 [PET_MODE_PASSIVE] = { 'pet_passive', SLASH_PET_PASSIVE1},
Nenue@22 30 [PET_MODE_ASSIST] = {'pet_assist', SLASH_PET_ASSIST1},
Nenue@16 31 }
Nenue@21 32 local SECONDARY_PROFESSIONS = {
Nenue@21 33 [5] = 3,
Nenue@21 34 [7] = 4,
Nenue@21 35 [9] = 5,
Nenue@21 36 [10] = 6
Nenue@21 37 }
Nenue@21 38 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
Nenue@16 39
Nenue@19 40 kb.ActionTypes = {}
Nenue@21 41 kb.PetCache = {
Nenue@21 42 spell = {},
Nenue@21 43 spellslot = {},
Nenue@21 44 action = {},
Nenue@21 45 special = {},
Nenue@21 46 subtext = {}
Nenue@21 47 }
Nenue@19 48 kb.TalentCache = {}
Nenue@19 49 kb.ProfessionCache = {}
Nenue@19 50
Nenue@19 51 local atype = kb.ActionTypes
Nenue@19 52
Nenue@17 53 --- Caps Lock
Nenue@19 54 atype['mount'] = function(id, name)
Nenue@17 55 if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then
Nenue@17 56 return 'mount_random', "/script C_MountJournal.SummonByID(0)", CLICK_KEYBINDER_MACRO
Nenue@17 57 else
Nenue@17 58 return 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", CLICK_KEYBINDER_MACRO
Nenue@17 59 end
Nenue@16 60 end
Nenue@19 61
Nenue@19 62 atype['macro'] = function(id, name)
Nenue@17 63 return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), id
Nenue@17 64 end
Nenue@19 65
Nenue@19 66 atype['equipset'] = function(id, name)
Nenue@17 67 return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")"
Nenue@17 68 end
Nenue@19 69
Nenue@19 70 atype['spell'] = function(id, name)
Nenue@17 71 local attributeName = name
Nenue@17 72 if kb.ProfessionCache[id] then
Nenue@17 73 attributeName = "profession_".. kb.ProfessionCache[id].profOffset .. '_' .. kb.ProfessionCache[id].spellNum
Nenue@17 74 end
Nenue@17 75 return CLICK_KEYBINDER_KEY, attributeName, name
Nenue@17 76 end
Nenue@19 77
Nenue@19 78 atype['petaction'] = function(_, name)
Nenue@17 79 -- ID doesn't exist for basic commands, even though they can be picked up
Nenue@17 80 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name)
Nenue@17 81 if PETACTION_SCRIPT[name] then
Nenue@22 82 attributeName, attributeValue = unpack(PETACTION_SCRIPT[name])
Nenue@19 83 elseif kb.PetCache.special[name] then
Nenue@21 84 attributeName = "petaction_"..kb.PetCache.special[name][3].."_" .. tonumber(kb.PetCache.special[name][6])
Nenue@17 85 end
Nenue@17 86 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue
Nenue@16 87 end
Nenue@16 88
Nenue@19 89 atype['battlepet'] = function(id, name)
Nenue@17 90 return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name)
Nenue@17 91 end
Nenue@19 92
Nenue@19 93 atype['item'] = function(id, name)
Nenue@17 94 return CLICK_KEYBINDER_KEY, 'item_' .. tostring(name), id
Nenue@17 95 end
Nenue@16 96
Nenue@16 97
Nenue@17 98 --- Resolves the SecureActionButton attribute names used for the given action
Nenue@16 99 kb.RegisterAction = function(actionType, id, name)
Nenue@16 100
Nenue@19 101 assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`')
Nenue@19 102 local target, attributeName, attributeValue = atype[actionType](id, name)
Nenue@17 103
Nenue@17 104 local command = target .. attributeName
Nenue@17 105 local baseName, iterative = attributeName, 1
Nenue@17 106 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do
Nenue@17 107 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"')
Nenue@17 108 attributeName = baseName .. '_' .. iterative
Nenue@17 109 iterative = iterative + 1
Nenue@17 110 end
Nenue@21 111 if attributeName ~= baseName then
Nenue@21 112 print(' * Creating|cFF00FF00', attributeName)
Nenue@17 113 else
Nenue@21 114 print(' * Re-using|cFF00FF00', attributeName)
Nenue@17 115 end
Nenue@17 116 kb.macros[attributeName] = {attributeValue, command}
Nenue@17 117
Nenue@17 118
Nenue@17 119 print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName)
Nenue@17 120 return attributeName, attributeValue, command
Nenue@17 121 end
Nenue@17 122
Nenue@17 123
Nenue@17 124
Nenue@17 125
Nenue@17 126 kb.ApplyTalentBinding = function(talentInfo, cache)
Nenue@17 127 for i = 5, #talentInfo do
Nenue@17 128 local command = CLICK_KEYBINDER_KEY.. talentInfo[2]
Nenue@17 129 SetBinding(talentInfo[i], command)
Nenue@17 130 cprint(' **', talentInfo[i], '->', command)
Nenue@17 131 tinsert(cache, talentInfo[i])
Nenue@17 132 end
Nenue@17 133 end
Nenue@17 134 kb.CacheTalentBinding = function(talentInfo, cache)
Nenue@17 135
Nenue@17 136 local spellID = talentInfo[4]
Nenue@19 137 cache[spellID] = cache[spellID] or {}
Nenue@19 138 cache[spellID] = {select(5,unpack(talentInfo)) }
Nenue@19 139 --cprint(spellID, unpack(kb.TalentBindings[spellID]))
Nenue@17 140 end
Nenue@17 141
Nenue@17 142 do
Nenue@17 143 local bindings = kb.bindings
Nenue@17 144 local key, macro = KeyBinderKey, KeyBinderMacro
Nenue@17 145 kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText )
Nenue@17 146
Nenue@17 147 if actionType == 'spell' then
Nenue@17 148 key:SetAttribute("*type-"..name, actionType)
Nenue@17 149 key:SetAttribute("*"..actionType.."-"..name, name)
Nenue@17 150 elseif actionType == 'item' then
Nenue@17 151 key:SetAttribute("*type-"..name, actionType)
Nenue@17 152 key:SetAttribute("*"..actionType.."-"..name, name)
Nenue@17 153 elseif actionType == 'macro' then
Nenue@17 154 macro:SetAttribute("*macro-"..macroName, actionID)
Nenue@16 155 else
Nenue@17 156 macro:SetAttribute("*macrotext-"..macroName, macroText)
Nenue@16 157 end
Nenue@16 158
Nenue@17 159 cprint('Loading binding', actionType, actionID)
Nenue@17 160 bindings[actionType] = bindings[actionType] or {}
Nenue@17 161 bindings[actionType][actionID] = bindings[actionType][actionID] or {}
Nenue@17 162 bindings[command] = bindings[actionType][actionID]
Nenue@17 163 return bindings[actionType], actionID
Nenue@16 164 end
Nenue@16 165
Nenue@17 166 kb.ApplyBindings = function (profile)
Nenue@17 167 cprint('binding profile', profile)
Nenue@17 168 for slot, data in pairs(profile.buttons) do
Nenue@17 169 kb.LoadBinding(unpack(data))
Nenue@17 170 end
Nenue@17 171
Nenue@17 172 for key, command in pairs(profile.bindings) do
Nenue@17 173
Nenue@17 174 cprint(' *', key, '->', command)
Nenue@17 175
Nenue@17 176 --_G.print('HotKey','loading', key, command)
Nenue@17 177 SetBinding(key, command)
Nenue@17 178 if bindings[command] and not tContains(bindings[command], key) then
Nenue@17 179 tinsert(bindings[command], key)
Nenue@17 180 end
Nenue@17 181 end
Nenue@17 182
Nenue@17 183 for spellName, talentInfo in pairs(profile.talents) do
Nenue@17 184 local dummy = GetSpellInfo(spellName)
Nenue@17 185 local func = kb.CacheTalentBinding
Nenue@19 186 local dest = kb.TalentBindings
Nenue@17 187 if dummy then
Nenue@17 188 cprint('|cFFBBFF00Active:|r', dummy)
Nenue@17 189 local macroName, spellName, actionType, actionID = unpack(talentInfo)
Nenue@17 190 bindings[actionType] = bindings[actionType] or {}
Nenue@17 191 bindings[actionType][actionID] = {}
Nenue@17 192 func = kb.ApplyTalentBinding
Nenue@17 193 dest = kb.bindings[actionType][actionID]
Nenue@17 194 else
Nenue@17 195
Nenue@17 196 cprint('|cFFFF4400Inactive:|r', talentInfo[2])
Nenue@17 197 end
Nenue@17 198 func(talentInfo, dest)
Nenue@17 199 end
Nenue@17 200
Nenue@17 201 end
Nenue@17 202
Nenue@17 203 kb.ApplyAllBindings =function ()
Nenue@21 204 wipe(kb.TalentBindings)
Nenue@17 205
Nenue@17 206
Nenue@17 207 -- reflect action key settings
Nenue@17 208 if GetCVarBool("ActionButtonUseKeyDown") then
Nenue@17 209 KeyBinderMacro:RegisterForClicks("AnyDown")
Nenue@17 210 KeyBinderKey:RegisterForClicks("AnyDown")
Nenue@17 211 else
Nenue@17 212 KeyBinderMacro:RegisterForClicks("AnyUp")
Nenue@17 213 KeyBinderKey:RegisterForClicks("AnyUp")
Nenue@17 214 end
Nenue@17 215
Nenue@17 216 for i, profile in ipairs(kb.orderedProfiles) do
Nenue@17 217 kb.ApplyBindings(profile)
Nenue@17 218 end
Nenue@17 219 -- do this after to ensure that profession binds are properly overridden
Nenue@17 220 kb.UpdateProfessionInfo()
Nenue@17 221
Nenue@17 222
Nenue@17 223 SaveBindings(GetCurrentBindingSet())
Nenue@17 224 end
Nenue@19 225 end
Nenue@19 226
Nenue@19 227
Nenue@19 228 kb.specInfo = {}
Nenue@19 229 kb.UpdateSpecInfo = function()
Nenue@19 230 kb.specInfo.id = GetSpecialization()
Nenue@19 231 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
Nenue@19 232 end
Nenue@19 233
Nenue@19 234 kb.UpdateTalentInfo = function()
Nenue@19 235 if kb.talentsPushed then
Nenue@19 236 return
Nenue@19 237 end
Nenue@21 238 wipe(kb.TalentCache)
Nenue@19 239 for row =1, MAX_TALENT_TIERS do
Nenue@19 240 for col = 1, NUM_TALENT_COLUMNS do
Nenue@19 241 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
Nenue@19 242 local talentInfo = kb.TalentCache[spellID] or {}
Nenue@19 243 talentInfo.row = 1
Nenue@19 244 talentInfo.col = col
Nenue@19 245 talentInfo.name = talentName
Nenue@19 246 talentInfo.talentID = talentID
Nenue@19 247 talentInfo.selected = selected
Nenue@19 248 talentInfo.available = available
Nenue@19 249 talentInfo.spellID = spellID
Nenue@19 250 kb.TalentCache[spellID] = talentInfo
Nenue@19 251 kb.TalentCache[talentName] = talentInfo
Nenue@19 252 print('Talent ', row, col, spellID, talentName)
Nenue@19 253 end
Nenue@19 254 end
Nenue@19 255 kb.talentsPushed = true
Nenue@19 256
Nenue@19 257 kb.UpdateDynamicButtons('talent')
Nenue@19 258 end
Nenue@19 259
Nenue@19 260 kb.UpdateProfessionInfo = function()
Nenue@21 261 wipe(kb.ProfessionCache)
Nenue@19 262 local profs = {GetProfessions() }
Nenue@19 263 local primaryNum = 0
Nenue@19 264 for i, index in ipairs(profs) do
Nenue@19 265 local profName, texture, rank, maxRank, numSpells, spellOffset = GetProfessionInfo(index)
Nenue@19 266 print(i, index, profName, numSpells, spellOffset)
Nenue@19 267 if not SECONDARY_PROFESSIONS[index] then
Nenue@19 268 primaryNum = primaryNum + 1
Nenue@19 269 end
Nenue@19 270 local profNum = SECONDARY_PROFESSIONS[index] or primaryNum
Nenue@19 271
Nenue@19 272
Nenue@19 273 kb.ProfessionCache[profNum] = kb.ProfessionCache[i] or {}
Nenue@19 274
Nenue@19 275 for j = 1, numSpells do
Nenue@19 276 local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION)
Nenue@19 277
Nenue@19 278 local profInfo = {
Nenue@19 279 spellName = spellName,
Nenue@19 280 spellID = spellID,
Nenue@19 281 icon = icon,
Nenue@19 282 profOffset = i,
Nenue@19 283 profIndex = index,
Nenue@19 284 spellOffset = (spellOffset+j),
Nenue@19 285 spellNum = j
Nenue@19 286 }
Nenue@19 287 KeyBinderKey:SetAttribute("*type-profession_"..i .. '_' ..j, "spell")
Nenue@19 288 KeyBinderKey:SetAttribute("*spell-profession_"..i .. '_' ..j, spellName)
Nenue@19 289
Nenue@19 290 kb.ProfessionCache[i .. '_' .. j] = profInfo
Nenue@19 291 kb.ProfessionCache[spellName] = profInfo
Nenue@19 292 kb.ProfessionCache[spellID] = profInfo
Nenue@19 293 print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
Nenue@19 294 end
Nenue@19 295
Nenue@19 296 end
Nenue@19 297
Nenue@19 298 kb.UpdateDynamicButtons('profession')
Nenue@19 299 end
Nenue@19 300
Nenue@19 301
Nenue@19 302
Nenue@19 303 kb.UpdatePetInfo = function()
Nenue@19 304 local hasPetSpells, petType = HasPetSpells()
Nenue@19 305 if PetHasSpellbook() then
Nenue@19 306 print('PET SPELLBOOK')
Nenue@19 307 local i = 1
Nenue@21 308 local specialNum = {}
Nenue@19 309 repeat
Nenue@19 310
Nenue@19 311 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
Nenue@19 312 local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
Nenue@21 313 local texture = GetSpellBookItemTexture(i, BOOKTYPE_PET)
Nenue@19 314 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
Nenue@19 315 if not isPassive then
Nenue@19 316 if spellName then
Nenue@21 317 kb.PetCache.spellslot[spellName] = {i, spellName, subText, spellID, texture}
Nenue@19 318 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
Nenue@19 319
Nenue@21 320 if subText then
Nenue@21 321 kb.PetCache.subtext[subText] = kb.PetCache.subtext[subText] or {}
Nenue@21 322 specialNum[subText] = (specialNum[subText] or 0) + 1
Nenue@21 323
Nenue@21 324 local entry = {i, spellName, subText, spellID, texture, specialNum[subText]}
Nenue@21 325
Nenue@21 326 kb.PetCache.special[spellName] = entry
Nenue@21 327 kb.PetCache.subtext[subText][specialNum[subText]] = entry
Nenue@21 328 KeyBinderMacro:SetAttribute("*macrotext-petaction_"..subText.."_"..specialNum[subText], "/cast "..spellName)
Nenue@21 329
Nenue@21 330 print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID, texture, specialNum[subText])
Nenue@19 331 end
Nenue@19 332
Nenue@19 333 if spellID then
Nenue@19 334 kb.PetCache.spell[i] = {spellID, spellName, subText}
Nenue@19 335 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
Nenue@19 336 end
Nenue@19 337 end
Nenue@19 338
Nenue@19 339
Nenue@19 340 end
Nenue@19 341
Nenue@19 342 i = i + 1
Nenue@19 343 until spellType == nil
Nenue@19 344 else
Nenue@19 345 print('NO PET SPELLBOOK')
Nenue@21 346 wipe(kb.PetCache.spell)
Nenue@21 347 wipe(kb.PetCache.spellslot)
Nenue@19 348 end
Nenue@19 349
Nenue@19 350 if PetHasActionBar() then
Nenue@19 351 print('PET ACTION BAR')
Nenue@19 352 for i = 1, 10 do
Nenue@19 353
Nenue@19 354
Nenue@19 355 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
Nenue@19 356 if name then
Nenue@19 357 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
Nenue@19 358
Nenue@19 359
Nenue@19 360 end
Nenue@19 361 print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
Nenue@19 362 end
Nenue@19 363 else
Nenue@19 364 print('NO PET ACTION BAR')
Nenue@21 365 wipe(kb.PetCache.action)
Nenue@19 366 end
Nenue@19 367
Nenue@19 368 kb.UpdateDynamicButtons('petaction')
Nenue@19 369
Nenue@19 370 end
Nenue@19 371
Nenue@19 372 kb.UpdateSystemBinds = function()
Nenue@21 373 wipe(kb.SystemBindings)
Nenue@19 374 local n = GetNumBindings()
Nenue@19 375 for i=1, n do
Nenue@19 376 local command, key1, key2 = GetBinding(i)
Nenue@19 377 if key1 then
Nenue@19 378 kb.SystemBindings[key1] = command
Nenue@19 379 end
Nenue@19 380 if key2 then
Nenue@19 381 kb.SystemBindings[key2] = command
Nenue@19 382 end
Nenue@19 383 end
Nenue@19 384 end
Nenue@19 385
Nenue@19 386 kb.UpdateDynamicButtons = function(dynamicType)
Nenue@19 387 for i, button in ipairs(kb.buttons) do
Nenue@19 388 if button.isDynamic == dynamicType then
Nenue@19 389 kb.UpdateSlot(button, true)
Nenue@19 390 end
Nenue@19 391 end
Nenue@16 392 end