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