From 1e014b2d5bfb69dca8279ce9a17200beba42f2c6 Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sun, 5 Jan 2025 15:19:37 +0100 Subject: [PATCH] Fix up importing macros --- Actions.lua | 86 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 34 deletions(-) diff --git a/Actions.lua b/Actions.lua index 2cf368f..1c7aaba 100644 --- a/Actions.lua +++ b/Actions.lua @@ -347,10 +347,12 @@ importExportFrameTextBox:SetScript("OnEscapePressed", function(self) importExportFrame:Hide() if importingSet then local lines = {strsplit("\n", self:GetText())} - print("Importing set " .. importingSet) - print(self:GetText()) - DumpTable(lines) - -- ImportSet(importingSet, self:GetText()) + for _, line in ipairs(lines) do + line = strtrim(line) + if line ~= "" then + ImportSet(importingSet, line) + end + end importingSet = nil end end) @@ -379,18 +381,19 @@ function ExportSet(setName) end end - local exported = {table.concat(stringified, "ž")} + local export = {} for name, macro in pairs(macros) do local content = B64.Encode(macro) - exported[#exported + 1] = string.format("Mž%sž%dž%s", name, idx, content) + export[#export + 1] = string.format("Mž%sž%s", name, content) end - local str = table.concat(exported, "\n") + export[#export + 1] = table.concat(stringified, "ž") + local str = table.concat(export, "\n") importExportFrame:Show() importExportFrameTextBox:SetText(str) importExportFrameTextBox:SetFocus() end -local function ParseAction(action) +function ParseAction(action) if not action or action == "" then return nil end @@ -425,35 +428,39 @@ local function ParseAction(action) } end -local macroParts = {} +function ImportMacro(importString) + if not importString or importString == "" then + print("Must provide a valid macro string") + return + end + importString = strtrim(importString) + local name, content = string.match(importString, "^Mž([^ž]+)ž([^ž]+)") + if not name or not content then + print("Error: Invalid macro part format") + return + end + content = strtrim(content) + name = strtrim(name) + + local reconstructed = B64.Decode(content) + local macroIdx = GetMacroIndexByName(name) + if macroIdx == 0 then + macroIdx = CreateMacro(name, "Inv_misc_questionmark", "") + macroIdx = GetMacroIndexByName(name) + end + EditMacro(macroIdx, name, nil, reconstructed) + print(string.format("Imported macro '%s' with index %d and content '%s'", name, macroIdx, reconstructed)) + return +end + function ImportSet(setName, str) if not setName or setName == "" then print("Must provide a valid set name") return end - if string.find(setName, "^Mž") then - setName = strtrim(setName) - local name, index, content = string.match(setName, "^Mž([^ž]+)ž([^ž]+)ž([^ž]+)") - if not name or not index or not content then - print("Error: Invalid macro part format") - return - end - content = strtrim(content) - name = strtrim(name) - index = tonumber(index) - macroParts[name] = macroParts[name] or {} - macroParts[name][index] = content - - local reconstructed = table.concat(macroParts[name], "") - reconstructed = B64.Decode(reconstructed) - - local macroIdx = GetMacroIndexByName(name) - if macroIdx == 0 then - macroIdx = CreateMacro(name, "Interface\\Icons\\INV_Misc_Note_01", "") - end - EditMacro(macroIdx, name, nil, reconstructed) - print(string.format("Imported macro '%s' with index %d and content '%s'", name, macroIdx, reconstructed)) + if string.find(str, "^Mž") then + ImportMacro(str) return end local set = ActionBarSaverReloaded.sets[setName] or {} @@ -480,6 +487,17 @@ function ImportSet(setName, str) print(string.format("Imported set '%s'", setName)) end +function ImportSetDialogue(setName) + if not setName or setName == "" then + print("Must provide a valid set name") + return + end + importingSet = setName + importExportFrameTextBox:SetText("") + importExportFrame:Show() + importExportFrameTextBox:SetFocus() +end + function PrintUsage() print("ABS Slash commands") print("/abs save - Saves your current action bar setup under the given ") @@ -489,8 +507,8 @@ function PrintUsage() print("/abs alias - Adds an alias with to ") print("/abs unalias - Removes all aliases associated with ") print("/abs aliases - List all spell aliases") - print("/abs export - Export set") - print("/abs import - Import set from exported string") + print("/abs export - Brings up a dialog to export the given ") + print("/abs import - Brings up a dialog to import the given ") end SlashCmdList["ABS"] = function(argv) @@ -522,7 +540,7 @@ SlashCmdList["ABS"] = function(argv) ExportSet(args[2]) end if cmd == "import" then - ImportSet(args[2], args[3]) + ImportSetDialogue(args[2]) end if cmd == "" or not cmd then