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,33 +174,36 @@ 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
---@cast actionButton {type: string, id: string}
AddWarning(messages, actionButton.id, duplicates[actionButton.id])
end
if IsMacro(actionButton) and duplicates[actionButton.id] then local succeeded, restoredID = RestoreActionButton(i, actionButton)
---@cast actionButton {type: string, id: string} if not succeeded or not restoredID then
AddWarning(messages, actionButton.id, duplicates[actionButton.id]) table.insert(
end messages,
string.format(
local succeeded, restoredID = RestoreActionButton(i, actionButton) "Error: Unable to restore %s with id [%s] to slot %d",
if not succeeded or not restoredID then actionButton.type,
table.insert( actionButton.id or "",
messages, i
string.format( )
"Error: Unable to restore %s with id [%s] to slot %d",
actionButton.type,
actionButton.id or "",
i
) )
) elseif actionButton and restoredID ~= actionButton.id then
elseif actionButton and restoredID ~= actionButton.id then table.insert(
table.insert( messages,
messages, string.format(
string.format( "Info: Restored spell %d (%s) in place of spell %d",
"Info: Restored spell %d (%s) in place of spell %d", restoredID,
restoredID, GetSpellInfo(restoredID),
GetSpellInfo(restoredID), actionButton.id
actionButton.id )
) )
) end
else
ClearActionButton(i)
end end
end end
@@ -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