From 815f23a0b5d0acee39b120c4dfb8f93d1dd37af2 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Thu, 23 May 2024 21:29:57 -0500 Subject: [PATCH] [nostalgia/studio] Make UndoCommand undo/redo return ox::Error --- .../studio/paletteeditor/paletteeditor.cpp | 49 +++++++++++-------- .../studio/paletteeditor/paletteeditor.hpp | 28 +++++------ .../commands/addsubsheetcommand.cpp | 8 +-- .../commands/addsubsheetcommand.hpp | 4 +- .../commands/cutpastecommand.cpp | 6 ++- .../commands/cutpastecommand.hpp | 4 +- .../commands/deletetilescommand.cpp | 6 ++- .../commands/deletetilescommand.hpp | 4 +- .../tilesheeteditor/commands/drawcommand.cpp | 6 ++- .../tilesheeteditor/commands/drawcommand.hpp | 4 +- .../commands/inserttilescommand.cpp | 6 ++- .../commands/inserttilescommand.hpp | 4 +- .../commands/palettechangecommand.cpp | 6 ++- .../commands/palettechangecommand.hpp | 4 +- .../commands/rmsubsheetcommand.cpp | 8 +-- .../commands/rmsubsheetcommand.hpp | 4 +- .../commands/updatesubsheetcommand.cpp | 6 ++- .../commands/updatesubsheetcommand.hpp | 4 +- .../modlib/include/studio/undocommand.hpp | 4 +- .../olympic/studio/modlib/src/undostack.cpp | 15 ++++-- 20 files changed, 106 insertions(+), 74 deletions(-) diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp index f3c57a2..6cc3d69 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.cpp @@ -14,12 +14,13 @@ int AddPageCommand::commandId() const noexcept { return static_cast(PaletteEditorCommandId::AddPage); } -void AddPageCommand::redo() noexcept { +ox::Error AddPageCommand::redo() noexcept { m_pal.pages.emplace_back(); + return {}; } -void AddPageCommand::undo() noexcept { - std::ignore = m_pal.pages.erase(static_cast(m_pal.pages.size() - 1)); +ox::Error AddPageCommand::undo() noexcept { + return m_pal.pages.erase(static_cast(m_pal.pages.size() - 1)).error; } @@ -37,13 +38,14 @@ int DuplicatePageCommand::commandId() const noexcept { return static_cast(PaletteEditorCommandId::DuplicatePage); } -void DuplicatePageCommand::redo() noexcept { +ox::Error DuplicatePageCommand::redo() noexcept { m_pal.pages.emplace(m_dstIdx, std::move(m_page)); + return {}; } -void DuplicatePageCommand::undo() noexcept { +ox::Error DuplicatePageCommand::undo() noexcept { m_page = std::move(m_pal.pages[m_dstIdx]); - std::ignore = m_pal.pages.erase(static_cast(m_dstIdx)); + return m_pal.pages.erase(static_cast(m_dstIdx)).error; } size_t DuplicatePageCommand::insertIdx() const noexcept { @@ -60,13 +62,14 @@ int RemovePageCommand::commandId() const noexcept { return static_cast(PaletteEditorCommandId::RemovePage); } -void RemovePageCommand::redo() noexcept { +ox::Error RemovePageCommand::redo() noexcept { m_page = std::move(m_pal.pages[m_idx]); - std::ignore = m_pal.pages.erase(static_cast(m_idx)); + return m_pal.pages.erase(static_cast(m_idx)).error; } -void RemovePageCommand::undo() noexcept { +ox::Error RemovePageCommand::undo() noexcept { m_pal.pages.insert(m_idx, std::move(m_page)); + return {}; } @@ -81,12 +84,13 @@ int AddColorCommand::commandId() const noexcept { return static_cast(PaletteEditorCommandId::AddColor); } -void AddColorCommand::redo() noexcept { +ox::Error AddColorCommand::redo() noexcept { m_pal->pages[m_page].insert(static_cast(m_idx), m_color); + return {}; } -void AddColorCommand::undo() noexcept { - std::ignore = m_pal->pages[m_page].erase(static_cast(m_idx)); +ox::Error AddColorCommand::undo() noexcept { + return m_pal->pages[m_page].erase(static_cast(m_idx)).error; } @@ -101,12 +105,13 @@ int RemoveColorCommand::commandId() const noexcept { return static_cast(PaletteEditorCommandId::RemoveColor); } -void RemoveColorCommand::redo() noexcept { - std::ignore = m_pal->pages[m_page].erase(static_cast(m_idx)); +ox::Error RemoveColorCommand::redo() noexcept { + return m_pal->pages[m_page].erase(static_cast(m_idx)).error; } -void RemoveColorCommand::undo() noexcept { -m_pal->pages[m_page].insert(static_cast(m_idx), m_color); +ox::Error RemoveColorCommand::undo() noexcept { + m_pal->pages[m_page].insert(static_cast(m_idx), m_color); + return {}; } @@ -141,12 +146,14 @@ int UpdateColorCommand::commandId() const noexcept { return static_cast(PaletteEditorCommandId::UpdateColor); } -void UpdateColorCommand::redo() noexcept { +ox::Error UpdateColorCommand::redo() noexcept { m_pal->pages[m_page][static_cast(m_idx)] = m_newColor; + return {}; } -void UpdateColorCommand::undo() noexcept { +ox::Error UpdateColorCommand::undo() noexcept { m_pal->pages[m_page][static_cast(m_idx)] = m_oldColor; + return {}; } @@ -161,12 +168,14 @@ int MoveColorCommand::commandId() const noexcept { return static_cast(PaletteEditorCommandId::MoveColor); } -void MoveColorCommand::redo() noexcept { +ox::Error MoveColorCommand::redo() noexcept { moveColor(static_cast(m_idx), m_offset); + return {}; } -void MoveColorCommand::undo() noexcept { +ox::Error MoveColorCommand::undo() noexcept { moveColor(static_cast(m_idx) + m_offset, -m_offset); + return {}; } void MoveColorCommand::moveColor(int idx, int offset) noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp index d56cf82..75c0115 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/paletteeditor/paletteeditor.hpp @@ -35,9 +35,9 @@ class AddPageCommand: public studio::UndoCommand { [[nodiscard]] int commandId() const noexcept final; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; }; @@ -55,9 +55,9 @@ class DuplicatePageCommand: public studio::UndoCommand { [[nodiscard]] int commandId() const noexcept final; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] size_t insertIdx() const noexcept; @@ -78,9 +78,9 @@ class RemovePageCommand: public studio::UndoCommand { [[nodiscard]] int commandId() const noexcept final; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; }; @@ -99,9 +99,9 @@ class AddColorCommand: public studio::UndoCommand { [[nodiscard]] int commandId() const noexcept override; - void redo() noexcept override; + ox::Error redo() noexcept override; - void undo() noexcept override; + ox::Error undo() noexcept override; }; @@ -120,9 +120,9 @@ class RemoveColorCommand: public studio::UndoCommand { [[nodiscard]] int commandId() const noexcept override; - void redo() noexcept override; + ox::Error redo() noexcept override; - void undo() noexcept override; + ox::Error undo() noexcept override; }; @@ -145,9 +145,9 @@ class UpdateColorCommand: public studio::UndoCommand { [[nodiscard]] int commandId() const noexcept final; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; }; @@ -167,9 +167,9 @@ class MoveColorCommand: public studio::UndoCommand { int commandId() const noexcept override; public: - void redo() noexcept override; + ox::Error redo() noexcept override; - void undo() noexcept override; + ox::Error undo() noexcept override; private: void moveColor(int idx, int offset) noexcept; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/addsubsheetcommand.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/addsubsheetcommand.cpp index c567973..a822cc7 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/addsubsheetcommand.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/addsubsheetcommand.cpp @@ -24,7 +24,7 @@ AddSubSheetCommand::AddSubSheetCommand( } } -void AddSubSheetCommand::redo() noexcept { +ox::Error AddSubSheetCommand::redo() noexcept { auto &parent = getSubSheet(m_img, m_parentIdx); if (m_addedSheets.size() < 2) { auto i = parent.subsheets.size(); @@ -35,9 +35,10 @@ void AddSubSheetCommand::redo() noexcept { parent.columns = 0; parent.subsheets.emplace_back(m_img.idIt++, "Subsheet 1", 1, 1, m_img.bpp); } + return {}; } -void AddSubSheetCommand::undo() noexcept { +ox::Error AddSubSheetCommand::undo() noexcept { auto &parent = getSubSheet(m_img, m_parentIdx); if (parent.subsheets.size() == 2) { auto s = parent.subsheets[0]; @@ -47,9 +48,10 @@ void AddSubSheetCommand::undo() noexcept { parent.subsheets.clear(); } else { for (auto idx = m_addedSheets.rbegin(); idx != m_addedSheets.rend(); ++idx) { - oxLogError(rmSubSheet(m_img, *idx)); + oxReturnError(rmSubSheet(m_img, *idx)); } } + return {}; } int AddSubSheetCommand::commandId() const noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/addsubsheetcommand.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/addsubsheetcommand.hpp index 2f1cdb9..64863fc 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/addsubsheetcommand.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/addsubsheetcommand.hpp @@ -17,9 +17,9 @@ class AddSubSheetCommand: public TileSheetCommand { public: AddSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx parentIdx) noexcept; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/cutpastecommand.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/cutpastecommand.cpp index 2158292..5f01df7 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/cutpastecommand.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/cutpastecommand.cpp @@ -41,18 +41,20 @@ CutPasteCommand::CutPasteCommand( } } -void CutPasteCommand::redo() noexcept { +ox::Error CutPasteCommand::redo() noexcept { auto &subsheet = getSubSheet(m_img, m_subSheetIdx); for (const auto &c : m_changes) { setPixel(subsheet, m_img.bpp, c.idx, static_cast(c.newPalIdx)); } + return {}; } -void CutPasteCommand::undo() noexcept { +ox::Error CutPasteCommand::undo() noexcept { auto &subsheet = getSubSheet(m_img, m_subSheetIdx); for (const auto &c : m_changes) { setPixel(subsheet, m_img.bpp, c.idx, static_cast(c.oldPalIdx)); } + return {}; } int CutPasteCommand::commandId() const noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/cutpastecommand.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/cutpastecommand.hpp index a0b1a59..0129337 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/cutpastecommand.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/cutpastecommand.hpp @@ -69,9 +69,9 @@ class CutPasteCommand: public TileSheetCommand { ox::Point const&dstEnd, TileSheetClipboard const&cb) noexcept; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.cpp index f7ca361..09e5749 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.cpp @@ -28,7 +28,7 @@ core::DeleteTilesCommand::DeleteTilesCommand( } } -void core::DeleteTilesCommand::redo() noexcept { +ox::Error core::DeleteTilesCommand::redo() noexcept { auto &s = getSubSheet(m_img, m_idx); auto &p = s.pixels; auto srcPos = m_deletePos + m_deleteSz; @@ -37,9 +37,10 @@ void core::DeleteTilesCommand::redo() noexcept { const auto dst2 = p.data() + (p.size() - m_deleteSz); ox::memmove(dst1, src, p.size() - srcPos); ox::memset(dst2, 0, m_deleteSz * sizeof(decltype(p[0]))); + return {}; } -void DeleteTilesCommand::undo() noexcept { +ox::Error DeleteTilesCommand::undo() noexcept { auto &s = getSubSheet(m_img, m_idx); auto &p = s.pixels; const auto src = p.data() + m_deletePos; @@ -48,6 +49,7 @@ void DeleteTilesCommand::undo() noexcept { const auto sz = p.size() - m_deletePos - m_deleteSz; ox::memmove(dst1, src, sz); ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); + return {}; } int DeleteTilesCommand::commandId() const noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.hpp index d692b9f..d96be81 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/deletetilescommand.hpp @@ -23,9 +23,9 @@ class DeleteTilesCommand: public TileSheetCommand { std::size_t tileIdx, std::size_t tileCnt) noexcept; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/drawcommand.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/drawcommand.cpp index 7af1bed..f99b783 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/drawcommand.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/drawcommand.cpp @@ -56,18 +56,20 @@ bool DrawCommand::append(const ox::Vector &idxList) noexcept { return out; } -void DrawCommand::redo() noexcept { +ox::Error DrawCommand::redo() noexcept { auto &subsheet = getSubSheet(m_img, m_subSheetIdx); for (const auto &c : m_changes) { setPixel(subsheet, m_img.bpp, c.idx, static_cast(m_palIdx)); } + return {}; } -void DrawCommand::undo() noexcept { +ox::Error DrawCommand::undo() noexcept { auto &subsheet = getSubSheet(m_img, m_subSheetIdx); for (const auto &c : m_changes) { setPixel(subsheet, m_img.bpp, c.idx, static_cast(c.oldPalIdx)); } + return {}; } int DrawCommand::commandId() const noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/drawcommand.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/drawcommand.hpp index 7ac8e5d..9c517fb 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/drawcommand.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/drawcommand.hpp @@ -40,9 +40,9 @@ class DrawCommand: public TileSheetCommand { bool append(const ox::Vector &idxList) noexcept; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.cpp index 3ef9618..d4a2437 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.cpp @@ -28,7 +28,7 @@ core::InsertTilesCommand::InsertTilesCommand( } } -void InsertTilesCommand::redo() noexcept { +ox::Error InsertTilesCommand::redo() noexcept { auto &s = getSubSheet(m_img, m_idx); auto &p = s.pixels; auto dstPos = m_insertPos + m_insertCnt; @@ -36,9 +36,10 @@ void InsertTilesCommand::redo() noexcept { const auto src = p.data() + m_insertPos; ox::memmove(dst, src, p.size() - dstPos); ox::memset(src, 0, m_insertCnt * sizeof(decltype(p[0]))); + return {}; } -void InsertTilesCommand::undo() noexcept { +ox::Error InsertTilesCommand::undo() noexcept { auto &s = getSubSheet(m_img, m_idx); auto &p = s.pixels; const auto srcIdx = m_insertPos + m_insertCnt; @@ -48,6 +49,7 @@ void InsertTilesCommand::undo() noexcept { const auto sz = p.size() - srcIdx; ox::memmove(dst1, src, sz); ox::memcpy(dst2, m_deletedPixels.data(), m_deletedPixels.size()); + return {}; } int InsertTilesCommand::commandId() const noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.hpp index d0ea74e..4bbb32b 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/inserttilescommand.hpp @@ -23,9 +23,9 @@ class InsertTilesCommand: public TileSheetCommand { std::size_t tileIdx, std::size_t tileCnt) noexcept; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/palettechangecommand.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/palettechangecommand.cpp index 4503eef..2138c85 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/palettechangecommand.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/palettechangecommand.cpp @@ -16,12 +16,14 @@ core::PaletteChangeCommand::PaletteChangeCommand( m_newPalette(ox::FileAddress(ox::sfmt>("uuid://{}", newPalette))) { } -void PaletteChangeCommand::redo() noexcept { +ox::Error PaletteChangeCommand::redo() noexcept { m_img.defaultPalette = m_newPalette; + return {}; } -void PaletteChangeCommand::undo() noexcept { +ox::Error PaletteChangeCommand::undo() noexcept { m_img.defaultPalette = m_oldPalette; + return {}; } int PaletteChangeCommand::commandId() const noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/palettechangecommand.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/palettechangecommand.hpp index e94a2f5..8561099 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/palettechangecommand.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/palettechangecommand.hpp @@ -21,9 +21,9 @@ class PaletteChangeCommand: public TileSheetCommand { TileSheet &img, ox::CRStringView newPalette) noexcept; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/rmsubsheetcommand.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/rmsubsheetcommand.cpp index fccfc71..4ea13a2 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/rmsubsheetcommand.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/rmsubsheetcommand.cpp @@ -13,16 +13,18 @@ core::RmSubSheetCommand::RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetId m_parentIdx.pop_back(); } -void RmSubSheetCommand::redo() noexcept { +ox::Error RmSubSheetCommand::redo() noexcept { auto &parent = getSubSheet(m_img, m_parentIdx); m_sheet = std::move(parent.subsheets[*m_idx.back().value]); - oxLogError(parent.subsheets.erase(*m_idx.back().value).error); + oxReturnError(parent.subsheets.erase(*m_idx.back().value).error); + return {}; } -void RmSubSheetCommand::undo() noexcept { +ox::Error RmSubSheetCommand::undo() noexcept { auto &parent = getSubSheet(m_img, m_parentIdx); auto const i = *m_idx.back().value; parent.subsheets.insert(i, std::move(m_sheet)); + return {}; } int RmSubSheetCommand::commandId() const noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/rmsubsheetcommand.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/rmsubsheetcommand.hpp index d27de89..f65e963 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/rmsubsheetcommand.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/rmsubsheetcommand.hpp @@ -18,9 +18,9 @@ class RmSubSheetCommand: public TileSheetCommand { public: RmSubSheetCommand(TileSheet &img, TileSheet::SubSheetIdx idx) noexcept; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/updatesubsheetcommand.cpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/updatesubsheetcommand.cpp index 4833e6f..56a4e75 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/updatesubsheetcommand.cpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/updatesubsheetcommand.cpp @@ -20,15 +20,17 @@ core::UpdateSubSheetCommand::UpdateSubSheetCommand( m_newRows(rows) { } -void UpdateSubSheetCommand::redo() noexcept { +ox::Error UpdateSubSheetCommand::redo() noexcept { auto &sheet = getSubSheet(m_img, m_idx); sheet.name = m_newName; oxLogError(resizeSubsheet(sheet, m_img.bpp, {m_newCols, m_newRows})); + return {}; } -void UpdateSubSheetCommand::undo() noexcept { +ox::Error UpdateSubSheetCommand::undo() noexcept { auto &sheet = getSubSheet(m_img, m_idx); sheet = m_sheet; + return {}; } int UpdateSubSheetCommand::commandId() const noexcept { diff --git a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/updatesubsheetcommand.hpp b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/updatesubsheetcommand.hpp index 1ba917d..fbfaebb 100644 --- a/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/updatesubsheetcommand.hpp +++ b/deps/nostalgia/src/nostalgia/modules/core/src/studio/tilesheeteditor/commands/updatesubsheetcommand.hpp @@ -25,9 +25,9 @@ class UpdateSubSheetCommand: public TileSheetCommand { int cols, int rows) noexcept; - void redo() noexcept final; + ox::Error redo() noexcept final; - void undo() noexcept final; + ox::Error undo() noexcept final; [[nodiscard]] int commandId() const noexcept final; diff --git a/deps/nostalgia/src/olympic/studio/modlib/include/studio/undocommand.hpp b/deps/nostalgia/src/olympic/studio/modlib/include/studio/undocommand.hpp index 5d57cef..93aa2a2 100644 --- a/deps/nostalgia/src/olympic/studio/modlib/include/studio/undocommand.hpp +++ b/deps/nostalgia/src/olympic/studio/modlib/include/studio/undocommand.hpp @@ -19,8 +19,8 @@ class NoChangesException: public ox::Exception { class UndoCommand { public: virtual ~UndoCommand() noexcept = default; - virtual void redo() noexcept = 0; - virtual void undo() noexcept = 0; + virtual ox::Error redo() noexcept = 0; + virtual ox::Error undo() noexcept = 0; [[nodiscard]] virtual int commandId() const noexcept = 0; virtual bool mergeWith(UndoCommand const&cmd) noexcept; diff --git a/deps/nostalgia/src/olympic/studio/modlib/src/undostack.cpp b/deps/nostalgia/src/olympic/studio/modlib/src/undostack.cpp index 26d25d6..2f0ed07 100644 --- a/deps/nostalgia/src/olympic/studio/modlib/src/undostack.cpp +++ b/deps/nostalgia/src/olympic/studio/modlib/src/undostack.cpp @@ -10,7 +10,9 @@ void UndoStack::push(ox::UPtr &&cmd) noexcept { for (auto const i = m_stackIdx; i < m_stack.size();) { std::ignore = m_stack.erase(i); } - cmd->redo(); + if (cmd->redo()) { + return; + } redoTriggered.emit(cmd.get()); changeTriggered.emit(cmd.get()); if (m_stack.empty() || !(*m_stack.back().value)->mergeWith(*cmd)) { @@ -21,8 +23,11 @@ void UndoStack::push(ox::UPtr &&cmd) noexcept { void UndoStack::redo() noexcept { if (m_stackIdx < m_stack.size()) { - auto &c = m_stack[m_stackIdx++]; - c->redo(); + auto &c = m_stack[m_stackIdx]; + if (c->redo()) { + return; + } + ++m_stackIdx; redoTriggered.emit(c.get()); changeTriggered.emit(c.get()); } @@ -31,7 +36,9 @@ void UndoStack::redo() noexcept { void UndoStack::undo() noexcept { if (m_stackIdx) { auto &c = m_stack[--m_stackIdx]; - c->undo(); + if (c->undo()) { + return; + } undoTriggered.emit(c.get()); changeTriggered.emit(c.get()); }