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()
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 <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 unalias <spellID> - Removes all aliases associated with <spellID>")
print("/abs aliases - List all spell aliases")
print("/abs export <set> - Export set")
print("/abs import <set> <str> - Import set from exported string")
print("/abs export <set> - Brings up a dialog to export the given <set>")
print("/abs import <set> - Brings up a dialog to import the given <set>")
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