Nenue@70
|
1 -- SkeletonKey
|
Nenue@70
|
2 -- ActionTemplates.lua
|
Nenue@70
|
3 -- Created: 7/29/2016 9:14 PM
|
Nenue@70
|
4 -- %file-revision%
|
Nenue@70
|
5 -- Code dealing with the implementation of action hotkeys
|
Nenue@70
|
6
|
Nenue@70
|
7 local tostring, tonumber, pairs, ipairs = tostring, tonumber, pairs, ipairs
|
Nenue@70
|
8 local unpack, SetBinding = unpack, SetBinding
|
Nenue@70
|
9 local tinsert, tContains, select, wipe = tinsert, tContains, select, table.wipe
|
Nenue@70
|
10 local GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo = GetSpellBookItemInfo, GetSpellBookItemName, GetSpellInfo
|
Nenue@70
|
11 local GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell = GetSpecialization, GetSpecializationInfo, IsPassiveSpell, IsTalentSpell
|
Nenue@70
|
12 local PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells = PetHasSpellbook, PetHasActionBar, GetPetActionInfo, HasPetSpells
|
Nenue@70
|
13 local GetProfessions, GetProfessionInfo, GetTalentInfo = GetProfessions, GetProfessionInfo, GetTalentInfo
|
Nenue@70
|
14 local GetNumBindings, GetBinding = GetNumBindings, GetBinding
|
Nenue@70
|
15
|
Nenue@70
|
16 local _, kb = ...
|
Nenue@70
|
17 local print = (DEVIAN_PNAME == 'SkeletonKey') and function(...) print('SK', ...) end or nop
|
Nenue@70
|
18 local cprint = (DEVIAN_PNAME == 'SkeletonKey') and function(...) _G.print('Cfg', ...) end or nop
|
Nenue@70
|
19
|
Nenue@70
|
20 local CLICK_KEYBINDER_MACRO = "CLICK SkeletonKeyMacro:"
|
Nenue@70
|
21 local CLICK_KEYBINDER_KEY = "CLICK SkeletonKeyKey:"
|
Nenue@70
|
22 local PET_BASIC_SUBTEXT = 'Basic Attack'
|
Nenue@70
|
23 local PET_SPECIAL_SUBTEXT = 'Special Ability'
|
Nenue@70
|
24 local PETACTION_SCRIPT = {
|
Nenue@70
|
25 [PET_ACTION_MOVE_TO] = {'pet_move_to', SLASH_PET_MOVE_TO1},
|
Nenue@70
|
26 [PET_ACTION_ATTACK] = {'pet_attack', SLASH_PET_ATTACK1},
|
Nenue@70
|
27 [PET_ACTION_FOLLOW] = {'pet_follow', SLASH_PET_FOLLOW1},
|
Nenue@70
|
28 [PET_ACTION_WAIT] = {'pet_stay', SLASH_PET_STAY1 },
|
Nenue@70
|
29 [PET_MODE_AGGRESSIVE] = {'pet_aggressive', SLASH_PET_AGGRESSIVE1 },
|
Nenue@70
|
30 [PET_MODE_DEFENSIVE] = { 'pet_defensive', SLASH_PET_DEFENSIVE1},
|
Nenue@70
|
31 [PET_MODE_PASSIVE] = { 'pet_passive', SLASH_PET_PASSIVE1},
|
Nenue@70
|
32 [PET_MODE_ASSIST] = {'pet_assist', SLASH_PET_ASSIST1},
|
Nenue@70
|
33 }
|
Nenue@70
|
34 local SECONDARY_PROFESSIONS = {
|
Nenue@70
|
35 [5] = 3,
|
Nenue@70
|
36 [7] = 4,
|
Nenue@70
|
37 [9] = 5,
|
Nenue@70
|
38 [10] = 6
|
Nenue@70
|
39 }
|
Nenue@70
|
40 local petSpellCache,petSubtextCache
|
Nenue@70
|
41 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
|
Nenue@70
|
42
|
Nenue@70
|
43 --kb.ChangedBindings = {}
|
Nenue@70
|
44 --kb.ActionTypes = {}
|
Nenue@70
|
45
|
Nenue@70
|
46 local atype = kb.ActionTypes
|
Nenue@70
|
47
|
Nenue@70
|
48 --- Caps Lock
|
Nenue@70
|
49 atype['mount'] = function(id, name)
|
Nenue@70
|
50 if id == SUMMON_RANDOM_FAVORITE_MOUNT_SPELL then
|
Nenue@70
|
51 return CLICK_KEYBINDER_MACRO, 'mount_random', "/script C_MountJournal.SummonByID(0)", SkeletonKeyMacro
|
Nenue@70
|
52 else
|
Nenue@70
|
53 return CLICK_KEYBINDER_MACRO, 'mount_'..id, "/script C_MountJournal.SummonByID("..id..")", SkeletonKeyMacro
|
Nenue@70
|
54 end
|
Nenue@70
|
55 end
|
Nenue@70
|
56
|
Nenue@70
|
57 atype['macro'] = function(id, name)
|
Nenue@70
|
58 local _, _, text = GetMacroInfo(id)
|
Nenue@70
|
59 return CLICK_KEYBINDER_MACRO, 'macro_' .. tostring(name), name, SkeletonKeyMacro
|
Nenue@70
|
60 end
|
Nenue@70
|
61
|
Nenue@70
|
62 atype['equipset'] = function(id, name)
|
Nenue@70
|
63 return CLICK_KEYBINDER_MACRO, 'equipset_'..tostring(name), "/script UseEquipmentSet("..tostring(id)..")", SkeletonKeyMacro
|
Nenue@70
|
64 end
|
Nenue@70
|
65
|
Nenue@70
|
66 atype['spell'] = function(id, name)
|
Nenue@70
|
67 local attributeName = name
|
Nenue@70
|
68 if kb.ProfessionCache[id] then
|
Nenue@70
|
69 attributeName = "profession_".. kb.ProfessionCache[id].dynamicIndex .. '_' .. kb.ProfessionCache[id].dynamicSubIndex
|
Nenue@70
|
70 end
|
Nenue@70
|
71 return CLICK_KEYBINDER_KEY, attributeName, name, SkeletonKeyKey
|
Nenue@70
|
72 end
|
Nenue@70
|
73
|
Nenue@70
|
74 atype['petaction'] = function(_, name)
|
Nenue@70
|
75 -- ID doesn't exist for basic commands, even though they can be picked up
|
Nenue@70
|
76 local attributeName, attributeValue = "petaction_" .. tostring(name), "/cast "..tostring(name)
|
Nenue@70
|
77
|
Nenue@70
|
78 if not petSpellCache then
|
Nenue@70
|
79 kb.UpdatePetInfo()
|
Nenue@70
|
80 end
|
Nenue@70
|
81 -- Compose a multi-macro for subtext abilities
|
Nenue@70
|
82 if petSpellCache[name] then
|
Nenue@70
|
83 attributeValue = ""
|
Nenue@70
|
84 for spellName, enabled in pairs(petSubtextCache[petSpellCache[name]]) do
|
Nenue@70
|
85 attributeValue = attributeValue .. "/cast " .. spellName .. "\n"
|
Nenue@70
|
86 end
|
Nenue@70
|
87 end
|
Nenue@70
|
88
|
Nenue@70
|
89 if PETACTION_SCRIPT[name] then
|
Nenue@70
|
90 attributeName, attributeValue = unpack(PETACTION_SCRIPT[name])
|
Nenue@70
|
91 elseif kb.PetCache.special[name] then
|
Nenue@70
|
92 attributeName = "petaction_"..kb.PetCache.special[name][3].."_" .. tonumber(kb.PetCache.special[name][6])
|
Nenue@70
|
93 end
|
Nenue@70
|
94 return CLICK_KEYBINDER_MACRO, attributeName, attributeValue, SkeletonKeyMacro
|
Nenue@70
|
95 end
|
Nenue@70
|
96
|
Nenue@70
|
97 atype['battlepet'] = function(id, name)
|
Nenue@70
|
98 return CLICK_KEYBINDER_MACRO, 'battlepet_' .. tostring(name), SLASH_SUMMON_BATTLE_PET1 .. " " .. tostring(name), SkeletonKeyMacro
|
Nenue@70
|
99 end
|
Nenue@70
|
100
|
Nenue@70
|
101 atype['item'] = function(id, name)
|
Nenue@70
|
102 return CLICK_KEYBINDER_KEY, tostring(name), id, SkeletonKeyKey
|
Nenue@70
|
103 end
|
Nenue@70
|
104
|
Nenue@70
|
105
|
Nenue@70
|
106 --- Resolves the SecureActionButton attribute names used for the given action
|
Nenue@70
|
107 kb.RegisterAction = function(actionType, id, name)
|
Nenue@70
|
108 assert(atype[actionType], 'Missing actionType handler for `'..tostring(actionType)..'`')
|
Nenue@74
|
109 local prefix, attributeName, attributeValue, button = atype[actionType](id, name)
|
Nenue@74
|
110 local command = prefix .. attributeName
|
Nenue@74
|
111 return attributeName, attributeValue, command, prefix, button
|
Nenue@70
|
112 end
|
Nenue@70
|
113
|
Nenue@70
|
114
|
Nenue@74
|
115 local spells = {}
|
Nenue@74
|
116 local SkeletonKey_GetGenericSpell = function(spellName, spellID, icon)
|
Nenue@74
|
117 if not spells[spellID] then
|
Nenue@74
|
118 spells[spellID] = {}
|
Nenue@74
|
119 spells[spellID].actionType = 'spell'
|
Nenue@74
|
120 spells[spellID].actionID = spellID
|
Nenue@74
|
121 spells[spellID].actionName = spellName
|
Nenue@74
|
122 spells[spellID].iconPath = icon
|
Nenue@74
|
123 spells[spellID].statusText = '|cFFBBBBBBSpell|r'
|
Nenue@74
|
124 spells[spellID].dynamicType = nil
|
Nenue@74
|
125 end
|
Nenue@74
|
126 return spells[spellID]
|
Nenue@74
|
127 end
|
Nenue@74
|
128
|
Nenue@74
|
129 -- tries to resolve spells from talent overrides/profession book/etc
|
Nenue@74
|
130 local dynamicTypes = {['profession'] = 'ProfessionCache', ['talent'] = 'TalentCache', ['petaction'] = 'PetInfoCache'}
|
Nenue@74
|
131 kb.ResolveSpellSlot = function(self)
|
Nenue@74
|
132 local spellName, spellID, command, icon = self.actionName, self.actionID, self.command, self.iconPath
|
Nenue@74
|
133 --print(' In:', spellName, spellID, command)
|
Nenue@74
|
134 --print(GetSpellInfo(spellName or spellID))
|
Nenue@74
|
135 local internalName, _, internalIcon, _, _, _, _ = GetSpellInfo(spellName or spellID)
|
Nenue@74
|
136 local isAvailable = internalName and true
|
Nenue@74
|
137
|
Nenue@74
|
138 if internalName and (internalName ~= spellName) then
|
Nenue@74
|
139 -- it's a binding for the originating spell, leave it as is
|
Nenue@74
|
140 print(' |cFFFF4400spell is an override(', internalName, '~=', spellName,') leave the name info alone')
|
Nenue@74
|
141 self.statusText = '|cFFFFFF00Spell|r'
|
Nenue@74
|
142 self.isAvailable = true
|
Nenue@74
|
143 return
|
Nenue@74
|
144 end
|
Nenue@74
|
145
|
Nenue@74
|
146 -- let's us match spells replaced by talents
|
Nenue@74
|
147 local info = kb.DynamicSpells[internalName or spellName]
|
Nenue@74
|
148 if not info then
|
Nenue@74
|
149 local dynamicType, dynamicIndex, dynamicSubIndex = command:match("(%a+)_(%S+)_(%S+)")
|
Nenue@74
|
150 if kb.DynamicSpells[dynamicType] then
|
Nenue@74
|
151 print('|cFFFF4400resolving dynamic type index:', internalName, spellName, command)
|
Nenue@74
|
152 dynamicIndex = tonumber(dynamicIndex)
|
Nenue@74
|
153 dynamicSubIndex = tonumber(dynamicSubIndex)
|
Nenue@74
|
154 local cache = kb.DynamicSpells[dynamicType]
|
Nenue@74
|
155 print('type:', dynamicType)
|
Nenue@74
|
156 if dynamicIndex and cache[dynamicIndex] then
|
Nenue@74
|
157 info = kb.DynamicSpells[dynamicType][dynamicIndex]
|
Nenue@74
|
158 print('index:', dynamicIndex)
|
Nenue@74
|
159 if dynamicSubIndex and info[dynamicSubIndex] then
|
Nenue@74
|
160 info = info[dynamicSubIndex]
|
Nenue@74
|
161 print('sub-index:', dynamicSubIndex)
|
Nenue@74
|
162 end
|
Nenue@74
|
163 isAvailable = true
|
Nenue@74
|
164 end
|
Nenue@74
|
165 end
|
Nenue@74
|
166 if not info then
|
Nenue@74
|
167 info = SkeletonKey_GetGenericSpell(spellName, spellID, internalIcon or icon)
|
Nenue@74
|
168 end
|
Nenue@74
|
169 end
|
Nenue@74
|
170 info.isAvailable = isAvailable
|
Nenue@74
|
171
|
Nenue@74
|
172 print('|cFF00FF88Slot Details:|r', info.actionName, info.actionID, info.dynamicType, info.isAvailable)
|
Nenue@74
|
173 for k,v in pairs(info) do
|
Nenue@74
|
174 --cprint(' ',k,v)
|
Nenue@74
|
175 self[k] = v
|
Nenue@74
|
176 end
|
Nenue@74
|
177
|
Nenue@74
|
178 return info
|
Nenue@74
|
179 end
|
Nenue@70
|
180
|
Nenue@70
|
181
|
Nenue@70
|
182 kb.ApplyTalentBinding = function(talentInfo, cache)
|
Nenue@70
|
183 talentInfo.assignedKeys = talentInfo.assignedKeys or {}
|
Nenue@70
|
184 for i , key in pairs(talentInfo.assignedKeys) do
|
Nenue@70
|
185 local command = CLICK_KEYBINDER_KEY.. talentInfo.actionName
|
Nenue@70
|
186 SetBinding(key, command)
|
Nenue@70
|
187 cprint(' **', i, '->', command)
|
Nenue@70
|
188 tinsert(cache, talentInfo)
|
Nenue@70
|
189 end
|
Nenue@70
|
190 end
|
Nenue@70
|
191 kb.CacheTalentBinding = function(talentInfo, cache)
|
Nenue@70
|
192
|
Nenue@70
|
193 local spellID = talentInfo.actionID
|
Nenue@70
|
194 cache[spellID] = cache[spellID] or {}
|
Nenue@70
|
195 cache[spellID] = talentInfo
|
Nenue@70
|
196 cprint(spellID, unpack(kb.TalentBindings[spellID]))
|
Nenue@70
|
197 end
|
Nenue@70
|
198
|
Nenue@70
|
199
|
Nenue@70
|
200 do
|
Nenue@70
|
201 local commandActions = {}
|
Nenue@70
|
202 local bindings = kb.bindings
|
Nenue@70
|
203 local key, macro = SkeletonKeyKey, SkeletonKeyMacro
|
Nenue@70
|
204 kb.LoadBinding = function( configTable)
|
Nenue@70
|
205 if configTable.command then
|
Nenue@70
|
206 configTable.command = configTable.command:gsub('KeyBinder', 'SkeletonKey')
|
Nenue@70
|
207 end
|
Nenue@70
|
208
|
Nenue@70
|
209 local command, name, icon, actionType, actionID, macroName, macroText =
|
Nenue@70
|
210 configTable.command, configTable.actionName, configTable.iconPath, configTable.actionType,
|
Nenue@70
|
211 configTable.actionID, configTable.macroName, configTable.macroText
|
Nenue@70
|
212
|
Nenue@70
|
213
|
Nenue@70
|
214 local indexKey = actionType..'_'..actionID
|
Nenue@70
|
215 local actionPrefix = "*"..actionType.."-"
|
Nenue@70
|
216 local button = SkeletonKeyKey
|
Nenue@72
|
217 local isAvailable
|
Nenue@70
|
218 local specialButtonType
|
Nenue@70
|
219 if actionType == 'spell' then
|
Nenue@72
|
220 cprint(GetSpellInfo(actionID))
|
Nenue@72
|
221 cprint(GetSpellInfo(name))
|
Nenue@72
|
222 if GetSpellInfo(name) then
|
Nenue@72
|
223 isAvailable = true
|
Nenue@70
|
224 end
|
Nenue@71
|
225 local dynamicInfo = kb.DynamicSpells[name]
|
Nenue@70
|
226 if dynamicInfo then
|
Nenue@71
|
227 configTable.assignedKeys = configTable.assignedKeys or {GetBindingKey(configTable.command)}
|
Nenue@72
|
228 cprint('|cFF00FFFFDynamicInfo:|r', dynamicInfo.dynamicType, table.concat(configTable.assignedKeys, ','))
|
Nenue@70
|
229 for k, v in pairs(dynamicInfo) do
|
Nenue@71
|
230 --cprint(' --', k, v)
|
Nenue@70
|
231 configTable[k] = v
|
Nenue@70
|
232 end
|
Nenue@70
|
233 end
|
Nenue@71
|
234
|
Nenue@70
|
235 else
|
Nenue@70
|
236 if actionType ~= 'macro' then
|
Nenue@70
|
237 actionPrefix = '*macrotext-'
|
Nenue@70
|
238 end
|
Nenue@70
|
239
|
Nenue@70
|
240 specialButtonType = 'macro'
|
Nenue@73
|
241 isAvailable = true
|
Nenue@70
|
242 end
|
Nenue@70
|
243
|
Nenue@72
|
244 if isAvailable then
|
Nenue@70
|
245
|
Nenue@72
|
246 local attributeSuffix, attributeValue, command, target, button = kb.RegisterAction(actionType, actionID, name)
|
Nenue@72
|
247 local actionKey = actionPrefix .. attributeSuffix
|
Nenue@72
|
248 cprint('|cFF00FF88LoadBinding()|r', button:GetName(), "*type-"..attributeSuffix, actionType, '|cFFFFFF00'..actionKey, attributeValue, isAvailable)
|
Nenue@70
|
249
|
Nenue@70
|
250
|
Nenue@70
|
251 kb.SecureAttribute(button, "*type-"..attributeSuffix, specialButtonType or actionType)
|
Nenue@70
|
252 kb.SecureAttribute(button, actionKey, attributeValue)
|
Nenue@72
|
253
|
Nenue@72
|
254 cprint('|cFFFF4400add', name, isAvailable, indexKey, unpack(configTable.assignedKeys))
|
Nenue@70
|
255 kb.bindings[indexKey] = configTable.assignedKeys
|
Nenue@70
|
256 commandActions[command] = kb.bindings[indexKey]
|
Nenue@70
|
257 return command, kb.bindings[indexKey]
|
Nenue@70
|
258 else
|
Nenue@72
|
259 if kb.bindings[indexKey] then
|
Nenue@72
|
260 cprint('|cFFFF4400remove', name, isAvailable, indexKey, unpack(configTable.assignedKeys))
|
Nenue@72
|
261 kb.bindings[indexKey] = nil
|
Nenue@72
|
262 end
|
Nenue@72
|
263
|
Nenue@70
|
264 return nil
|
Nenue@70
|
265 end
|
Nenue@70
|
266 end
|
Nenue@70
|
267
|
Nenue@71
|
268
|
Nenue@70
|
269 local usedSlots = {}
|
Nenue@71
|
270 kb.UpgradeProfile = function(profile)
|
Nenue@70
|
271 wipe(usedSlots)
|
Nenue@70
|
272 for slot, configTable in pairs(profile.buttons) do
|
Nenue@70
|
273
|
Nenue@71
|
274 -- convert old style table
|
Nenue@70
|
275 if #configTable >= 1 then
|
Nenue@70
|
276 local command, name, icon, actionType, actionID, macroName, macroText, spellbookSlot, spellbookType = unpack(configTable)
|
Nenue@70
|
277
|
Nenue@70
|
278 cprint('|CFFFF4400Fixing pad entry', slot, command, name)
|
Nenue@70
|
279 local assignedKeys = {GetBindingKey(command)}
|
Nenue@70
|
280 for k,v in pairs(profile.bindings) do
|
Nenue@70
|
281 if v == command then
|
Nenue@70
|
282 tinsert(assignedKeys, k)
|
Nenue@70
|
283 end
|
Nenue@70
|
284 end
|
Nenue@70
|
285
|
Nenue@70
|
286 configTable = {
|
Nenue@70
|
287 command = command,
|
Nenue@70
|
288 actionType = actionType,
|
Nenue@70
|
289 actionName = name,
|
Nenue@70
|
290 actionID = actionID,
|
Nenue@70
|
291 macroName = macroName,
|
Nenue@70
|
292 macroText = macroText,
|
Nenue@70
|
293 iconPath = icon,
|
Nenue@70
|
294 spellbookSlot = spellbookSlot,
|
Nenue@70
|
295 spellbookType = spellbookType,
|
Nenue@70
|
296 assignedKeys = assignedKeys
|
Nenue@70
|
297 }
|
Nenue@71
|
298
|
Nenue@71
|
299 local dynamic = kb.DynamicSpells[name]
|
Nenue@71
|
300 if dynamic then
|
Nenue@71
|
301 configTable.dynamicType = dynamic.dynamicType
|
Nenue@71
|
302 configTable.dynamicIndex = dynamic.dynamicIndex
|
Nenue@71
|
303 configTable.dynamicSubIndex = dynamic.dynamicSubIndex
|
Nenue@71
|
304 configTable.dynamicID = dynamic.dynamicID
|
Nenue@71
|
305 if configTable.dynamicType == 'talent' then
|
Nenue@71
|
306 profile.talents[name] = configTable
|
Nenue@71
|
307 end
|
Nenue@71
|
308 end
|
Nenue@71
|
309
|
Nenue@71
|
310
|
Nenue@70
|
311 kb.currentProfile.buttons[slot] = configTable
|
Nenue@70
|
312 end
|
Nenue@70
|
313 if not configTable.actionID then
|
Nenue@70
|
314 configTable.actionID = configTable.actionName
|
Nenue@70
|
315 end
|
Nenue@70
|
316 if not configTable.iconPath then
|
Nenue@70
|
317 print('corrected missing icon')
|
Nenue@70
|
318 configTable.iconPath = GetSpellTexture(configTable.actionName)
|
Nenue@70
|
319 end
|
Nenue@70
|
320
|
Nenue@70
|
321 usedSlots[configTable.actionName or configTable.actionID] = true
|
Nenue@70
|
322 usedSlots[configTable.command] = true
|
Nenue@70
|
323 end
|
Nenue@70
|
324
|
Nenue@70
|
325
|
Nenue@71
|
326 -- clean up legacy data
|
Nenue@70
|
327 for spellName, talentInfo in pairs(profile.talents) do
|
Nenue@70
|
328 if not usedSlots[spellName] then
|
Nenue@70
|
329 cprint('|cFFFF4400Unslotted talent', spellName)
|
Nenue@70
|
330 profile.talents[spellName] = nil
|
Nenue@70
|
331 end
|
Nenue@70
|
332 end
|
Nenue@70
|
333 for command in pairs(profile.bound) do
|
Nenue@70
|
334 if not usedSlots[command] then
|
Nenue@70
|
335 cprint('|cFFFF4400Unslotted bound entry', command)
|
Nenue@70
|
336 profile.bound[command] = nil
|
Nenue@70
|
337 profile.commands[command] = nil
|
Nenue@70
|
338 end
|
Nenue@70
|
339 end
|
Nenue@70
|
340 for command in pairs(profile.commands) do
|
Nenue@70
|
341 if not usedSlots[command] then
|
Nenue@70
|
342 cprint('|cFFFF4400Unslotted command entry', command)
|
Nenue@70
|
343 profile.commands[command] = nil
|
Nenue@70
|
344 end
|
Nenue@70
|
345 end
|
Nenue@71
|
346 end
|
Nenue@70
|
347
|
Nenue@71
|
348 kb.ApplyBindings = function (profile)
|
Nenue@71
|
349 cprint('|cFF0088FFApplyBindings()')
|
Nenue@71
|
350 --cprint('binding profile', profile)
|
Nenue@71
|
351
|
Nenue@71
|
352 local version = profile.versionID or 0
|
Nenue@71
|
353 if version < 310 then
|
Nenue@71
|
354 kb.UpgradeProfile(profile)
|
Nenue@71
|
355 end
|
Nenue@71
|
356
|
Nenue@71
|
357 -- do flat bindings to start
|
Nenue@71
|
358 for key, command in pairs(profile.bindings) do
|
Nenue@71
|
359 command = command:gsub('KeyBinder', 'SkeletonKey')
|
Nenue@71
|
360 profile.bindings[key] = command
|
Nenue@71
|
361 cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command)
|
Nenue@71
|
362 SetBinding(key, command)
|
Nenue@71
|
363 if commandActions[command] and not tContains(commandActions[command], key) then
|
Nenue@71
|
364 tinsert(commandActions[command], key)
|
Nenue@71
|
365 end
|
Nenue@71
|
366 end
|
Nenue@71
|
367
|
Nenue@71
|
368 -- then buttons
|
Nenue@71
|
369 for slot, configTable in pairs(profile.buttons) do
|
Nenue@71
|
370 -- convert old style table
|
Nenue@71
|
371 if kb.LoadBinding(configTable) then
|
Nenue@71
|
372 local talent = profile.talents[configTable.actionName]
|
Nenue@71
|
373 if talent then
|
Nenue@71
|
374 configTable.assignedKeys = talent.assignedKeys
|
Nenue@71
|
375 end
|
Nenue@71
|
376 if not configTable.assignedKeys then
|
Nenue@71
|
377 configTable.assignedKeys = {GetBindingKey(configTable.command) }
|
Nenue@71
|
378 end
|
Nenue@74
|
379 if configTable.dynamicType == 'talent' then
|
Nenue@74
|
380 --kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName)
|
Nenue@71
|
381 end
|
Nenue@74
|
382 for _, key in pairs(configTable.assignedKeys) do
|
Nenue@74
|
383
|
Nenue@74
|
384 SetBinding(key, configTable.command)
|
Nenue@74
|
385 end
|
Nenue@74
|
386
|
Nenue@71
|
387 end
|
Nenue@71
|
388 end
|
Nenue@70
|
389 end
|
Nenue@70
|
390
|
Nenue@70
|
391 kb.ApplyAllBindings =function ()
|
Nenue@74
|
392 print('|cFFFFFF00ApplyAllBindings()')
|
Nenue@70
|
393 wipe(kb.TalentBindings)
|
Nenue@70
|
394 wipe(kb.bindings)
|
Nenue@70
|
395 --kb:print('Loading binding profile', kb.profileName)
|
Nenue@70
|
396
|
Nenue@70
|
397 -- reflect action key settings
|
Nenue@70
|
398 if GetCVarBool("ActionButtonUseKeyDown") then
|
Nenue@70
|
399 SkeletonKeyMacro:RegisterForClicks("AnyDown")
|
Nenue@70
|
400 SkeletonKeyKey:RegisterForClicks("AnyDown")
|
Nenue@70
|
401 else
|
Nenue@70
|
402 SkeletonKeyMacro:RegisterForClicks("AnyUp")
|
Nenue@70
|
403 SkeletonKeyKey:RegisterForClicks("AnyUp")
|
Nenue@70
|
404 end
|
Nenue@70
|
405
|
Nenue@70
|
406 for i, profile in ipairs(kb.orderedProfiles) do
|
Nenue@70
|
407 kb.ApplyBindings(profile)
|
Nenue@70
|
408 end
|
Nenue@70
|
409 -- do this after to ensure that profession binds are properly overridden
|
Nenue@70
|
410 kb.UpdateProfessionInfo()
|
Nenue@70
|
411
|
Nenue@70
|
412 SaveBindings(GetCurrentBindingSet())
|
Nenue@72
|
413
|
Nenue@70
|
414 end
|
Nenue@70
|
415 end
|
Nenue@70
|
416
|
Nenue@70
|
417
|
Nenue@70
|
418 kb.specInfo = {}
|
Nenue@70
|
419 kb.UpdateSpecInfo = function()
|
Nenue@70
|
420 kb.specInfo.id = GetSpecialization()
|
Nenue@70
|
421 kb.specInfo.globalID, kb.specInfo.name, kb.specInfo.desc, kb.specInfo.texture = GetSpecializationInfo(kb.specInfo.id)
|
Nenue@70
|
422 end
|
Nenue@70
|
423
|
Nenue@70
|
424 kb.UpdateMacroInfo = function()
|
Nenue@70
|
425 print('|cFFFFFF00kb.UpdateMacroInfo()|r')
|
Nenue@70
|
426 for index = 1, GetNumMacros() do
|
Nenue@70
|
427 local name = GetMacroInfo(index)
|
Nenue@70
|
428 kb.SecureAttribute(SkeletonKeyMacro, "*type-macro_"..tostring(name), 'macro')
|
Nenue@70
|
429 kb.SecureAttribute(SkeletonKeyMacro, "*macro-macro_"..tostring(name), index)
|
Nenue@70
|
430 end
|
Nenue@70
|
431 end
|
Nenue@70
|
432
|
Nenue@70
|
433 kb.UpdateTalentInfo = function()
|
Nenue@70
|
434 print('|cFFFFFF00kb.UpdateTalentInfo()|r')
|
Nenue@70
|
435 if kb.talentsPushed then
|
Nenue@70
|
436 return
|
Nenue@70
|
437 end
|
Nenue@70
|
438 for row =1, MAX_TALENT_TIERS do
|
Nenue@70
|
439 for col = 1, NUM_TALENT_COLUMNS do
|
Nenue@70
|
440 local talentID, talentName, icon, selected, available, spellID = GetTalentInfo(row, col, 1)
|
Nenue@70
|
441 local talentInfo = kb.TalentCache[spellID] or {}
|
Nenue@70
|
442 if spellID then
|
Nenue@70
|
443 talentInfo.actionType = 'spell'
|
Nenue@70
|
444 talentInfo.actionName = talentName
|
Nenue@70
|
445 talentInfo.dynamicType = 'talent'
|
Nenue@70
|
446 talentInfo.dynamicID = talentID
|
Nenue@70
|
447 talentInfo.dynamicIndex = row
|
Nenue@70
|
448 talentInfo.dynamicSubIndex = col
|
Nenue@70
|
449 talentInfo.actionID = spellID
|
Nenue@70
|
450 talentInfo.isAvailable = selected
|
Nenue@70
|
451 kb.DynamicSpells[spellID] = talentInfo
|
Nenue@70
|
452 kb.DynamicSpells[talentName] = talentInfo
|
Nenue@70
|
453 end
|
Nenue@70
|
454
|
Nenue@70
|
455 --print('Talent ', row, col, spellID, talentName)
|
Nenue@70
|
456 end
|
Nenue@70
|
457 end
|
Nenue@70
|
458
|
Nenue@70
|
459 for row = 1, MAX_PVP_TALENT_TIERS do
|
Nenue@70
|
460 for col = 1, MAX_PVP_TALENT_COLUMNS do
|
Nenue@70
|
461 local id, name, icon, selected, available, spellID, unlocked = GetPvpTalentInfo(row, col, 1)
|
Nenue@70
|
462 if spellID then
|
Nenue@70
|
463 local talentInfo = kb.TalentCache[spellID] or {}
|
Nenue@70
|
464 talentInfo.actionType = 'spell'
|
Nenue@70
|
465 talentInfo.actionName = name
|
Nenue@70
|
466 talentInfo.dynamicType = 'talent'
|
Nenue@70
|
467 talentInfo.dynamicID = id
|
Nenue@70
|
468 talentInfo.actionID = spellID
|
Nenue@70
|
469 talentInfo.isAvailable = selected
|
Nenue@70
|
470 kb.DynamicSpells[spellID] = talentInfo
|
Nenue@70
|
471 kb.DynamicSpells[name] = talentInfo
|
Nenue@70
|
472 end
|
Nenue@70
|
473 end
|
Nenue@70
|
474 end
|
Nenue@70
|
475
|
Nenue@70
|
476 kb.talentsPushed = true
|
Nenue@70
|
477 kb.UpdateDynamicButtons('talent')
|
Nenue@70
|
478 end
|
Nenue@70
|
479
|
Nenue@70
|
480 kb.UpdateProfessionInfo = function()
|
Nenue@70
|
481 wipe(kb.ProfessionCache)
|
Nenue@70
|
482 local profs = {GetProfessions() }
|
Nenue@70
|
483 --print(GetProfessions())
|
Nenue@70
|
484 local primaryNum = 0
|
Nenue@70
|
485 for i = 1, 6 do
|
Nenue@70
|
486 if profs[i] then
|
Nenue@70
|
487 local profID = profs[i]
|
Nenue@70
|
488 local profName, texture, _, _, numSpells, spellOffset = GetProfessionInfo(profID)
|
Nenue@70
|
489 cprint(i, profID, profName, numSpells, spellOffset)
|
Nenue@70
|
490 if not SECONDARY_PROFESSIONS[profID] then
|
Nenue@70
|
491 primaryNum = primaryNum + 1
|
Nenue@70
|
492 end
|
Nenue@70
|
493 local profNum = SECONDARY_PROFESSIONS[profID] or primaryNum
|
Nenue@70
|
494 cprint(i, profNum)
|
Nenue@70
|
495
|
Nenue@70
|
496
|
Nenue@70
|
497 kb.ProfessionCache[profNum] = kb.ProfessionCache[profNum] or {}
|
Nenue@70
|
498
|
Nenue@70
|
499 for j = 1, numSpells do
|
Nenue@70
|
500 local spellName, _, icon, _, _, _, spellID = GetSpellInfo(spellOffset+j, BOOKTYPE_PROFESSION)
|
Nenue@70
|
501 cprint(j, spellName)
|
Nenue@70
|
502 local profInfo = {
|
Nenue@70
|
503 actionType = 'spell',
|
Nenue@70
|
504 actionName = spellName,
|
Nenue@70
|
505 statusText = 'Profession ' .. i,
|
Nenue@70
|
506 actionID = spellID,
|
Nenue@70
|
507 iconPath = icon,
|
Nenue@70
|
508 dynamicIndex = i,
|
Nenue@70
|
509 dynamicSubIndex = j,
|
Nenue@70
|
510 dynamicType = 'profession',
|
Nenue@70
|
511 spellbookOffset = (spellOffset+j),
|
Nenue@70
|
512 spellbookType = BOOKTYPE_PROFESSION,
|
Nenue@70
|
513 isAvailable = true,
|
Nenue@70
|
514 -- need to check if necessary
|
Nenue@70
|
515 uniqueID = profID,
|
Nenue@70
|
516 }
|
Nenue@70
|
517
|
Nenue@70
|
518 kb.SecureAttribute(SkeletonKeyKey, "*type-profession_"..i .. '_' ..j, "spell")
|
Nenue@70
|
519 kb.SecureAttribute(SkeletonKeyKey, "*spell-profession_"..i .. '_' ..j, spellName)
|
Nenue@70
|
520
|
Nenue@70
|
521 kb.ProfessionCache[spellName] = profInfo
|
Nenue@70
|
522 kb.ProfessionCache[spellID] = profInfo
|
Nenue@70
|
523
|
Nenue@70
|
524 kb.DynamicSpells[spellName] = profInfo
|
Nenue@70
|
525 kb.DynamicSpells[spellID] = profInfo
|
Nenue@70
|
526
|
Nenue@70
|
527 kb.DynamicSpells.profession[i] = kb.DynamicSpells.profession[i] or {}
|
Nenue@70
|
528 kb.DynamicSpells.profession[i][j] = profInfo
|
Nenue@70
|
529 --print(' |cFF0088FF['..i..']|r|cFFFF44BB['..spellOffset+i..']|r', spellName, "profession_"..i .. '_' ..j)
|
Nenue@70
|
530 end
|
Nenue@70
|
531 end
|
Nenue@70
|
532
|
Nenue@70
|
533 end
|
Nenue@70
|
534
|
Nenue@70
|
535 kb.UpdateDynamicButtons('profession')
|
Nenue@70
|
536 end
|
Nenue@70
|
537
|
Nenue@70
|
538
|
Nenue@70
|
539
|
Nenue@70
|
540 kb.UpdatePetInfo = function()
|
Nenue@70
|
541 local hasPetSpells, petType = HasPetSpells()
|
Nenue@70
|
542
|
Nenue@70
|
543 -- reconcile saved data if it becomes available
|
Nenue@70
|
544 if kb.db then
|
Nenue@70
|
545 kb.db.petSpellsDB = kb.db.petSpellsDB or {}
|
Nenue@70
|
546 kb.db.petSpellsDB.subtext = kb.db.petSpellsDB.subtext or {}
|
Nenue@70
|
547 kb.db.petSpellsDB.spell = kb.db.petSpellsDB.spell or {}
|
Nenue@70
|
548 local spellCache = kb.db.petSpellsDB.spell
|
Nenue@70
|
549 local subtextCache = kb.db.petSpellsDB.subtext
|
Nenue@70
|
550 if petSpellCache then
|
Nenue@70
|
551 for k,v in pairs(petSpellCache) do
|
Nenue@70
|
552 if not spellCache[k] then
|
Nenue@70
|
553 spellCache[k] = v
|
Nenue@70
|
554 end
|
Nenue@70
|
555 end
|
Nenue@70
|
556 end
|
Nenue@70
|
557 petSpellCache = spellCache
|
Nenue@70
|
558 if petSubtextCache then
|
Nenue@70
|
559 for k,v in pairs(petSubtextCache) do
|
Nenue@70
|
560 if not subtextCache[k] then
|
Nenue@70
|
561 subtextCache[k] = v
|
Nenue@70
|
562 end
|
Nenue@70
|
563 end
|
Nenue@70
|
564 end
|
Nenue@70
|
565 petSubtextCache = subtextCache
|
Nenue@70
|
566 else
|
Nenue@70
|
567 petSpellCache = {}
|
Nenue@70
|
568 petSubtextCache = {}
|
Nenue@70
|
569 end
|
Nenue@70
|
570
|
Nenue@70
|
571 if PetHasSpellbook() then
|
Nenue@70
|
572 --print('PET SPELLBOOK')
|
Nenue@70
|
573 local spellbookOffset = 1
|
Nenue@70
|
574 local specialNum = {}
|
Nenue@70
|
575 local newSubtextItems = false
|
Nenue@70
|
576
|
Nenue@70
|
577 repeat
|
Nenue@70
|
578
|
Nenue@70
|
579 local spellType, spellID = GetSpellBookItemInfo(spellbookOffset, BOOKTYPE_PET)
|
Nenue@70
|
580 local spellName, subText = GetSpellBookItemName(spellbookOffset, BOOKTYPE_PET)
|
Nenue@70
|
581 local texture = GetSpellBookItemTexture(spellbookOffset, BOOKTYPE_PET)
|
Nenue@70
|
582 if (spellType == 'SPELL') and (not IsPassiveSpell(spellbookOffset, BOOKTYPE_PET)) then
|
Nenue@70
|
583 local info = kb.PetCache[spellName] or {}
|
Nenue@70
|
584 kb.PetCache.spellslot[spellName] = {spellbookOffset, spellName, subText, spellID, texture}
|
Nenue@70
|
585 --print('|cFF00FF88spellslot['..spellName..']|r', '=>', i, subText)
|
Nenue@70
|
586
|
Nenue@70
|
587 if subText then
|
Nenue@70
|
588 kb.PetCache.subtext[subText] = kb.PetCache.subtext[subText] or {}
|
Nenue@70
|
589 specialNum[subText] = (specialNum[subText] or 0) + 1
|
Nenue@70
|
590
|
Nenue@70
|
591 petSpellCache[spellName] = subText
|
Nenue@70
|
592 petSubtextCache[subText] = petSubtextCache[subText] or {}
|
Nenue@70
|
593
|
Nenue@70
|
594 -- add to the list
|
Nenue@70
|
595 if not petSubtextCache[subText][spellName] then
|
Nenue@70
|
596 petSubtextCache[subText][spellName] = true
|
Nenue@70
|
597 newSubtextItems = true
|
Nenue@70
|
598 --print('|cFF00FFFFspecial['..spellName..']|r', '\n','|cFF00FFFFsubtext['..subText..']['..specialNum[subText]..']|r', '=>', i, spellName, subText, spellID, texture, specialNum[subText])
|
Nenue@70
|
599 end
|
Nenue@70
|
600
|
Nenue@70
|
601
|
Nenue@70
|
602
|
Nenue@70
|
603 local entry = {spellbookOffset, spellName, subText, spellID, texture, specialNum[subText] }
|
Nenue@70
|
604
|
Nenue@70
|
605
|
Nenue@70
|
606 info.spellbookOffset = spellbookOffset
|
Nenue@70
|
607 info.spellbookType = BOOKTYPE_PET
|
Nenue@70
|
608 info.actionName = spellName
|
Nenue@70
|
609 info.spellID = spellID
|
Nenue@70
|
610 info.dynamicType = 'petaction'
|
Nenue@70
|
611 info.dynamicID = spellID
|
Nenue@70
|
612 info.dynamicIndex = subText
|
Nenue@70
|
613 info.dynamicSubIndex = specialNum[subText]
|
Nenue@70
|
614 info.isAvailable = true
|
Nenue@70
|
615
|
Nenue@70
|
616 kb.PetCache.special[spellName] = info
|
Nenue@70
|
617 kb.PetCache.subtext[subText][specialNum[subText]] = info
|
Nenue@70
|
618 kb.DynamicSpells[spellName] = info
|
Nenue@70
|
619 kb.DynamicSpells[spellID] = info
|
Nenue@70
|
620
|
Nenue@70
|
621 end
|
Nenue@70
|
622
|
Nenue@70
|
623 if spellID then
|
Nenue@70
|
624 kb.PetCache.spell[spellbookOffset] = {spellID, spellName, subText}
|
Nenue@70
|
625 --print('|cFF0088FFspell['..i..']|r', '=>', spellID, spellName, subText)
|
Nenue@70
|
626 end
|
Nenue@70
|
627
|
Nenue@70
|
628 kb.PetCache[spellName] = info
|
Nenue@70
|
629 end
|
Nenue@70
|
630
|
Nenue@70
|
631 spellbookOffset = spellbookOffset + 1
|
Nenue@70
|
632 until spellType == nil
|
Nenue@70
|
633
|
Nenue@70
|
634 if newSubtextItems then
|
Nenue@70
|
635
|
Nenue@70
|
636 local macrotext = ""
|
Nenue@70
|
637 for subText, spells in pairs(petSubtextCache) do
|
Nenue@70
|
638 if specialNum[subText] then
|
Nenue@70
|
639 for spellName, enabled in pairs(spells) do
|
Nenue@70
|
640 macrotext = macrotext .. "/cast " .. spellName .. "\n"
|
Nenue@70
|
641 end
|
Nenue@70
|
642 kb.SecureAttribute(SkeletonKeyMacro, "*macrotext-petaction_"..subText.."_"..specialNum[subText], macrotext)
|
Nenue@70
|
643 end
|
Nenue@70
|
644 end
|
Nenue@70
|
645 end
|
Nenue@70
|
646
|
Nenue@70
|
647
|
Nenue@70
|
648 else
|
Nenue@70
|
649 --print('NO PET SPELLBOOK')
|
Nenue@70
|
650 wipe(kb.PetCache.spell)
|
Nenue@70
|
651 wipe(kb.PetCache.spellslot)
|
Nenue@70
|
652 end
|
Nenue@70
|
653
|
Nenue@70
|
654 if PetHasActionBar() then
|
Nenue@70
|
655 --print('PET ACTION BAR')
|
Nenue@70
|
656 for i = 1, 10 do
|
Nenue@70
|
657
|
Nenue@70
|
658
|
Nenue@70
|
659 local name, subtext, texture, isToken, isActive = GetPetActionInfo(i)
|
Nenue@70
|
660 if name then
|
Nenue@70
|
661 kb.PetCache.action[i] = {name, subtext, texture, isToken, isActive }
|
Nenue@70
|
662
|
Nenue@70
|
663
|
Nenue@70
|
664 end
|
Nenue@70
|
665 --print('|cFFFFFF00action['..i..']|r', name, subtext, texture)
|
Nenue@70
|
666 end
|
Nenue@70
|
667 else
|
Nenue@70
|
668 --print('NO PET ACTION BAR')
|
Nenue@70
|
669 wipe(kb.PetCache.action)
|
Nenue@70
|
670 end
|
Nenue@70
|
671
|
Nenue@70
|
672 kb.UpdateDynamicButtons('petaction')
|
Nenue@70
|
673
|
Nenue@70
|
674 end
|
Nenue@70
|
675
|
Nenue@70
|
676 kb.UpdateSystemBinds = function()
|
Nenue@70
|
677 wipe(kb.SystemBindings)
|
Nenue@70
|
678 local n = GetNumBindings()
|
Nenue@70
|
679 for i=1, n do
|
Nenue@70
|
680 local command, key1, key2 = GetBinding(i)
|
Nenue@70
|
681 if not command:match('ACTION.*%d+') then
|
Nenue@70
|
682 if key1 then
|
Nenue@70
|
683 kb.SystemBindings[key1] = command
|
Nenue@70
|
684 end
|
Nenue@70
|
685 if key2 then
|
Nenue@70
|
686 kb.SystemBindings[key2] = command
|
Nenue@70
|
687 end
|
Nenue@70
|
688 else
|
Nenue@70
|
689 --print('ignoring action button binding', command)
|
Nenue@70
|
690 end
|
Nenue@70
|
691 end
|
Nenue@70
|
692 end
|
Nenue@70
|
693
|
Nenue@70
|
694 kb.UpdateDynamicButtons = function(dynamicType)
|
Nenue@70
|
695 for i, button in ipairs(kb.buttons) do
|
Nenue@70
|
696 if button.isDynamic == dynamicType then
|
Nenue@70
|
697 kb.UpdateSlot(button, true)
|
Nenue@70
|
698 end
|
Nenue@70
|
699 end
|
Nenue@70
|
700 end
|
Nenue@70
|
701
|
Nenue@70
|
702 kb.pendingAttributes = {}
|
Nenue@70
|
703 kb.SecureAttribute = function(target, name, value)
|
Nenue@70
|
704 if InCombatLockdown() then
|
Nenue@70
|
705 if #kb.pendingAttributes == 0 then
|
Nenue@70
|
706 kb:print(kb.L('Key bindings will be applied when you exit combat.'))
|
Nenue@70
|
707 end
|
Nenue@70
|
708 tinsert(kb.pendingAttributes, {target, name, value})
|
Nenue@70
|
709 SkeletonKey:RegisterEvent('PLAYER_REGEN_ENABLED')
|
Nenue@70
|
710 else
|
Nenue@70
|
711 --cprint('|cFFFF4444' .. target:GetName()..'|r.|cFFFFFF00'.. tostring(name)..'|r = "'..tostring(value)..'"')
|
Nenue@70
|
712 target:SetAttribute(name, value)
|
Nenue@70
|
713 end
|
Nenue@70
|
714 end
|
Nenue@70
|
715
|
Nenue@70
|
716 kb.PLAYER_REGEN_ENABLED = function()
|
Nenue@70
|
717 if #kb.pendingAttributes >= 1 then
|
Nenue@70
|
718 local args = tremove(kb.pendingAttributes)
|
Nenue@70
|
719 while args do
|
Nenue@70
|
720 local target, name, value = unpack(args)
|
Nenue@70
|
721 --print(target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
|
Nenue@70
|
722 cprint('deferred', target:GetName(), 'attribute', '"'.. tostring(name)..'" = "'..tostring(value)..'"')
|
Nenue@70
|
723 target:SetAttribute(name, value)
|
Nenue@70
|
724 args = tremove(kb.pendingAttributes)
|
Nenue@70
|
725 end
|
Nenue@70
|
726 end
|
Nenue@70
|
727
|
Nenue@70
|
728 if #kb.pendingCalls >= 1 then
|
Nenue@70
|
729
|
Nenue@70
|
730 local func = tremove(kb.pendingCalls)
|
Nenue@70
|
731 while func do
|
Nenue@70
|
732 func()
|
Nenue@70
|
733 end
|
Nenue@70
|
734 end
|
Nenue@70
|
735 end
|
Nenue@70
|
736
|
Nenue@70
|
737 kb.UpdateBindingsCache = function(actionType, actionID, bindings)
|
Nenue@70
|
738 local indexKey = actionType .. '_' .. actionID
|
Nenue@70
|
739 kb.bindings[indexKey] = bindings
|
Nenue@70
|
740
|
Nenue@70
|
741 cprint('|cFF00FF00'..indexKey..'|r = {'.. table.concat(bindings,', ').. '}')
|
Nenue@70
|
742 tinsert(kb.ChangedBindings, {actionType, actionID})
|
Nenue@70
|
743 end |