Mercurial > wow > skeletonkey
diff 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 |
line wrap: on
line diff
--- a/ActionTemplates.lua Sat Jan 07 12:52:05 2017 -0500 +++ b/ActionTemplates.lua Sat Jan 14 02:29:33 2017 -0500 @@ -106,13 +106,77 @@ --- Resolves the SecureActionButton attribute names used for the given action kb.RegisterAction = function(actionType, id, name) assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`') - local target, attributeName, attributeValue, button = atype[actionType](id, name) - local command = target .. attributeName - - return attributeName, attributeValue, command, target, button + local prefix, attributeName, attributeValue, button = atype[actionType](id, name) + local command = prefix .. attributeName + return attributeName, attributeValue, command, prefix, button end +local spells = {} +local SkeletonKey_GetGenericSpell = function(spellName, spellID, icon) + if not spells[spellID] then + spells[spellID] = {} + spells[spellID].actionType = 'spell' + spells[spellID].actionID = spellID + spells[spellID].actionName = spellName + spells[spellID].iconPath = icon + spells[spellID].statusText = '|cFFBBBBBBSpell|r' + spells[spellID].dynamicType = nil + end + return spells[spellID] +end + +-- tries to resolve spells from talent overrides/profession book/etc +local dynamicTypes = {['profession'] = 'ProfessionCache', ['talent'] = 'TalentCache', ['petaction'] = 'PetInfoCache'} +kb.ResolveSpellSlot = function(self) + local spellName, spellID, command, icon = self.actionName, self.actionID, self.command, self.iconPath + --print(' In:', spellName, spellID, command) + --print(GetSpellInfo(spellName or spellID)) + local internalName, _, internalIcon, _, _, _, _ = GetSpellInfo(spellName or spellID) + local isAvailable = internalName and true + + if internalName and (internalName ~= spellName) then + -- it's a binding for the originating spell, leave it as is + print(' |cFFFF4400spell is an override(', internalName, '~=', spellName,') leave the name info alone') + self.statusText = '|cFFFFFF00Spell|r' + self.isAvailable = true + return + end + + -- let's us match spells replaced by talents + local info = kb.DynamicSpells[internalName or spellName] + if not info then + local dynamicType, dynamicIndex, dynamicSubIndex = command:match("(%a+)_(%S+)_(%S+)") + if kb.DynamicSpells[dynamicType] then + print('|cFFFF4400resolving dynamic type index:', internalName, spellName, command) + dynamicIndex = tonumber(dynamicIndex) + dynamicSubIndex = tonumber(dynamicSubIndex) + local cache = kb.DynamicSpells[dynamicType] + print('type:', dynamicType) + if dynamicIndex and cache[dynamicIndex] then + info = kb.DynamicSpells[dynamicType][dynamicIndex] + print('index:', dynamicIndex) + if dynamicSubIndex and info[dynamicSubIndex] then + info = info[dynamicSubIndex] + print('sub-index:', dynamicSubIndex) + end + isAvailable = true + end + end + if not info then + info = SkeletonKey_GetGenericSpell(spellName, spellID, internalIcon or icon) + end + end + info.isAvailable = isAvailable + + print('|cFF00FF88Slot Details:|r', info.actionName, info.actionID, info.dynamicType, info.isAvailable) + for k,v in pairs(info) do + --cprint(' ',k,v) + self[k] = v + end + + return info +end kb.ApplyTalentBinding = function(talentInfo, cache) @@ -312,15 +376,20 @@ if not configTable.assignedKeys then configTable.assignedKeys = {GetBindingKey(configTable.command) } end - if configTable.dynamicType then - kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName) + if configTable.dynamicType == 'talent' then + --kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName) end + for _, key in pairs(configTable.assignedKeys) do + + SetBinding(key, configTable.command) + end + end end end kb.ApplyAllBindings =function () - cprint('|cFF0088FFApplyAllBindings()') + print('|cFFFFFF00ApplyAllBindings()') wipe(kb.TalentBindings) wipe(kb.bindings) --kb:print('Loading binding profile', kb.profileName) @@ -366,7 +435,6 @@ if kb.talentsPushed then return end - wipe(kb.TalentCache) for row =1, MAX_TALENT_TIERS do for col = 1, NUM_TALENT_COLUMNS do local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1) @@ -406,7 +474,6 @@ end kb.talentsPushed = true - kb.UpdateDynamicButtons('talent') end @@ -638,12 +705,9 @@ if #kb.pendingAttributes == 0 then kb:print(kb.L('Key bindings will be applied when you exit combat.')) end - tinsert(kb.pendingAttributes, {target, name, value}) SkeletonKey:RegisterEvent('PLAYER_REGEN_ENABLED') - else - --cprint('|cFFFF4444' .. target:GetName()..'|r.|cFFFFFF00'.. tostring(name)..'|r = "'..tostring(value)..'"') target:SetAttribute(name, value) end