comparison SkeletonKey/ActionTypes.lua @ 21:564015ef0317

- use pet spellbook subtext to categorize dynamic buttons
author Nenue
date Sat, 30 Jul 2016 20:28:15 -0400
parents 67db6b712bf3
children f6dd297cb812
comparison
equal deleted inserted replaced
20:5250877895ae 21:564015ef0317
1 -- SkeletonKey 1 -- SkeletonKey
2 -- ActionTypes.lua 2 -- ActionTypes.lua
3 -- Created: 7/29/2016 9:14 PM 3 -- Created: 7/29/2016 9:14 PM
4 -- %file-revision% 4 -- %file-revision%
5 -- 5 --
6 local kb, print, wrap = LibStub('LibKraken').register(KeyBinder) 6 local tostring, tonumber, pairs, ipairs = tostring, tonumber, pairs, ipairs
7 local unpack, SetBinding = unpack, SetBinding
8 local tinsert, tContains, select, wipe = tinsert, tContains, select, table.wipe
9 local GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo = GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo
10 local GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell = GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell
11 local PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells = PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells
12 local GetProfessions, GetProfessionInfo, GetTalentInfo = GetProfessions, GetProfessionInfo, GetTalentInfo
13 local GetNumBindings, GetBinding = GetNumBindings, GetBinding
14
15 local kb, print, wrap = LibStub('LibKraken').register(KeyBinder, 'Info')
7 local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end 16 local cprint = DEVIAN_WORKSPACE and function(...) _G.print('Cfg', ...) end or function() end
8 17
9 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
10 local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:" 18 local CLICK_KEYBINDER_MACRO = "CLICK KeyBinderMacro:"
11 local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:" 19 local CLICK_KEYBINDER_KEY = "CLICK KeyBinderKey:"
12 20 local PET_BASIC_SUBTEXT = 'Basic Attack'
21 local PET_SPECIAL_SUBTEXT = 'Special Ability'
13 local PETACTION_SCRIPT = { 22 local PETACTION_SCRIPT = {
14 [PET_ACTION_MOVE_TO] = {SLASH_PET_MOVE_TO1, 'pet_move_to'}, 23 [PET_ACTION_MOVE_TO] = {SLASH_PET_MOVE_TO1, 'pet_move_to'},
15 [PET_ACTION_ATTACK] = {SLASH_PET_ATTACK1, 'pet_attack'}, 24 [PET_ACTION_ATTACK] = {SLASH_PET_ATTACK1, 'pet_attack'},
16 [PET_ACTION_FOLLOW] = {SLASH_PET_FOLLOW1, 'pet_follow'}, 25 [PET_ACTION_FOLLOW] = {SLASH_PET_FOLLOW1, 'pet_follow'},
17 [PET_ACTION_WAIT] = {SLASH_PET_STAY1, 'pet_stay'}, 26 [PET_ACTION_WAIT] = {SLASH_PET_STAY1, 'pet_stay'},
18 [PET_MODE_AGGRESSIVE] = {SLASH_PET_AGGRESSIVE1, 'pet_aggressive'}, 27 [PET_MODE_AGGRESSIVE] = {SLASH_PET_AGGRESSIVE1, 'pet_aggressive'},
19 [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'}, 28 [PET_MODE_DEFENSIVE] = {SLASH_PET_DEFENSIVE1, 'pet_defensive'},
20 [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'}, 29 [PET_MODE_PASSIVE] = {SLASH_PET_PASSIVE1, 'pet_passive'},
21 [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'}, 30 [PET_MODE_ASSIST] = {SLASH_PET_ASSIST1, 'pet_assist'},
22 } 31 }
32 local SECONDARY_PROFESSIONS = {
33 [5] = 3,
34 [7] = 4,
35 [9] = 5,
36 [10] = 6
37 }
38 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
23 39
24 kb.ActionTypes = {} 40 kb.ActionTypes = {}
25 kb.PetCache = {} 41 kb.PetCache = {
42 spell = {},
43 spellslot = {},
44 action = {},
45 special = {},
46 subtext = {}
47 }
26 kb.TalentCache = {} 48 kb.TalentCache = {}
27 kb.ProfessionCache = {} 49 kb.ProfessionCache = {}
28 50
29 local atype = kb.ActionTypes 51 local atype = kb.ActionTypes
30 52
57 -- ID doesn't exist for basic commands, even though they can be picked up 79 -- ID doesn't exist for basic commands, even though they can be picked up
58 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name) 80 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name)
59 if PETACTION_SCRIPT[name] then 81 if PETACTION_SCRIPT[name] then
60 attributeValue, attributeName = unpack(PETACTION_SCRIPT[name]) 82 attributeValue, attributeName = unpack(PETACTION_SCRIPT[name])
61 elseif kb.PetCache.special[name] then 83 elseif kb.PetCache.special[name] then
62 attributeName = "petaction_special" .. tonumber(kb.PetCache.special[name][2]) 84 attributeName = "petaction_"..kb.PetCache.special[name][3].."_" .. tonumber(kb.PetCache.special[name][6])
63 end 85 end
64 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue 86 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue
65 end 87 end
66 88
67 atype['battlepet'] = function(id, name) 89 atype['battlepet'] = function(id, name)
84 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do 106 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do
85 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"') 107 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"')
86 attributeName = baseName .. '_' .. iterative 108 attributeName = baseName .. '_' .. iterative
87 iterative = iterative + 1 109 iterative = iterative + 1
88 end 110 end
89 if macroName ~= baseName then 111 if attributeName ~= baseName then
90 print(' * Creating|cFF00FF00', macroName) 112 print(' * Creating|cFF00FF00', attributeName)
91 else 113 else
92 print(' * Re-using|cFF00FF00', macroName) 114 print(' * Re-using|cFF00FF00', attributeName)
93 end 115 end
94 kb.macros[attributeName] = {attributeValue, command} 116 kb.macros[attributeName] = {attributeValue, command}
95 117
96 118
97 print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName) 119 print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName)
177 end 199 end
178 200
179 end 201 end
180 202
181 kb.ApplyAllBindings =function () 203 kb.ApplyAllBindings =function ()
182 table.wipe(kb.TalentBindings) 204 wipe(kb.TalentBindings)
183 205
184 206
185 -- reflect action key settings 207 -- reflect action key settings
186 if GetCVarBool("ActionButtonUseKeyDown") then 208 if GetCVarBool("ActionButtonUseKeyDown") then
187 KeyBinderMacro:RegisterForClicks("AnyDown") 209 KeyBinderMacro:RegisterForClicks("AnyDown")
201 SaveBindings(GetCurrentBindingSet()) 223 SaveBindings(GetCurrentBindingSet())
202 end 224 end
203 end 225 end
204 226
205 227
206 local PET_SPECIAL_SUBTEXT = 'Special Ability'
207 local SECONDARY_PROFESSIONS = {
208 [5] = 3,
209 [7] = 4,
210 [9] = 5,
211 [10] = 6
212 }
213
214 kb.TalentCache = {}
215 kb.ProfessionCache = {}
216 kb.PetCache = {}
217 kb.specInfo = {} 228 kb.specInfo = {}
218 kb.UpdateSpecInfo = function() 229 kb.UpdateSpecInfo = function()
219 kb.specInfo.id = GetSpecialization() 230 kb.specInfo.id = GetSpecialization()
220 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id) 231 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
221 print('|cFF00FF00current spec:|r', kb.specInfo.id, 'of', GetNumSpecializations())
222 end 232 end
223 233
224 kb.UpdateTalentInfo = function() 234 kb.UpdateTalentInfo = function()
225 if kb.talentsPushed then 235 if kb.talentsPushed then
226 return 236 return
227 end 237 end
228 table.wipe(kb.TalentCache) 238 wipe(kb.TalentCache)
229 for row =1, MAX_TALENT_TIERS do 239 for row =1, MAX_TALENT_TIERS do
230 for col = 1, NUM_TALENT_COLUMNS do 240 for col = 1, NUM_TALENT_COLUMNS do
231 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1) 241 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
232 local talentInfo = kb.TalentCache[spellID] or {} 242 local talentInfo = kb.TalentCache[spellID] or {}
233 talentInfo.row = 1 243 talentInfo.row = 1
246 256
247 kb.UpdateDynamicButtons('talent') 257 kb.UpdateDynamicButtons('talent')
248 end 258 end
249 259
250 kb.UpdateProfessionInfo = function() 260 kb.UpdateProfessionInfo = function()
251 table.wipe(kb.ProfessionCache) 261 wipe(kb.ProfessionCache)
252 local profs = {GetProfessions() } 262 local profs = {GetProfessions() }
253 local primaryNum = 0 263 local primaryNum = 0
254 for i, index in ipairs(profs) do 264 for i, index in ipairs(profs) do
255 local profName, texture, rank, maxRank, numSpells, spellOffset = GetProfessionInfo(index) 265 local profName, texture, rank, maxRank, numSpells, spellOffset = GetProfessionInfo(index)
256 print(i, index, profName, numSpells, spellOffset) 266 print(i, index, profName, numSpells, spellOffset)
289 end 299 end
290 300
291 301
292 302
293 kb.UpdatePetInfo = function() 303 kb.UpdatePetInfo = function()
294 kb.PetCache.spell = kb.PetCache.spell or {}
295 kb.PetCache.spellslot = kb.PetCache.spellslot or {}
296 kb.PetCache.action = kb.PetCache.action or {}
297 kb.PetCache.special = kb.PetCache.action or {}
298 local hasPetSpells, petType = HasPetSpells() 304 local hasPetSpells, petType = HasPetSpells()
299 if PetHasSpellbook() then 305 if PetHasSpellbook() then
300 print('PET SPELLBOOK') 306 print('PET SPELLBOOK')
301 local i = 1 307 local i = 1
302 local specialNum = 0 308 local specialNum = {}
303 repeat 309 repeat
304 310
305 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET) 311 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
306 local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET) 312 local spellName, subText = GetSpellBookItemName(i, BOOKTYPE_PET)
313 local texture = GetSpellBookItemTexture(i, BOOKTYPE_PET)
307 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET) 314 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
308 if not isPassive then 315 if not isPassive then
309 if spellName then 316 if spellName then
310 kb.PetCache.spellslot[spellName] = {i, spellName, subText} 317 kb.PetCache.spellslot[spellName] = {i, spellName, subText, spellID, texture}
311 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText) 318 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
312 319
313 if subText == PET_SPECIAL_SUBTEXT then 320 if subText then
314 specialNum = specialNum + 1 321 kb.PetCache.subtext[subText] = kb.PetCache.subtext[subText] or {}
315 kb.PetCache.special[spellName] = {i, specialNum, spellID, subText } 322 specialNum[subText] = (specialNum[subText] or 0) + 1
316 print('|cFF00FFFFspecial['..spellName..']|r', '=>', i, specialNum, spellID, subText) 323
317 KeyBinderMacro:SetAttribute("*macrotext-pet_special_"..specialNum, "/cast "..spellName) 324 local entry = {i, spellName, subText, spellID, texture, specialNum[subText]}
325
326 kb.PetCache.special[spellName] = entry
327 kb.PetCache.subtext[subText][specialNum[subText]] = entry
328 KeyBinderMacro:SetAttribute("*macrotext-petaction_"..subText.."_"..specialNum[subText], "/cast "..spellName)
329
330 print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID, texture, specialNum[subText])
318 end 331 end
319 332
320 if spellID then 333 if spellID then
321 kb.PetCache.spell[i] = {spellID, spellName, subText} 334 kb.PetCache.spell[i] = {spellID, spellName, subText}
322 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText) 335 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
328 341
329 i = i + 1 342 i = i + 1
330 until spellType == nil 343 until spellType == nil
331 else 344 else
332 print('NO PET SPELLBOOK') 345 print('NO PET SPELLBOOK')
333 table.wipe(kb.PetCache.spell) 346 wipe(kb.PetCache.spell)
334 table.wipe(kb.PetCache.spellslot) 347 wipe(kb.PetCache.spellslot)
335 end 348 end
336 349
337 if PetHasActionBar() then 350 if PetHasActionBar() then
338 print('PET ACTION BAR') 351 print('PET ACTION BAR')
339 for i = 1, 10 do 352 for i = 1, 10 do
347 end 360 end
348 print('|cFFFFFF00action['..i..']|r', name, subtext, texture) 361 print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
349 end 362 end
350 else 363 else
351 print('NO PET ACTION BAR') 364 print('NO PET ACTION BAR')
352 table.wipe(kb.PetCache.action) 365 wipe(kb.PetCache.action)
353 end 366 end
354 367
355 kb.UpdateDynamicButtons('petaction') 368 kb.UpdateDynamicButtons('petaction')
356 369
357 end 370 end
358 371
359 kb.UpdateSystemBinds = function() 372 kb.UpdateSystemBinds = function()
360 table.wipe(kb.SystemBindings) 373 wipe(kb.SystemBindings)
361 local n = GetNumBindings() 374 local n = GetNumBindings()
362 for i=1, n do 375 for i=1, n do
363 local command, key1, key2 = GetBinding(i) 376 local command, key1, key2 = GetBinding(i)
364 if key1 then 377 if key1 then
365 kb.SystemBindings[key1] = command 378 kb.SystemBindings[key1] = command