Fix up importing macros

This commit is contained in:
2025-01-05 15:19:37 +01:00
parent ac32b1fd75
commit 1e014b2d5b

View File

@@ -347,10 +347,12 @@ importExportFrameTextBox:SetScript("OnEscapePressed", function(self)
importExportFrame:Hide() importExportFrame:Hide()
if importingSet then if importingSet then
local lines = {strsplit("\n", self:GetText())} local lines = {strsplit("\n", self:GetText())}
print("Importing set " .. importingSet) for _, line in ipairs(lines) do
print(self:GetText()) line = strtrim(line)
DumpTable(lines) if line ~= "" then
-- ImportSet(importingSet, self:GetText()) ImportSet(importingSet, line)
end
end
importingSet = nil importingSet = nil
end end
end) end)
@@ -379,18 +381,19 @@ function ExportSet(setName)
end end
end end
local exported = {table.concat(stringified, "ž")} local export = {}
for name, macro in pairs(macros) do for name, macro in pairs(macros) do
local content = B64.Encode(macro) 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 end
local str = table.concat(exported, "\n") export[#export + 1] = table.concat(stringified, "ž")
local str = table.concat(export, "\n")
importExportFrame:Show() importExportFrame:Show()
importExportFrameTextBox:SetText(str) importExportFrameTextBox:SetText(str)
importExportFrameTextBox:SetFocus() importExportFrameTextBox:SetFocus()
end end
local function ParseAction(action) function ParseAction(action)
if not action or action == "" then if not action or action == "" then
return nil return nil
end end
@@ -425,35 +428,39 @@ local function ParseAction(action)
} }
end 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) function ImportSet(setName, str)
if not setName or setName == "" then if not setName or setName == "" then
print("Must provide a valid set name") print("Must provide a valid set name")
return return
end end
if string.find(setName, "^Mž") then if string.find(str, "^Mž") then
setName = strtrim(setName) ImportMacro(str)
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))
return return
end end
local set = ActionBarSaverReloaded.sets[setName] or {} local set = ActionBarSaverReloaded.sets[setName] or {}
@@ -480,6 +487,17 @@ function ImportSet(setName, str)
print(string.format("Imported set '%s'", setName)) print(string.format("Imported set '%s'", setName))
end 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() function PrintUsage()
print("ABS Slash commands") print("ABS Slash commands")
print("/abs save <set> - Saves your current action bar setup under the given <set>") print("/abs save <set> - Saves your current action bar setup under the given <set>")
@@ -489,8 +507,8 @@ function PrintUsage()
print("/abs alias <spellID> <aliasID> - Adds an alias with <aliasID> to <spellID>") print("/abs alias <spellID> <aliasID> - Adds an alias with <aliasID> to <spellID>")
print("/abs unalias <spellID> - Removes all aliases associated with <spellID>") print("/abs unalias <spellID> - Removes all aliases associated with <spellID>")
print("/abs aliases - List all spell aliases") print("/abs aliases - List all spell aliases")
print("/abs export <set> - Export set") print("/abs export <set> - Brings up a dialog to export the given <set>")
print("/abs import <set> <str> - Import set from exported string") print("/abs import <set> - Brings up a dialog to import the given <set>")
end end
SlashCmdList["ABS"] = function(argv) SlashCmdList["ABS"] = function(argv)
@@ -522,7 +540,7 @@ SlashCmdList["ABS"] = function(argv)
ExportSet(args[2]) ExportSet(args[2])
end end
if cmd == "import" then if cmd == "import" then
ImportSet(args[2], args[3]) ImportSetDialogue(args[2])
end end
if cmd == "" or not cmd then if cmd == "" or not cmd then