Fix import and export

This commit is contained in:
2025-05-06 23:00:44 +02:00
parent 0638896bc3
commit f5b9b973e3

View File

@@ -66,6 +66,15 @@ local function RestoreActionButton(index, actionButton)
return false return false
end end
---@param index number
---@return boolean
local function ClearActionButton(index)
if not index then return false end
PickupAction(index)
ClearCursor()
return true
end
---@param actionButton {type: string, id: number|string} ---@param actionButton {type: string, id: number|string}
---@return boolean ---@return boolean
local function IsMacro(actionButton) return actionButton and actionButton.type == "macro" end local function IsMacro(actionButton) return actionButton and actionButton.type == "macro" end
@@ -165,7 +174,7 @@ function RestoreActionbarSet(setName)
for i = 1, MAX_ACTION_BUTTONS do for i = 1, MAX_ACTION_BUTTONS do
local actionButton = set[i] local actionButton = set[i]
if actionButton then
if IsMacro(actionButton) and duplicates[actionButton.id] then if IsMacro(actionButton) and duplicates[actionButton.id] then
---@cast actionButton {type: string, id: string} ---@cast actionButton {type: string, id: string}
AddWarning(messages, actionButton.id, duplicates[actionButton.id]) AddWarning(messages, actionButton.id, duplicates[actionButton.id])
@@ -193,6 +202,9 @@ function RestoreActionbarSet(setName)
) )
) )
end end
else
ClearActionButton(i)
end
end end
print(string.format("Restored set '%s'", setName)) print(string.format("Restored set '%s'", setName))
@@ -380,6 +392,10 @@ function ExportActionbarSet(setName)
importExportFrameTextBox:SetFocus() importExportFrameTextBox:SetFocus()
end end
---@param action {slot: number, id: number|string, type: string}
---@return string
function FormatAction(action) return string.format("slot: %d, id: %s, type: %s", action.slot, action.id, action.type) end
---@param action string ---@param action string
---@return {slot: number, id: number|string, type: string} ---@return {slot: number, id: number|string, type: string}
function ParseAction(action) function ParseAction(action)
@@ -393,12 +409,12 @@ function ParseAction(action)
action = strtrim(action) action = strtrim(action)
local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)") local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)")
if not typeChar then if not typeChar then
print(string.format("Unknown action type '%s'", tostring(typeChar))) print(string.format("Unknown action type '%s' for action '%s'", tostring(typeChar), FormatAction(ret)))
return ret return ret
end end
local type = inverseTypeMap[typeChar] local type = inverseTypeMap[typeChar]
if not type then if not type then
print(string.format("Unknown action type '%s'", tostring(typeChar))) print(string.format("Unknown action type '%s' for action '%s'", tostring(typeChar), FormatAction(ret)))
return ret return ret
end end
@@ -406,12 +422,12 @@ function ParseAction(action)
id = tonumber(id) id = tonumber(id)
if not slot then if not slot then
print(string.format("Unknown slot '%s'", tostring(slot))) print(string.format("Unknown slot '%s' for action '%s'", tostring(slot), FormatAction(ret)))
return ret return ret
end end
if not id then if not id then
print(string.format("Unknown id '%s'", tostring(id))) print(string.format("Unknown id '%s' for action '%s'", tostring(id), FormatAction(ret)))
return ret return ret
end end