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