comparison SkeletonKey/ActionTemplates.lua @ 62:04c23ceaf9e0

- fix taint caused by loading in combat
author Nenue
date Mon, 05 Sep 2016 14:56:38 -0400
parents 9eebce04e69b
children 2409fe9b81e1
comparison
equal deleted inserted replaced
61:b7be92f62b05 62:04c23ceaf9e0
108 local target, attributeName, attributeValue = atype[actionType](id, name) 108 local target, attributeName, attributeValue = atype[actionType](id, name)
109 109
110 local command = target .. attributeName 110 local command = target .. attributeName
111 local baseName, iterative = attributeName, 1 111 local baseName, iterative = attributeName, 1
112 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do 112 while (kb.macros[attributeName] and kb.macros[attributeName][1] ~= attributeValue) do
113 print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"') 113 --print(' * cannot use|cFF00FF00', attributeName, '|r"'.. tostring(kb.macros[attributeName][1]) .. '"')
114 attributeName = baseName .. '_' .. iterative 114 attributeName = baseName .. '_' .. iterative
115 iterative = iterative + 1 115 iterative = iterative + 1
116 end 116 end
117 if attributeName ~= baseName then 117 if attributeName ~= baseName then
118 print(' * Creating|cFF00FF00', attributeName) 118 --print(' * Creating|cFF00FF00', attributeName)
119 else 119 else
120 print(' * Re-using|cFF00FF00', attributeName) 120 --print(' * Re-using|cFF00FF00', attributeName)
121 end 121 end
122 kb.macros[attributeName] = {attributeValue, command} 122 kb.macros[attributeName] = {attributeValue, command}
123 123
124 124
125 print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName) 125 --print('RegisterAction', actionType, id, '->', attributeName, attributeValue, target .. attributeName)
126 return attributeName, attributeValue, command 126 return attributeName, attributeValue, command
127 end 127 end
128 128
129 129
130 130
131 131
132 kb.ApplyTalentBinding = function(talentInfo, cache) 132 kb.ApplyTalentBinding = function(talentInfo, cache)
133 for i = 5, #talentInfo do 133 for i = 5, #talentInfo do
134 local command = CLICK_KEYBINDER_KEY.. talentInfo[2] 134 local command = CLICK_KEYBINDER_KEY.. talentInfo[2]
135 SetBinding(talentInfo[i], command) 135 SetBinding(talentInfo[i], command)
136 cprint(' **', talentInfo[i], '->', command) 136 --cprint(' **', talentInfo[i], '->', command)
137 tinsert(cache, talentInfo[i]) 137 tinsert(cache, talentInfo[i])
138 end 138 end
139 end 139 end
140 kb.CacheTalentBinding = function(talentInfo, cache) 140 kb.CacheTalentBinding = function(talentInfo, cache)
141 141
149 do 149 do
150 local bindings = kb.bindings 150 local bindings = kb.bindings
151 local key, macro = KeyBinderKey, KeyBinderMacro 151 local key, macro = KeyBinderKey, KeyBinderMacro
152 kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText ) 152 kb.LoadBinding = function(command, name, icon, actionType, actionID, macroName, macroText )
153 153
154 local buttonTypeKey, buttonTypeValue = "*type-"..name, actionType
155 local buttonActionKey, buttonActionValue = "*"..actionType.."-"..name, actionID
156 local button = key
154 if actionType == 'spell' then 157 if actionType == 'spell' then
155 key:SetAttribute("*type-"..name, actionType) 158 buttonTypeKey = "*type-"..name
156 key:SetAttribute("*"..actionType.."-"..name, name) 159 buttonTypeValue = actionType
160 buttonActionKey = "*"..actionType.."-"..name
161 buttonActionValue = name
157 elseif actionType == 'item' then 162 elseif actionType == 'item' then
158 key:SetAttribute("*type-"..name, actionType) 163 buttonTypeKey = "*type-"..name
159 key:SetAttribute("*"..actionType.."-"..name, name) 164 buttonTypeValue = actionType
165 buttonActionKey = "*"..actionType.."-"..name
166 buttonActionValue = actionID
160 elseif actionType == 'macro' then 167 elseif actionType == 'macro' then
161 macro:SetAttribute("*macro-"..macroName, actionID) 168 button = macro
169 buttonTypeKey = "*macro-"..macroName
170 buttonTypeValue = actionID
171 buttonActionKey = nil
162 else 172 else
163 macro:SetAttribute("*macrotext-"..macroName, macroText) 173 button = macro
164 end 174 buttonTypeKey = "*macrotext-"..macroName
175 buttonTypeValue = macroText
176 buttonActionKey = nil
177 end
178
179 --cprint(actionType, actionID, name)
180 --cprint(button:GetName(), buttonTypeKey,'=', buttonTypeValue)
181 kb.SecureAttribute(button, buttonTypeKey, buttonTypeValue)
182 if buttonActionKey then
183 --cprint(button:GetName(), buttonActionKey,'=', buttonActionValue)
184 kb.SecureAttribute(button, buttonActionKey, buttonActionValue)
185 end
186
165 local indexKey = actionType..'_'..actionID 187 local indexKey = actionType..'_'..actionID
166 cprint('Loading binding', indexKey)
167 bindings[indexKey] = bindings[indexKey] or {} 188 bindings[indexKey] = bindings[indexKey] or {}
168 bindings[command] = bindings[indexKey] 189 bindings[command] = bindings[indexKey]
169 return bindings[indexKey], actionID 190 return bindings[indexKey], actionID
170 end 191 end
171 192
172 kb.ApplyBindings = function (profile) 193 kb.ApplyBindings = function (profile)
173 cprint('binding profile', profile) 194 --cprint('binding profile', profile)
174 for slot, data in pairs(profile.buttons) do 195 for slot, data in pairs(profile.buttons) do
175 kb.LoadBinding(unpack(data)) 196 kb.LoadBinding(unpack(data))
176 end 197 end
177 198
178 for key, command in pairs(profile.bindings) do 199 for key, command in pairs(profile.bindings) do
179 200
180 cprint(' *', key, '->', command) 201 --cprint(' *', key, '->', command)
181 202
182 --_G.print('HotKey','loading', key, command) 203 --_G.print('HotKey','loading', key, command)
183 SetBinding(key, command) 204 SetBinding(key, command)
184 if bindings[command] and not tContains(bindings[command], key) then 205 if bindings[command] and not tContains(bindings[command], key) then
185 tinsert(bindings[command], key) 206 tinsert(bindings[command], key)
189 for spellName, talentInfo in pairs(profile.talents) do 210 for spellName, talentInfo in pairs(profile.talents) do
190 local dummy = GetSpellInfo(spellName) 211 local dummy = GetSpellInfo(spellName)
191 local func = kb.CacheTalentBinding 212 local func = kb.CacheTalentBinding
192 local dest = kb.TalentBindings 213 local dest = kb.TalentBindings
193 if dummy then 214 if dummy then
194 cprint('|cFFBBFF00Active:|r', dummy) 215 --cprint('|cFFBBFF00Active:|r', dummy)
195 local macroName, spellName, actionType, actionID = unpack(talentInfo) 216 local macroName, spellName, actionType, actionID = unpack(talentInfo)
196 local indexKey = actionType .. '_' .. actionID 217 local indexKey = actionType .. '_' .. actionID
197 bindings[indexKey] = {} 218 bindings[indexKey] = {}
198 func = kb.ApplyTalentBinding 219 func = kb.ApplyTalentBinding
199 dest = kb.bindings[indexKey] 220 dest = kb.bindings[indexKey]
200 else 221 else
201 222
202 cprint('|cFFFF4400Inactive:|r', talentInfo[2]) 223 --cprint('|cFFFF4400Inactive:|r', talentInfo[2])
203 end 224 end
204 func(talentInfo, dest) 225 func(talentInfo, dest)
205 end 226 end
206 227
207 end 228 end
208 229
209 kb.ApplyAllBindings =function () 230 kb.ApplyAllBindings =function ()
210 wipe(kb.TalentBindings) 231 wipe(kb.TalentBindings)
211 232 wipe(kb.bindings)
233 kb:print('Loading binding profile', kb.profileName)
212 234
213 -- reflect action key settings 235 -- reflect action key settings
214 if GetCVarBool("ActionButtonUseKeyDown") then 236 if GetCVarBool("ActionButtonUseKeyDown") then
215 KeyBinderMacro:RegisterForClicks("AnyDown") 237 KeyBinderMacro:RegisterForClicks("AnyDown")
216 KeyBinderKey:RegisterForClicks("AnyDown") 238 KeyBinderKey:RegisterForClicks("AnyDown")
253 talentInfo.selected = selected 275 talentInfo.selected = selected
254 talentInfo.available = available 276 talentInfo.available = available
255 talentInfo.spellID = spellID 277 talentInfo.spellID = spellID
256 kb.TalentCache[spellID] = talentInfo 278 kb.TalentCache[spellID] = talentInfo
257 kb.TalentCache[talentName] = talentInfo 279 kb.TalentCache[talentName] = talentInfo
258 print('Talent ', row, col, spellID, talentName) 280 --print('Talent ', row, col, spellID, talentName)
259 end 281 end
260 end 282 end
261 kb.talentsPushed = true 283 kb.talentsPushed = true
262 284
263 kb.UpdateDynamicButtons('talent') 285 kb.UpdateDynamicButtons('talent')
264 end 286 end
265 287
266 kb.UpdateProfessionInfo = function() 288 kb.UpdateProfessionInfo = function()
267 wipe(kb.ProfessionCache) 289 wipe(kb.ProfessionCache)
268 local profs = {GetProfessions() } 290 local profs = {GetProfessions() }
269 print(GetProfessions()) 291 --print(GetProfessions())
270 local primaryNum = 0 292 local primaryNum = 0
271 for i = 1, 6 do 293 for i = 1, 6 do
272 if profs[i] then 294 if profs[i] then
273 local index = profs[i] 295 local index = profs[i]
274 local profName, texture, _, _, numSpells, spellOffset = GetProfessionInfo(index) 296 local profName, texture, _, _, numSpells, spellOffset = GetProfessionInfo(index)
275 print(i, index, profName, numSpells, spellOffset) 297 --print(i, index, profName, numSpells, spellOffset)
276 if not SECONDARY_PROFESSIONS[index] then 298 if not SECONDARY_PROFESSIONS[index] then
277 primaryNum = primaryNum + 1 299 primaryNum = primaryNum + 1
278 end 300 end
279 local profNum = SECONDARY_PROFESSIONS[index] or primaryNum 301 local profNum = SECONDARY_PROFESSIONS[index] or primaryNum
280 print(i, profNum) 302 --print(i, profNum)
281 303
282 304
283 kb.ProfessionCache[profNum] = kb.ProfessionCache[profNum] or {} 305 kb.ProfessionCache[profNum] = kb.ProfessionCache[profNum] or {}
284 306
285 for j = 1, numSpells do 307 for j = 1, numSpells do
299 kb.SecureAttribute(KeyBinderKey, "*spell-profession_"..i .. '_' ..j, spellName) 321 kb.SecureAttribute(KeyBinderKey, "*spell-profession_"..i .. '_' ..j, spellName)
300 322
301 kb.ProfessionCache[i .. '_' .. j] = profInfo 323 kb.ProfessionCache[i .. '_' .. j] = profInfo
302 kb.ProfessionCache[spellName] = profInfo 324 kb.ProfessionCache[spellName] = profInfo
303 kb.ProfessionCache[spellID] = profInfo 325 kb.ProfessionCache[spellID] = profInfo
304 print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j) 326 --print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
305 end 327 end
306 end 328 end
307 329
308 end 330 end
309 331
342 petSpellCache = {} 364 petSpellCache = {}
343 petSubtextCache = {} 365 petSubtextCache = {}
344 end 366 end
345 367
346 if PetHasSpellbook() then 368 if PetHasSpellbook() then
347 print('PET SPELLBOOK') 369 --print('PET SPELLBOOK')
348 local i = 1 370 local i = 1
349 local specialNum = {} 371 local specialNum = {}
350 repeat 372 repeat
351 373
352 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET) 374 local spellType, spellID = GetSpellBookItemInfo(i, BOOKTYPE_PET)
354 local texture = GetSpellBookItemTexture(i, BOOKTYPE_PET) 376 local texture = GetSpellBookItemTexture(i, BOOKTYPE_PET)
355 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET) 377 local isPassive = IsPassiveSpell(i, BOOKTYPE_PET)
356 if not isPassive then 378 if not isPassive then
357 if spellName then 379 if spellName then
358 kb.PetCache.spellslot[spellName] = {i, spellName, subText, spellID, texture} 380 kb.PetCache.spellslot[spellName] = {i, spellName, subText, spellID, texture}
359 print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText) 381 --print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
360 382
361 if subText then 383 if subText then
362 -- make sure that pet specialization subtext maps correctly 384 -- make sure that pet specialization subtext maps correctly
363 --if match(subText, kb.PetCache.specName) then 385 --if match(subText, kb.PetCache.specName) then
364 -- subText = 'specialization' 386 -- subText = 'specialization'
376 local macrotext = "" 398 local macrotext = ""
377 for spellName, enabled in pairs(petSubtextCache[subText]) do 399 for spellName, enabled in pairs(petSubtextCache[subText]) do
378 macrotext = macrotext .. "/cast " .. spellName .. "\n" 400 macrotext = macrotext .. "/cast " .. spellName .. "\n"
379 end 401 end
380 kb.SecureAttribute(KeyBinderMacro, "*macrotext-petaction_"..subText.."_"..specialNum[subText], macrotext) 402 kb.SecureAttribute(KeyBinderMacro, "*macrotext-petaction_"..subText.."_"..specialNum[subText], macrotext)
381 print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID, texture, specialNum[subText]) 403 --print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID, texture, specialNum[subText])
382 end 404 end
383 405
384 406
385 407
386 local entry = {i, spellName, subText, spellID, texture, specialNum[subText]} 408 local entry = {i, spellName, subText, spellID, texture, specialNum[subText]}
389 kb.PetCache.subtext[subText][specialNum[subText]] = entry 411 kb.PetCache.subtext[subText][specialNum[subText]] = entry
390 end 412 end
391 413
392 if spellID then 414 if spellID then
393 kb.PetCache.spell[i] = {spellID, spellName, subText} 415 kb.PetCache.spell[i] = {spellID, spellName, subText}
394 print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText) 416 --print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
395 end 417 end
396 end 418 end
397 419
398 420
399 end 421 end
400 422
401 i = i + 1 423 i = i + 1
402 until spellType == nil 424 until spellType == nil
403 else 425 else
404 print('NO PET SPELLBOOK') 426 --print('NO PET SPELLBOOK')
405 wipe(kb.PetCache.spell) 427 wipe(kb.PetCache.spell)
406 wipe(kb.PetCache.spellslot) 428 wipe(kb.PetCache.spellslot)
407 end 429 end
408 430
409 if PetHasActionBar() then 431 if PetHasActionBar() then
410 print('PET ACTION BAR') 432 --print('PET ACTION BAR')
411 for i = 1, 10 do 433 for i = 1, 10 do
412 434
413 435
414 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i) 436 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
415 if name then 437 if name then
416 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive } 438 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
417 439
418 440
419 end 441 end
420 print('|cFFFFFF00action['..i..']|r', name, subtext, texture) 442 --print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
421 end 443 end
422 else 444 else
423 print('NO PET ACTION BAR') 445 --print('NO PET ACTION BAR')
424 wipe(kb.PetCache.action) 446 wipe(kb.PetCache.action)
425 end 447 end
426 448
427 kb.UpdateDynamicButtons('petaction') 449 kb.UpdateDynamicButtons('petaction')
428 450
439 end 461 end
440 if key2 then 462 if key2 then
441 kb.SystemBindings[key2] = command 463 kb.SystemBindings[key2] = command
442 end 464 end
443 else 465 else
444 print('ignoring action button binding', command) 466 --print('ignoring action button binding', command)
445 end 467 end
446 end 468 end
447 end 469 end
448 470
449 kb.UpdateDynamicButtons = function(dynamicType) 471 kb.UpdateDynamicButtons = function(dynamicType)
464 tinsert(kb.pendingAttributes, {target, name, value}) 486 tinsert(kb.pendingAttributes, {target, name, value})
465 kb:RegisterEvent('PLAYER_REGEN_ENABLED') 487 kb:RegisterEvent('PLAYER_REGEN_ENABLED')
466 488
467 else 489 else
468 490
469 print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"') 491 --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
470 target:SetAttribute(name, value) 492 target:SetAttribute(name, value)
471 end 493 end
472 end 494 end
473 495
474 kb.PLAYER_REGEN_ENABLED = function() 496 kb.PLAYER_REGEN_ENABLED = function()
475 if #kb.pendingAttributes >= 1 then 497 if #kb.pendingAttributes >= 1 then
476 local args = tremove(kb.pendingAttributes) 498 local args = tremove(kb.pendingAttributes)
477 while args do 499 while args do
478 local target, name, value = unpack(args) 500 local target, name, value = unpack(args)
479 print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"') 501 --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
480 target:SetAttribute(name, value) 502 target:SetAttribute(name, value)
481 args = tremove(kb.pendingAttributes) 503 args = tremove(kb.pendingAttributes)
482 end 504 end
483 end 505 end
484 506
493 515
494 kb.UpdateBindingsCache = function(actionType, actionID, bindings) 516 kb.UpdateBindingsCache = function(actionType, actionID, bindings)
495 local indexKey = actionType .. '_' .. actionID 517 local indexKey = actionType .. '_' .. actionID
496 kb.bindings[indexKey] = bindings 518 kb.bindings[indexKey] = bindings
497 519
498 print('|cFF00FF00'..indexKey..'|r = {', table.concat(bindings,', '), '}') 520 --print('|cFF00FF00'..indexKey..'|r = {', table.concat(bindings,', '), '}')
499 tinsert(kb.ChangedBindings, {actionType, actionID}) 521 tinsert(kb.ChangedBindings, {actionType, actionID})
500 end 522 end