annotate Import.lua @ 93:f9df7cd7bfd6 tip

revert pet spell subText collation remove an empty script handler
author Nenue
date Tue, 04 Sep 2018 23:00:21 -0400
parents 131d9190db6b
children
rev   line source
Nenue@70 1 -- KrakTool
Nenue@70 2 -- Import.lua
Nenue@70 3 -- Created: 7/10/2016 6:20 AM
Nenue@70 4 -- %file-revision%
Nenue@70 5 -- Tools for first-time setup and migration from other addons.
Nenue@70 6
Nenue@70 7 local kb = LibStub("LibKraken").register(KeyBinder, 'Import')
Nenue@70 8 local print = DEVIAN_WORKSPACE and function(...) print('kbi', ...) end or function() end
Nenue@70 9
Nenue@70 10
Nenue@70 11 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544
Nenue@70 12 local SUMMON_RANDOM_FAVORITE_MOUNT_SPELLNAME = "Summon Random Favorite Mount"
Nenue@70 13 local results = {}
Nenue@70 14 local importSet = setmetatable({}, {__tostring = function() return 'Global Bindings' end})
Nenue@70 15 kb.importTypes = {}
Nenue@70 16
Nenue@70 17 local lineNumber = 0
Nenue@70 18 local usedBinds, usedKeys = {}, {}
Nenue@70 19 local profileName = ''
Nenue@70 20 local specProfile
Nenue@70 21 local msg = function(...) return KeyBinderImportLog:AddMessage(...) end
Nenue@70 22
Nenue@70 23 --- Core interfaces
Nenue@70 24 kb.ImportScan = function()
Nenue@70 25 -- hang onto this
Nenue@70 26 SUMMON_RANDOM_FAVORITE_MOUNT_SPELLNAME = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL)
Nenue@70 27
Nenue@70 28 local hasAnyData = false
Nenue@70 29 for addon, module in pairs(kb.importTypes) do
Nenue@70 30 if IsAddOnLoaded(addon) then
Nenue@70 31 local hasData = module.GetChanges(importSet)
Nenue@70 32 if hasData then
Nenue@70 33 kb:print("|cFFFFFF00"..addon.." is currently enabled.")
Nenue@70 34 end
Nenue@70 35
Nenue@70 36 hasAnyData = (hasData or hasAnyData)
Nenue@70 37 end
Nenue@70 38 end
Nenue@70 39 if hasAnyData then
Nenue@70 40 kb:print("You can use /skb import |cFF00FF00<AddOn Name>|r to attempt to copy settings related to this character. This will also disable that AddOn.")
Nenue@70 41 end
Nenue@70 42
Nenue@70 43
Nenue@70 44 kb.ui()
Nenue@70 45 --KeyBinderImportLog:Show()
Nenue@70 46
Nenue@70 47 return importSet
Nenue@70 48 end
Nenue@70 49
Nenue@70 50 kb.ImportCommmit = function(self, text)
Nenue@70 51 kb.db.buttons = importSet.buttons
Nenue@70 52 kb.db.bound = importSet.bound
Nenue@70 53 kb.db.commands = importSet.commands
Nenue@70 54 kb.db.bindings = importSet.bindings
Nenue@70 55 kb.db.macros = importSet.macros
Nenue@70 56 kb.db[profileName] = importSet[profileName]
Nenue@70 57 kb.profile(profileName)
Nenue@70 58
Nenue@70 59
Nenue@70 60 kb:ApplyAllBindings()
Nenue@70 61 kb.ui()
Nenue@70 62 kb:print('Imported settings applied! Note that you will need to change active specializations and run the command again to create their respective Char+Spec profiles.')
Nenue@70 63 end
Nenue@70 64
Nenue@70 65 --- Key Scan
Nenue@70 66 kb.importTypes.KeyBinder = {}
Nenue@70 67 kb.importTypes.BindPad = {}
Nenue@70 68 local kbi = kb.importTypes.KeyBinder
Nenue@70 69 local bp = kb.importTypes.BindPad
Nenue@70 70
Nenue@70 71 --- BindPad import process
Nenue@70 72 -- because bindpad doesn't store class info, it is not possible to discern the identity of primary/secondary
Nenue@70 73
Nenue@70 74 local GetBindPadSlot = function(profile, slot, data)
Nenue@70 75 local actionType = data.type:lower()
Nenue@70 76 local command = data.action:gsub('CLICK BindPadKey:%s*', '')
Nenue@70 77 local clickAction = command:match('BindPadMacro:%s*(.+)%s*$')
Nenue@70 78 local macroName, macroText
Nenue@70 79 if clickAction then
Nenue@70 80 local clickType = 'spell'
Nenue@70 81 if clickAction == SUMMON_RANDOM_FAVORITE_MOUNT_SPELLNAME then
Nenue@70 82 clickType = 'mount'
Nenue@70 83 clickAction = 0
Nenue@70 84 else
Nenue@70 85 clickType = 'spell'
Nenue@70 86 end
Nenue@70 87
Nenue@70 88 macroName, macroText, command = kb.RegisterAction(nil, clickType, clickAction)
Nenue@70 89 profile.macros[macroName] = {macroText, command}
Nenue@70 90 end
Nenue@70 91 print('[|cFF00FF00'.. data.type .. '|r] |cFFFF00FF' .. data.action .. '|r :: "' .. tostring(clickAction) .. '"')
Nenue@70 92
Nenue@70 93 results[actionType] = (results[actionType] or 0) + 1
Nenue@70 94 profile.buttons[slot] = {
Nenue@70 95 command,
Nenue@70 96 command:gsub(data.type, ''),
Nenue@70 97 data.texture
Nenue@70 98 }
Nenue@70 99 profile.commands[command] = slot
Nenue@70 100
Nenue@70 101 if usedBinds[data.action] then
Nenue@70 102 local key1, key2 = unpack(usedBinds[data.action])
Nenue@70 103 print('adding keybind |cFF00FFFF' .. command .. ' |cFF00FF00' .. (key1) .. ' |cFF00FF00' .. (key2 or ''))
Nenue@70 104 profile.bindings[key1] = command
Nenue@70 105
Nenue@70 106 if key2 then
Nenue@70 107 profile.bindings[key2] = command
Nenue@70 108 end
Nenue@70 109
Nenue@70 110 usedBinds[data.action] = nil
Nenue@70 111
Nenue@70 112 msg('|cFF00FFFF'..tostring(profile)..'|r '..slot..': ' .. '|cFF00FFFF' .. command .. '|r |cFF00FF00' .. (key1 or '') .. (key2 and ('|r, |cFF00FF00key2') or '') )
Nenue@70 113 else
Nenue@70 114 print('|cFFFF4400no binding|r ' .. command)
Nenue@70 115 end
Nenue@70 116 end
Nenue@70 117
Nenue@70 118 local GetBindPadProfile = function(profile, bp)
Nenue@70 119 local bpnames = {'CharacterSpecificTab1', 'CharacterSpecificTab2', 'CharacterSpecificTab3'} -- won't need this ever again, let it fall into gc
Nenue@70 120
Nenue@70 121 -- resolve spec ID
Nenue@70 122 local specID = GetSpecialization()
Nenue@70 123 local globalID = GetSpecializationInfo(GetSpecialization())
Nenue@70 124 local activeProfile
Nenue@70 125
Nenue@70 126 -- setup string coercions for debugging
Nenue@70 127 setmetatable(profile,{__tostring = function(t) return 'Character' end})
Nenue@70 128 if GetNumSpecGroups() > 1 then
Nenue@70 129 local activeGroup = GetActiveSpecGroup()
Nenue@70 130 activeProfile = bp.profileForTalentGroup[activeGroup]
Nenue@70 131 profile[specID] = kb.InitProfile(profile[specID] or {})
Nenue@70 132 specProfile = profile[specID]
Nenue@70 133 setmetatable(specProfile,{__tostring = function(t) return 'Spec #'..specID end})
Nenue@70 134 end
Nenue@70 135
Nenue@70 136 print('-')
Nenue@70 137
Nenue@70 138 results.spell = 0
Nenue@70 139 results.macro = 0
Nenue@70 140 results.click = 0
Nenue@70 141 results.item = 0
Nenue@70 142
Nenue@70 143 table.wipe(usedBinds) -- [action] = {key1, key2}
Nenue@70 144 table.wipe(usedKeys) -- [key] = "action"
Nenue@70 145 for id, bpProfile in ipairs(bp) do
Nenue@70 146
Nenue@70 147 local slots = 0
Nenue@70 148
Nenue@70 149 if bpProfile.AllKeyBindings then
Nenue@70 150 for binding, command in pairs(bpProfile.AllKeyBindings) do
Nenue@70 151 -- each binding value
Nenue@70 152 if not usedKeys[binding] then
Nenue@70 153 usedKeys[binding] = command
Nenue@70 154 end
Nenue@70 155
Nenue@70 156 usedBinds[command] = usedBinds[command] or {}
Nenue@70 157 tinsert(usedBinds[command], binding)
Nenue@70 158 end
Nenue@70 159 end
Nenue@70 160
Nenue@70 161
Nenue@70 162
Nenue@70 163 for i, name in ipairs(bpnames) do
Nenue@70 164 -- each tab
Nenue@70 165 if bpProfile[name] then
Nenue@70 166 for slot, data in pairs(bpProfile[name]) do
Nenue@70 167 if type(data) == 'table' then
Nenue@70 168 slots = slots + 1
Nenue@70 169
Nenue@70 170
Nenue@70 171 local profile = (id == activeProfile) and specProfile or profile
Nenue@70 172 lineNumber = lineNumber + 1
Nenue@70 173 GetBindPadSlot(profile, slot, data)
Nenue@70 174
Nenue@70 175 else
Nenue@70 176 --print(type(data), slot, data)
Nenue@70 177 end
Nenue@70 178 end
Nenue@70 179 end
Nenue@70 180 end
Nenue@70 181 end
Nenue@70 182 end
Nenue@70 183
Nenue@70 184
Nenue@70 185 bp.GetChanges = function(importSet)
Nenue@70 186 -- ensure that subtables are there
Nenue@70 187 kb.InitProfile(importSet)
Nenue@70 188 if BindPadVars then
Nenue@70 189 local globalSlots = 0
Nenue@70 190 for k,v in pairs(BindPadVars) do
Nenue@70 191 --print(k, type(k))
Nenue@70 192 if type(k) == 'string' then
Nenue@70 193 local realm, name = k:match("^PROFILE_([%S]+)_(%S+)$")
Nenue@70 194 if realm == kb.playerRealm and name == kb.playerName then
Nenue@70 195 profileName = realm .. '_' .. name
Nenue@70 196 msg('Found character profile: |cFFFFFF00'.. tostring(realm) .. '|r-|cFF00FFFF'..tostring(name)..'|r')
Nenue@70 197 importSet[profileName] = kb.InitProfile({})
Nenue@70 198 importSet[profileName].imported = true
Nenue@70 199 GetBindPadProfile(importSet[profileName], v)
Nenue@70 200 end
Nenue@70 201 elseif type(k) == 'number' and type(v) == 'table' then
Nenue@70 202 globalSlots = globalSlots + 1
Nenue@70 203 GetBindPadSlot(importSet, globalSlots, v)
Nenue@70 204 end
Nenue@70 205 end
Nenue@70 206 end
Nenue@70 207
Nenue@70 208 return results
Nenue@70 209 end