comparison ActionTemplates.lua @ 74:9824d524a661

- binding slot mixin: - store key binding definitions under their slot's data table - apply action button attributes when a slot is assigned - obtain correct macro body text when a macro is slotted - fix algorithm for resolving renamed macro indices - move spell detail lookup code out of mixin script - event chains: - initialize addon from PLAYER_LOGIN - reload keybinds from PLAYER_SPECIALIZATION_CHANGED, after spec profile is resolved - refresh interface content from SPELLS_CHANGED - hotkey text: - restore communication and detection of key binding updates and reflect them accordingly - properly respond to dynamic bindings that result from talent updates
author Nenue
date Sat, 14 Jan 2017 02:29:33 -0500
parents 68365bda5ab5
children e75a2fd448c0
comparison
equal deleted inserted replaced
73:68365bda5ab5 74:9824d524a661
104 104
105 105
106 --- Resolves the SecureActionButton attribute names used for the given action 106 --- Resolves the SecureActionButton attribute names used for the given action
107 kb.RegisterAction = function(actionType, id, name) 107 kb.RegisterAction = function(actionType, id, name)
108 assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`') 108 assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`')
109 local target, attributeName, attributeValue, button = atype[actionType](id, name) 109 local prefix, attributeName, attributeValue, button = atype[actionType](id, name)
110 local command = target .. attributeName 110 local command = prefix .. attributeName
111 111 return attributeName, attributeValue, command, prefix, button
112 return attributeName, attributeValue, command, target, button 112 end
113 end 113
114 114
115 115 local spells = {}
116 local SkeletonKey_GetGenericSpell = function(spellName, spellID, icon)
117 if not spells[spellID] then
118 spells[spellID] = {}
119 spells[spellID].actionType = 'spell'
120 spells[spellID].actionID = spellID
121 spells[spellID].actionName = spellName
122 spells[spellID].iconPath = icon
123 spells[spellID].statusText = '|cFFBBBBBBSpell|r'
124 spells[spellID].dynamicType = nil
125 end
126 return spells[spellID]
127 end
128
129 -- tries to resolve spells from talent overrides/profession book/etc
130 local dynamicTypes = {['profession'] = 'ProfessionCache', ['talent'] = 'TalentCache', ['petaction'] = 'PetInfoCache'}
131 kb.ResolveSpellSlot = function(self)
132 local spellName, spellID, command, icon = self.actionName, self.actionID, self.command, self.iconPath
133 --print(' In:', spellName, spellID, command)
134 --print(GetSpellInfo(spellName or spellID))
135 local internalName, _, internalIcon, _, _, _, _ = GetSpellInfo(spellName or spellID)
136 local isAvailable = internalName and true
137
138 if internalName and (internalName ~= spellName) then
139 -- it's a binding for the originating spell, leave it as is
140 print(' |cFFFF4400spell is an override(', internalName, '~=', spellName,') leave the name info alone')
141 self.statusText = '|cFFFFFF00Spell|r'
142 self.isAvailable = true
143 return
144 end
145
146 -- let's us match spells replaced by talents
147 local info = kb.DynamicSpells[internalName or spellName]
148 if not info then
149 local dynamicType, dynamicIndex, dynamicSubIndex = command:match("(%a+)_(%S+)_(%S+)")
150 if kb.DynamicSpells[dynamicType] then
151 print('|cFFFF4400resolving dynamic type index:', internalName, spellName, command)
152 dynamicIndex = tonumber(dynamicIndex)
153 dynamicSubIndex = tonumber(dynamicSubIndex)
154 local cache = kb.DynamicSpells[dynamicType]
155 print('type:', dynamicType)
156 if dynamicIndex and cache[dynamicIndex] then
157 info = kb.DynamicSpells[dynamicType][dynamicIndex]
158 print('index:', dynamicIndex)
159 if dynamicSubIndex and info[dynamicSubIndex] then
160 info = info[dynamicSubIndex]
161 print('sub-index:', dynamicSubIndex)
162 end
163 isAvailable = true
164 end
165 end
166 if not info then
167 info = SkeletonKey_GetGenericSpell(spellName, spellID, internalIcon or icon)
168 end
169 end
170 info.isAvailable = isAvailable
171
172 print('|cFF00FF88Slot Details:|r', info.actionName, info.actionID, info.dynamicType, info.isAvailable)
173 for k,v in pairs(info) do
174 --cprint(' ',k,v)
175 self[k] = v
176 end
177
178 return info
179 end
116 180
117 181
118 kb.ApplyTalentBinding = function(talentInfo, cache) 182 kb.ApplyTalentBinding = function(talentInfo, cache)
119 talentInfo.assignedKeys = talentInfo.assignedKeys or {} 183 talentInfo.assignedKeys = talentInfo.assignedKeys or {}
120 for i , key in pairs(talentInfo.assignedKeys) do 184 for i , key in pairs(talentInfo.assignedKeys) do
310 configTable.assignedKeys = talent.assignedKeys 374 configTable.assignedKeys = talent.assignedKeys
311 end 375 end
312 if not configTable.assignedKeys then 376 if not configTable.assignedKeys then
313 configTable.assignedKeys = {GetBindingKey(configTable.command) } 377 configTable.assignedKeys = {GetBindingKey(configTable.command) }
314 end 378 end
315 if configTable.dynamicType then 379 if configTable.dynamicType == 'talent' then
316 kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName) 380 --kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName)
317 end 381 end
382 for _, key in pairs(configTable.assignedKeys) do
383
384 SetBinding(key, configTable.command)
385 end
386
318 end 387 end
319 end 388 end
320 end 389 end
321 390
322 kb.ApplyAllBindings =function () 391 kb.ApplyAllBindings =function ()
323 cprint('|cFF0088FFApplyAllBindings()') 392 print('|cFFFFFF00ApplyAllBindings()')
324 wipe(kb.TalentBindings) 393 wipe(kb.TalentBindings)
325 wipe(kb.bindings) 394 wipe(kb.bindings)
326 --kb:print('Loading binding profile', kb.profileName) 395 --kb:print('Loading binding profile', kb.profileName)
327 396
328 -- reflect action key settings 397 -- reflect action key settings
364 kb.UpdateTalentInfo = function() 433 kb.UpdateTalentInfo = function()
365 print('|cFFFFFF00kb.UpdateTalentInfo()|r') 434 print('|cFFFFFF00kb.UpdateTalentInfo()|r')
366 if kb.talentsPushed then 435 if kb.talentsPushed then
367 return 436 return
368 end 437 end
369 wipe(kb.TalentCache)
370 for row =1, MAX_TALENT_TIERS do 438 for row =1, MAX_TALENT_TIERS do
371 for col = 1, NUM_TALENT_COLUMNS do 439 for col = 1, NUM_TALENT_COLUMNS do
372 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1) 440 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
373 local talentInfo = kb.TalentCache[spellID] or {} 441 local talentInfo = kb.TalentCache[spellID] or {}
374 if spellID then 442 if spellID then
404 end 472 end
405 end 473 end
406 end 474 end
407 475
408 kb.talentsPushed = true 476 kb.talentsPushed = true
409
410 kb.UpdateDynamicButtons('talent') 477 kb.UpdateDynamicButtons('talent')
411 end 478 end
412 479
413 kb.UpdateProfessionInfo = function() 480 kb.UpdateProfessionInfo = function()
414 wipe(kb.ProfessionCache) 481 wipe(kb.ProfessionCache)
636 kb.SecureAttribute = function(target, name, value) 703 kb.SecureAttribute = function(target, name, value)
637 if InCombatLockdown() then 704 if InCombatLockdown() then
638 if #kb.pendingAttributes == 0 then 705 if #kb.pendingAttributes == 0 then
639 kb:print(kb.L('Key bindings will be applied when you exit combat.')) 706 kb:print(kb.L('Key bindings will be applied when you exit combat.'))
640 end 707 end
641
642 tinsert(kb.pendingAttributes, {target, name, value}) 708 tinsert(kb.pendingAttributes, {target, name, value})
643 SkeletonKey:RegisterEvent('PLAYER_REGEN_ENABLED') 709 SkeletonKey:RegisterEvent('PLAYER_REGEN_ENABLED')
644
645 else 710 else
646
647 --cprint('|cFFFF4444' .. target:GetName()..'|r.|cFFFFFF00'.. tostring(name)..'|r = "'..tostring(value)..'"') 711 --cprint('|cFFFF4444' .. target:GetName()..'|r.|cFFFFFF00'.. tostring(name)..'|r = "'..tostring(value)..'"')
648 target:SetAttribute(name, value) 712 target:SetAttribute(name, value)
649 end 713 end
650 end 714 end
651 715