diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.cpp index b84b0f6a..0b8f59a7 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.cpp @@ -63,7 +63,7 @@ DrawCommand::DrawCommand( TileSheet &img, TileSheet::SubSheetIdx subSheetIdx, std::size_t idx, - int palIdx) noexcept: + int const palIdx) noexcept: m_img(img), m_subSheetIdx(std::move(subSheetIdx)), m_palIdx(palIdx) { @@ -75,7 +75,7 @@ DrawCommand::DrawCommand( TileSheet &img, TileSheet::SubSheetIdx subSheetIdx, ox::SpanView const&idxList, - int palIdx) noexcept: + int const palIdx) noexcept: m_img(img), m_subSheetIdx(std::move(subSheetIdx)), m_palIdx(palIdx) { @@ -123,7 +123,9 @@ void DrawCommand::lineUpdate(ox::Point a, ox::Point b) noexcept { for (int32_t i{}; i < range; ++i) { auto const idx = ptToIdx(x, y + i * mod, ss.columns * TileWidth); if (idx < ss.pixels.size()) { - m_changes.emplace_back(static_cast(idx), getPixel(ss, idx)); + if (m_palIdx != getPixel(ss, idx)) { + m_changes.emplace_back(static_cast(idx), getPixel(ss, idx)); + } } } }); @@ -154,4 +156,8 @@ TileSheet::SubSheetIdx const&DrawCommand::subsheetIdx() const noexcept { return m_subSheetIdx; } +void DrawCommand::finish() noexcept { + setObsolete(m_changes.empty()); +} + } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.hpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.hpp index a9945e72..84b21188 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.hpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/commands/drawcommand.hpp @@ -52,6 +52,8 @@ class DrawCommand: public TileSheetCommand { [[nodiscard]] TileSheet::SubSheetIdx const&subsheetIdx() const noexcept override; + void finish() noexcept; + }; } diff --git a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp index 52b91f40..d64fa945 100644 --- a/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp +++ b/src/nostalgia/modules/gfx/src/studio/tilesheeteditor/tilesheeteditormodel.cpp @@ -172,7 +172,7 @@ void TileSheetEditorModel::drawLineCommand(ox::Point const &pt, std::size_t cons if (m_ongoingDrawCommand) { m_ongoingDrawCommand->lineUpdate(m_lineStartPt, pt); m_updated = true; - } else if (getPixel(activeSubSheet, idx) != palIdx) { + } else { std::ignore = pushCommand(ox::make( m_img, m_activeSubsSheetIdx, idx, static_cast(palIdx))); m_lineStartPt = pt; @@ -180,7 +180,10 @@ void TileSheetEditorModel::drawLineCommand(ox::Point const &pt, std::size_t cons } void TileSheetEditorModel::endDrawCommand() noexcept { - m_ongoingDrawCommand = nullptr; + if (m_ongoingDrawCommand) { + m_ongoingDrawCommand->finish(); + m_ongoingDrawCommand = nullptr; + } } void TileSheetEditorModel::addSubsheet(TileSheet::SubSheetIdx const&parentIdx) noexcept {