Mercurial > wow > skeletonkey
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SkeletonKey/Import.lua Thu Jul 28 16:45:56 2016 -0400 @@ -0,0 +1,209 @@ +-- KrakTool +-- Import.lua +-- Created: 7/10/2016 6:20 AM +-- %file-revision% +-- Tools for first-time setup and migration from other addons. + +local kb = LibStub("LibKraken").register(KeyBinder) +local print = DEVIAN_WORKSPACE and function(...) print('kbi', ...) end or function() end + + +local SUMMON_RANDOM_FAVORITE_MOUNT_SPELL = 150544 +local SUMMON_RANDOM_FAVORITE_MOUNT_SPELLNAME = "Summon Random Favorite Mount" +local results = {} +local importSet = setmetatable({}, {__tostring = function() return 'Global Bindings' end}) +kb.importTypes = {} + +local lineNumber = 0 +local usedBinds, usedKeys = {}, {} +local profileName = '' +local specProfile +local msg = function(...) return KeyBinderImportLog:AddMessage(...) end + +--- Core interfaces +kb.ImportScan = function() + -- hang onto this + SUMMON_RANDOM_FAVORITE_MOUNT_SPELLNAME = GetSpellInfo(SUMMON_RANDOM_FAVORITE_MOUNT_SPELL) + + local hasAnyData = false + for addon, module in pairs(kb.importTypes) do + if IsAddOnLoaded(addon) then + local hasData = module.GetChanges(importSet) + if hasData then + kb:print("|cFFFFFF00"..addon.." is currently enabled.") + end + + hasAnyData = (hasData or hasAnyData) + end + end + if hasAnyData then + 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.") + end + + + kb.ui() + --KeyBinderImportLog:Show() + + return importSet +end + +kb.ImportCommmit = function(self, text) + kb.db.buttons = importSet.buttons + kb.db.bound = importSet.bound + kb.db.commands = importSet.commands + kb.db.bindings = importSet.bindings + kb.db.macros = importSet.macros + kb.db[profileName] = importSet[profileName] + kb.profile(profileName) + + + kb:ApplyAllBindings() + kb.ui() + 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.') +end + +--- Key Scan +kb.importTypes.KeyBinder = {} +kb.importTypes.BindPad = {} +local kbi = kb.importTypes.KeyBinder +local bp = kb.importTypes.BindPad + +--- BindPad import process +-- because bindpad doesn't store class info, it is not possible to discern the identity of primary/secondary + +local GetBindPadSlot = function(profile, slot, data) + local actionType = data.type:lower() + local command = data.action:gsub('CLICK BindPadKey:%s*', '') + local clickAction = command:match('BindPadMacro:%s*(.+)%s*$') + local macroName, macroText + if clickAction then + local clickType = 'spell' + if clickAction == SUMMON_RANDOM_FAVORITE_MOUNT_SPELLNAME then + clickType = 'mount' + clickAction = 0 + else + clickType = 'spell' + end + + macroName, macroText, command = kb.RegisterAction(nil, clickType, clickAction) + profile.macros[macroName] = {macroText, command} + end + print('[|cFF00FF00'.. data.type .. '|r] |cFFFF00FF' .. data.action .. '|r :: "' .. tostring(clickAction) .. '"') + + results[actionType] = (results[actionType] or 0) + 1 + profile.buttons[slot] = { + command, + command:gsub(data.type, ''), + data.texture + } + profile.commands[command] = slot + + if usedBinds[data.action] then + local key1, key2 = unpack(usedBinds[data.action]) + print('adding keybind |cFF00FFFF' .. command .. ' |cFF00FF00' .. (key1) .. ' |cFF00FF00' .. (key2 or '')) + profile.bindings[key1] = command + + if key2 then + profile.bindings[key2] = command + end + + usedBinds[data.action] = nil + + msg('|cFF00FFFF'..tostring(profile)..'|r '..slot..': ' .. '|cFF00FFFF' .. command .. '|r |cFF00FF00' .. (key1 or '') .. (key2 and ('|r, |cFF00FF00key2') or '') ) + else + print('|cFFFF4400no binding|r ' .. command) + end +end + +local GetBindPadProfile = function(profile, bp) + local bpnames = {'CharacterSpecificTab1', 'CharacterSpecificTab2', 'CharacterSpecificTab3'} -- won't need this ever again, let it fall into gc + + -- resolve spec ID + local specID = GetSpecialization() + local globalID = GetSpecializationInfo(GetSpecialization()) + local activeProfile + + -- setup string coercions for debugging + setmetatable(profile,{__tostring = function(t) return 'Character' end}) + if GetNumSpecGroups() > 1 then + local activeGroup = GetActiveSpecGroup() + activeProfile = bp.profileForTalentGroup[activeGroup] + profile[specID] = kb.InitProfile(profile[specID] or {}) + specProfile = profile[specID] + setmetatable(specProfile,{__tostring = function(t) return 'Spec #'..specID end}) + end + + print('-') + + results.spell = 0 + results.macro = 0 + results.click = 0 + results.item = 0 + + table.wipe(usedBinds) -- [action] = {key1, key2} + table.wipe(usedKeys) -- [key] = "action" + for id, bpProfile in ipairs(bp) do + + local slots = 0 + + if bpProfile.AllKeyBindings then + for binding, command in pairs(bpProfile.AllKeyBindings) do + -- each binding value + if not usedKeys[binding] then + usedKeys[binding] = command + end + + usedBinds[command] = usedBinds[command] or {} + tinsert(usedBinds[command], binding) + end + end + + + + for i, name in ipairs(bpnames) do + -- each tab + if bpProfile[name] then + for slot, data in pairs(bpProfile[name]) do + if type(data) == 'table' then + slots = slots + 1 + + + local profile = (id == activeProfile) and specProfile or profile + lineNumber = lineNumber + 1 + GetBindPadSlot(profile, slot, data) + + else + --print(type(data), slot, data) + end + end + end + end + end +end + + +bp.GetChanges = function(importSet) + -- ensure that subtables are there + kb.InitProfile(importSet) + if BindPadVars then + local globalSlots = 0 + for k,v in pairs(BindPadVars) do + --print(k, type(k)) + if type(k) == 'string' then + local realm, name = k:match("^PROFILE_([%S]+)_(%S+)$") + if realm == kb.playerRealm and name == kb.playerName then + profileName = realm .. '_' .. name + msg('Found character profile: |cFFFFFF00'.. tostring(realm) .. '|r-|cFF00FFFF'..tostring(name)..'|r') + importSet[profileName] = kb.InitProfile({}) + importSet[profileName].imported = true + GetBindPadProfile(importSet[profileName], v) + end + elseif type(k) == 'number' and type(v) == 'table' then + globalSlots = globalSlots + 1 + GetBindPadSlot(importSet, globalSlots, v) + end + end + end + + return results +end