diff --git a/Actions.lua b/Actions.lua index c26f1f7..f55e1c7 100644 --- a/Actions.lua +++ b/Actions.lua @@ -66,6 +66,15 @@ local function RestoreActionButton(index, actionButton) return false 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} ---@return boolean 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 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 - ---@cast actionButton {type: string, id: string} - AddWarning(messages, actionButton.id, duplicates[actionButton.id]) - end - - local succeeded, restoredID = RestoreActionButton(i, actionButton) - if not succeeded or not restoredID then - table.insert( - messages, - string.format( - "Error: Unable to restore %s with id [%s] to slot %d", - actionButton.type, - actionButton.id or "", - i + local succeeded, restoredID = RestoreActionButton(i, actionButton) + if not succeeded or not restoredID then + table.insert( + messages, + 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 - table.insert( - messages, - string.format( - "Info: Restored spell %d (%s) in place of spell %d", - restoredID, - GetSpellInfo(restoredID), - actionButton.id + elseif actionButton and restoredID ~= actionButton.id then + table.insert( + messages, + string.format( + "Info: Restored spell %d (%s) in place of spell %d", + restoredID, + GetSpellInfo(restoredID), + actionButton.id + ) ) - ) + end + else + ClearActionButton(i) end end @@ -380,6 +392,10 @@ function ExportActionbarSet(setName) importExportFrameTextBox:SetFocus() 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 ---@return {slot: number, id: number|string, type: string} function ParseAction(action) @@ -393,12 +409,12 @@ function ParseAction(action) action = strtrim(action) local slot, id, typeChar = string.match(action, "([^\\]+)\\([^\\]+)\\([^\\]+)") 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 end local type = inverseTypeMap[typeChar] 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 end @@ -406,12 +422,12 @@ function ParseAction(action) id = tonumber(id) 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 end 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 end