From c3e75bdb5524ac25c2e0ce9a3e038afc28afdc97 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 8 Jun 2025 16:26:55 -0500 Subject: [PATCH] [nostalgia/gfx/studio/tilesheet] Cleanup --- .../tilesheeteditor/tilesheeteditormodel.cpp | 48 +++++++++---------- .../tilesheeteditor/tilesheeteditormodel.hpp | 2 +- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index 89bdf296..b8c7a521 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -84,9 +84,9 @@ void TileSheetEditorModel::cut() { auto const pt1 = m_selection->a; auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight}; turbine::setClipboardObject(m_tctx, std::move(cb)); - if (auto const cmd = ox::makeCatch( + if (auto cmd = ox::make_unique_catch( CommandId::Cut, m_img, m_activeSubsSheetIdx, pt1, pt2, blankCb); cmd.ok()) { - std::ignore = pushCommand(cmd.value); + std::ignore = pushCommand(std::move(cmd.value)); } } @@ -125,9 +125,9 @@ void TileSheetEditorModel::paste() { auto const&s = activeSubSheet(); auto const pt1 = m_selection->a; auto const pt2 = ox::Point{s.columns * TileWidth, s.rows * TileHeight}; - if (auto const cmd = ox::makeCatch( + if (auto cmd = ox::make_unique_catch( CommandId::Paste, m_img, m_activeSubsSheetIdx, pt1, pt2, *cb); cmd.value) { - std::ignore = pushCommand(cmd.value); + std::ignore = pushCommand(std::move(cmd.value)); } } @@ -142,7 +142,7 @@ ox::String const &TileSheetEditorModel::palPath() const & noexcept { ox::Error TileSheetEditorModel::setPalette(ox::StringViewCR path) noexcept { OX_REQUIRE(uuid, keelCtx(m_tctx).pathToUuid.at(path)); - std::ignore = pushCommand(ox::make( + std::ignore = pushCommand(ox::make_unique( activeSubSheetIdx(), m_img, uuid->toString())); return {}; } @@ -169,7 +169,7 @@ void TileSheetEditorModel::drawCommand(ox::Point const &pt, std::size_t const pa if (m_ongoingDrawCommand) { m_updated = m_updated || m_ongoingDrawCommand->append(idx); } else if (activeSubSheet.pixels[idx] != palIdx) { - std::ignore = pushCommand(ox::make( + std::ignore = pushCommand(ox::make_unique( m_img, m_activeSubsSheetIdx, idx, static_cast(palIdx))); } } @@ -188,7 +188,7 @@ void TileSheetEditorModel::drawLineCommand(ox::Point const &pt, std::size_t cons m_ongoingDrawCommand->lineUpdate(m_lineStartPt, pt); m_updated = true; } else { - std::ignore = pushCommand(ox::make( + std::ignore = pushCommand(ox::make_unique( m_img, m_activeSubsSheetIdx, idx, static_cast(palIdx))); m_lineStartPt = pt; } @@ -203,27 +203,27 @@ void TileSheetEditorModel::endDrawCommand() noexcept { } void TileSheetEditorModel::addSubsheet(TileSheet::SubSheetIdx const &parentIdx) noexcept { - std::ignore = pushCommand(ox::make(m_img, parentIdx)); + std::ignore = pushCommand(ox::make_unique(m_img, parentIdx)); } void TileSheetEditorModel::rmSubsheet(TileSheet::SubSheetIdx const &idx) noexcept { - std::ignore = pushCommand(ox::make(m_img, idx)); + std::ignore = pushCommand(ox::make_unique(m_img, idx)); } void TileSheetEditorModel::insertTiles( TileSheet::SubSheetIdx const &idx, std::size_t const tileIdx, std::size_t const tileCnt) noexcept { - std::ignore = pushCommand(ox::make(m_img, idx, tileIdx, tileCnt)); + std::ignore = pushCommand(ox::make_unique(m_img, idx, tileIdx, tileCnt)); } void TileSheetEditorModel::deleteTiles( TileSheet::SubSheetIdx const &idx, std::size_t const tileIdx, std::size_t const tileCnt) noexcept { - std::ignore = pushCommand(ox::make(m_img, idx, tileIdx, tileCnt)); + std::ignore = pushCommand(ox::make_unique(m_img, idx, tileIdx, tileCnt)); } ox::Error TileSheetEditorModel::updateSubsheet( TileSheet::SubSheetIdx const &idx, ox::StringViewCR name, int const cols, int const rows) noexcept { - OX_REQUIRE(cmd, ox::makeCatch(m_img, idx, name, cols, rows)); - std::ignore = pushCommand(cmd); + OX_REQUIRE_M(cmd, ox::make_unique_catch(m_img, idx, name, cols, rows)); + std::ignore = pushCommand(std::move(cmd)); return {}; } @@ -255,29 +255,29 @@ void TileSheetEditorModel::fill(ox::Point const &pt, uint8_t const palIdx) noexc if (m_ongoingDrawCommand) { m_updated = m_updated || m_ongoingDrawCommand->append(idxList); } else if (getPixel(activeSubSheet, pt) != palIdx) { - std::ignore = pushCommand(ox::make(m_img, m_activeSubsSheetIdx, idxList, palIdx)); + std::ignore = pushCommand(ox::make_unique(m_img, m_activeSubsSheetIdx, idxList, palIdx)); } } ox::Error TileSheetEditorModel::rotateLeft() noexcept { - auto &ss = activeSubSheet(); + auto const &ss = activeSubSheet(); ox::Point pt1, pt2{ss.columns * TileWidth - 1, ss.rows * TileHeight - 1}; if (m_selection) { pt1 = m_selection->a; pt2 = m_selection->b; } - return pushCommand(ox::make( + return pushCommand(ox::make_unique( m_img, m_activeSubsSheetIdx, pt1, pt2, RotateCommand::Direction::Left)); } ox::Error TileSheetEditorModel::rotateRight() noexcept { - auto &ss = activeSubSheet(); + auto const &ss = activeSubSheet(); ox::Point pt1, pt2{ss.columns * TileWidth - 1, ss.rows * TileHeight - 1}; if (m_selection) { pt1 = m_selection->a; pt2 = m_selection->b; } - return pushCommand(ox::make( + return pushCommand(ox::make_unique( m_img, m_activeSubsSheetIdx, pt1, pt2, RotateCommand::Direction::Right)); } @@ -365,7 +365,7 @@ ox::Error TileSheetEditorModel::flipX() noexcept { a = m_selection->a; b = m_selection->b; } - return pushCommand(ox::make(m_img, m_activeSubsSheetIdx, a, b)); + return pushCommand(ox::make_unique(m_img, m_activeSubsSheetIdx, a, b)); } ox::Error TileSheetEditorModel::flipY() noexcept { @@ -376,7 +376,7 @@ ox::Error TileSheetEditorModel::flipY() noexcept { a = m_selection->a; b = m_selection->b; } - return pushCommand(ox::make(m_img, m_activeSubsSheetIdx, a, b)); + return pushCommand(ox::make_unique(m_img, m_activeSubsSheetIdx, a, b)); } bool TileSheetEditorModel::rotateEligible() const noexcept { @@ -390,7 +390,7 @@ bool TileSheetEditorModel::rotateEligible() const noexcept { } ox::Error TileSheetEditorModel::moveSubSheet(TileSheet::SubSheetIdx src, TileSheet::SubSheetIdx dst) noexcept { - return pushCommand(ox::make(m_img, std::move(src), std::move(dst))); + return pushCommand(ox::make_unique(m_img, std::move(src), std::move(dst))); } void TileSheetEditorModel::getFillPixels( @@ -437,9 +437,9 @@ void TileSheetEditorModel::setPalPath() noexcept { } } -ox::Error TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept { - std::ignore = m_undoStack.push(ox::UPtr{cmd}); - m_ongoingDrawCommand = dynamic_cast(cmd); +ox::Error TileSheetEditorModel::pushCommand(ox::UPtr &&cmd) noexcept { + m_ongoingDrawCommand = dynamic_cast(cmd.get()); + std::ignore = m_undoStack.push(std::move(cmd)); m_updated = true; return {}; } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp index fae64016..eaa17871 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.hpp @@ -152,7 +152,7 @@ class TileSheetEditorModel final: public ox::SignalHandler { void setPalPath() noexcept; - ox::Error pushCommand(studio::UndoCommand *cmd) noexcept; + ox::Error pushCommand(ox::UPtr &&cmd) noexcept; ox::Error handleFileRename(ox::StringViewCR, ox::StringViewCR newPath, ox::UUID const &id) noexcept;