From c812051ec0f215eebb5dd9eb89c3163b0ef27863 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Fri, 30 Jan 2026 00:30:48 -0600 Subject: [PATCH] [nostalgia/gfx/studio] Cleanup --- .../commands/cutpastecommand.cpp | 26 ++++++++++--------- .../commands/cutpastecommand.hpp | 17 ++++++------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/cutpastecommand.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/cutpastecommand.cpp index f48c601c..03379445 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/cutpastecommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/cutpastecommand.cpp @@ -5,14 +5,15 @@ #include "cutpastecommand.hpp" namespace nostalgia::gfx { + TileSheetClipboard::Pixel::Pixel( - uint16_t const pColorIdx, + uint8_t const pColorIdx, ox::Point const pPt) noexcept: colorIdx(pColorIdx), pt(pPt) {} -void TileSheetClipboard::addPixel(ox::Point const &pt, uint16_t colorIdx) noexcept { +void TileSheetClipboard::addPixel(ox::Point const &pt, uint8_t colorIdx) noexcept { m_pixels.emplace_back(colorIdx, pt); } @@ -22,7 +23,7 @@ const ox::Vector &TileSheetClipboard::pixels() const CutPasteCommand::CutPasteCommand( - CommandId commandId, + CommandId const commandId, TileSheet &img, TileSheet::SubSheetIdx subSheetIdx, ox::Point const &dstStart, @@ -41,24 +42,18 @@ CutPasteCommand::CutPasteCommand( auto const dstPt = p.pt + dstStart; if (dstPt.x <= dstEnd.x && dstPt.y <= dstEnd.y) { auto const idx = gfx::idx(ss, dstPt); - m_changes.emplace_back(static_cast(idx), p.colorIdx, getPixel(ss, idx)); + m_changes.emplace_back(static_cast(idx), p.colorIdx); } } } ox::Error CutPasteCommand::redo() noexcept { - auto &subsheet = getSubSheet(m_img, m_subSheetIdx); - for (auto const &c : m_changes) { - subsheet.pixels[c.idx] = static_cast(c.newPalIdx); - } + swap(); return {}; } ox::Error CutPasteCommand::undo() noexcept { - auto &subsheet = getSubSheet(m_img, m_subSheetIdx); - for (auto const &c : m_changes) { - subsheet.pixels[c.idx] = static_cast(c.oldPalIdx); - } + swap(); return {}; } @@ -70,4 +65,11 @@ TileSheet::SubSheetIdx const &CutPasteCommand::subsheetIdx() const noexcept { return m_subSheetIdx; } +void CutPasteCommand::swap() noexcept { + auto &subsheet = getSubSheet(m_img, m_subSheetIdx); + for (auto &c : m_changes) { + std::swap(subsheet.pixels[c.idx], c.palIdx); + } +} + } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/cutpastecommand.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/cutpastecommand.hpp index 25146141..2bd767c1 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/cutpastecommand.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/cutpastecommand.hpp @@ -22,15 +22,15 @@ class TileSheetClipboard: public turbine::ClipboardObject { struct Pixel { static constexpr auto TypeName = "net.drinkingtea.nostalgia.gfx.studio.TileSheetClipboard.Pixel"; static constexpr auto TypeVersion = 1; - uint16_t colorIdx = 0; + uint8_t colorIdx = 0; ox::Point pt; - Pixel(uint16_t pColorIdx, ox::Point pPt) noexcept; + Pixel(uint8_t pColorIdx, ox::Point pPt) noexcept; }; protected: ox::Vector m_pixels; public: - void addPixel(ox::Point const &pt, uint16_t colorIdx) noexcept; + void addPixel(ox::Point const &pt, uint8_t colorIdx) noexcept; [[nodiscard]] ox::Vector const &pixels() const noexcept; @@ -49,12 +49,10 @@ class CutPasteCommand: public TileSheetCommand { private: struct Change { uint32_t idx = 0; - uint16_t newPalIdx = 0; - uint16_t oldPalIdx = 0; - constexpr Change(uint32_t pIdx, uint16_t pNewPalIdx, uint16_t pOldPalIdx) noexcept { + uint8_t palIdx = 0; + constexpr Change(uint32_t const pIdx, uint8_t const pPalIdx) noexcept { idx = pIdx; - newPalIdx = pNewPalIdx; - oldPalIdx = pOldPalIdx; + palIdx = pPalIdx; } }; CommandId m_commandId; @@ -81,6 +79,9 @@ class CutPasteCommand: public TileSheetCommand { [[nodiscard]] TileSheet::SubSheetIdx const &subsheetIdx() const noexcept override; + private: + void swap() noexcept; + }; }