comparison ActionTemplates.lua @ 71:ca3118127e5e

- Talent change detection - Use stored assignments for inactive talent slots
author Nenue
date Fri, 06 Jan 2017 16:21:49 -0500
parents 131d9190db6b
children c48913c5924c
comparison
equal deleted inserted replaced
70:131d9190db6b 71:ca3118127e5e
154 local specialButtonType 154 local specialButtonType
155 if actionType == 'spell' then 155 if actionType == 'spell' then
156 if not GetSpellInfo(actionID) then 156 if not GetSpellInfo(actionID) then
157 isAvailable = nil 157 isAvailable = nil
158 end 158 end
159 local dynamicInfo = kb.TalentCache[name] or kb.ProfessionCache[name] 159 local dynamicInfo = kb.DynamicSpells[name]
160 if dynamicInfo then 160 if dynamicInfo then
161 cprint('|cFF00FFFFDynamicInfo:|r', name) 161 configTable.assignedKeys = configTable.assignedKeys or {GetBindingKey(configTable.command)}
162 cprint('|cFF00FFFFDynamicInfo:|r', dynamicInfo.dynamicType, table.concat(configTable.assignedKeys or {}, ','))
162 for k, v in pairs(dynamicInfo) do 163 for k, v in pairs(dynamicInfo) do
163 cprint(' --', k, v) 164 --cprint(' --', k, v)
164 configTable[k] = v 165 configTable[k] = v
165 end 166 end
166 end 167 end
168
169
167 else 170 else
168 if actionType ~= 'macro' then 171 if actionType ~= 'macro' then
169 actionPrefix = '*macrotext-' 172 actionPrefix = '*macrotext-'
170 end 173 end
171 174
173 end 176 end
174 177
175 local attributeSuffix, attributeValue, command, target, button = kb.RegisterAction(actionType, actionID, name) 178 local attributeSuffix, attributeValue, command, target, button = kb.RegisterAction(actionType, actionID, name)
176 local actionKey = actionPrefix .. attributeSuffix 179 local actionKey = actionPrefix .. attributeSuffix
177 cprint('|cFF00FF88LoadBinding()|r', button:GetName(), "*type-"..attributeSuffix, actionType, '|cFFFFFF00'..actionKey, attributeValue) 180 cprint('|cFF00FF88LoadBinding()|r', button:GetName(), "*type-"..attributeSuffix, actionType, '|cFFFFFF00'..actionKey, attributeValue)
181
178 182
179 183
180 184
181 if isAvailable then 185 if isAvailable then
182 kb.SecureAttribute(button, "*type-"..attributeSuffix, specialButtonType or actionType) 186 kb.SecureAttribute(button, "*type-"..attributeSuffix, specialButtonType or actionType)
187 else 191 else
188 return nil 192 return nil
189 end 193 end
190 end 194 end
191 195
196
192 local usedSlots = {} 197 local usedSlots = {}
193 kb.ApplyBindings = function (profile) 198 kb.UpgradeProfile = function(profile)
194 cprint('|cFF0088FFApplyBindings()')
195 --cprint('binding profile', profile)
196
197 wipe(usedSlots) 199 wipe(usedSlots)
198 for slot, configTable in pairs(profile.buttons) do 200 for slot, configTable in pairs(profile.buttons) do
199 201
200 202 -- convert old style table
201 if #configTable >= 1 then 203 if #configTable >= 1 then
202 local command, name, icon, actionType, actionID, macroName, macroText, spellbookSlot, spellbookType = unpack(configTable) 204 local command, name, icon, actionType, actionID, macroName, macroText, spellbookSlot, spellbookType = unpack(configTable)
203 205
204 cprint('|CFFFF4400Fixing pad entry', slot, command, name) 206 cprint('|CFFFF4400Fixing pad entry', slot, command, name)
205 local assignedKeys = {GetBindingKey(command)} 207 local assignedKeys = {GetBindingKey(command)}
219 iconPath = icon, 221 iconPath = icon,
220 spellbookSlot = spellbookSlot, 222 spellbookSlot = spellbookSlot,
221 spellbookType = spellbookType, 223 spellbookType = spellbookType,
222 assignedKeys = assignedKeys 224 assignedKeys = assignedKeys
223 } 225 }
226
227 local dynamic = kb.DynamicSpells[name]
228 if dynamic then
229 configTable.dynamicType = dynamic.dynamicType
230 configTable.dynamicIndex = dynamic.dynamicIndex
231 configTable.dynamicSubIndex = dynamic.dynamicSubIndex
232 configTable.dynamicID = dynamic.dynamicID
233 if configTable.dynamicType == 'talent' then
234 profile.talents[name] = configTable
235 end
236 end
237
238
224 kb.currentProfile.buttons[slot] = configTable 239 kb.currentProfile.buttons[slot] = configTable
225 end 240 end
226 if not configTable.actionID then 241 if not configTable.actionID then
227 configTable.actionID = configTable.actionName 242 configTable.actionID = configTable.actionName
228 end 243 end
231 configTable.iconPath = GetSpellTexture(configTable.actionName) 246 configTable.iconPath = GetSpellTexture(configTable.actionName)
232 end 247 end
233 248
234 usedSlots[configTable.actionName or configTable.actionID] = true 249 usedSlots[configTable.actionName or configTable.actionID] = true
235 usedSlots[configTable.command] = true 250 usedSlots[configTable.command] = true
236 251 end
237 if kb.LoadBinding(configTable) then 252
238 configTable.isAvailable = true 253
239 end 254 -- clean up legacy data
240 end 255 for spellName, talentInfo in pairs(profile.talents) do
241 256 if not usedSlots[spellName] then
257 cprint('|cFFFF4400Unslotted talent', spellName)
258 profile.talents[spellName] = nil
259 end
260 end
261 for command in pairs(profile.bound) do
262 if not usedSlots[command] then
263 cprint('|cFFFF4400Unslotted bound entry', command)
264 profile.bound[command] = nil
265 profile.commands[command] = nil
266 end
267 end
268 for command in pairs(profile.commands) do
269 if not usedSlots[command] then
270 cprint('|cFFFF4400Unslotted command entry', command)
271 profile.commands[command] = nil
272 end
273 end
274 end
275
276 kb.ApplyBindings = function (profile)
277 cprint('|cFF0088FFApplyBindings()')
278 --cprint('binding profile', profile)
279
280 local version = profile.versionID or 0
281 if version < 310 then
282 kb.UpgradeProfile(profile)
283 end
284
285 -- do flat bindings to start
242 for key, command in pairs(profile.bindings) do 286 for key, command in pairs(profile.bindings) do
243 command = command:gsub('KeyBinder', 'SkeletonKey') 287 command = command:gsub('KeyBinder', 'SkeletonKey')
244 profile.bindings[key] = command 288 profile.bindings[key] = command
245 cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command) 289 cprint('|cFF00FFFF'.. key .. '|r to|cFF00FF00', command)
246 SetBinding(key, command) 290 SetBinding(key, command)
247
248 if commandActions[command] and not tContains(commandActions[command], key) then 291 if commandActions[command] and not tContains(commandActions[command], key) then
249 tinsert(commandActions[command], key) 292 tinsert(commandActions[command], key)
250 end 293 end
251 end 294 end
252 295
253 for spellName, talentInfo in pairs(profile.talents) do 296 -- then buttons
254 if not usedSlots[spellName] then 297 for slot, configTable in pairs(profile.buttons) do
255 cprint('|cFFFF4400Unslotted talent', spellName) 298 -- convert old style table
256 profile.talents[spellName] = nil 299 if kb.LoadBinding(configTable) then
257 end 300 local talent = profile.talents[configTable.actionName]
258 end 301 if talent then
259 for command in pairs(profile.bound) do 302 configTable.assignedKeys = talent.assignedKeys
260 if not usedSlots[command] then 303 end
261 cprint('|cFFFF4400Unslotted bound entry', command) 304 if not configTable.assignedKeys then
262 profile.bound[command] = nil 305 configTable.assignedKeys = {GetBindingKey(configTable.command) }
263 profile.commands[command] = nil 306 end
264 end 307 configTable.isAvailable = true
265 end 308 if configTable.dynamicType then
266 for command in pairs(profile.commands) do 309 kb:print(table.concat(configTable.assignedKeys, ', ') .. ' bound to '.. configTable.actionName)
267 if not usedSlots[command] then 310 end
268 cprint('|cFFFF4400Unslotted command entry', command) 311
269 profile.commands[command] = nil 312 end
270 end 313 end
271 end
272
273 end 314 end
274 315
275 kb.ApplyAllBindings =function () 316 kb.ApplyAllBindings =function ()
276 cprint('|cFF0088FFApplyAllBindings()') 317 cprint('|cFF0088FFApplyAllBindings()')
277 wipe(kb.TalentBindings) 318 wipe(kb.TalentBindings)
330 talentInfo.dynamicID = talentID 371 talentInfo.dynamicID = talentID
331 talentInfo.dynamicIndex = row 372 talentInfo.dynamicIndex = row
332 talentInfo.dynamicSubIndex = col 373 talentInfo.dynamicSubIndex = col
333 talentInfo.actionID = spellID 374 talentInfo.actionID = spellID
334 talentInfo.isAvailable = selected 375 talentInfo.isAvailable = selected
335 kb.TalentCache[spellID] = talentInfo
336 kb.TalentCache[talentName] = talentInfo
337 kb.DynamicSpells[spellID] = talentInfo 376 kb.DynamicSpells[spellID] = talentInfo
338 kb.DynamicSpells[talentName] = talentInfo 377 kb.DynamicSpells[talentName] = talentInfo
339 end 378 end
340 379
341 --print('Talent ', row, col, spellID, talentName) 380 --print('Talent ', row, col, spellID, talentName)
351 talentInfo.actionName = name 390 talentInfo.actionName = name
352 talentInfo.dynamicType = 'talent' 391 talentInfo.dynamicType = 'talent'
353 talentInfo.dynamicID = id 392 talentInfo.dynamicID = id
354 talentInfo.actionID = spellID 393 talentInfo.actionID = spellID
355 talentInfo.isAvailable = selected 394 talentInfo.isAvailable = selected
356 kb.TalentCache[spellID] = talentInfo
357 kb.TalentCache[name] = talentInfo
358 kb.DynamicSpells[spellID] = talentInfo 395 kb.DynamicSpells[spellID] = talentInfo
359 kb.DynamicSpells[name] = talentInfo 396 kb.DynamicSpells[name] = talentInfo
360 end 397 end
361 end 398 end
362 end 399 end