From 0e041a666a9c20b92f47f552affaf870f25e2af2 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Sun, 13 Feb 2022 23:46:45 -0600 Subject: [PATCH] [nostalgia/core/studio] Fix DrawCommand not to allow appending of duplicates --- src/nostalgia/core/studio/tilesheeteditormodel.cpp | 2 +- src/nostalgia/core/studio/tilesheeteditormodel.hpp | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.cpp b/src/nostalgia/core/studio/tilesheeteditormodel.cpp index 91261b1e5..b692a9722 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.cpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.cpp @@ -19,7 +19,6 @@ void TileSheetEditorModel::draw(const geo::Point &pt, std::size_t palIdx) noexce m_updated = m_ongoingDrawCommand->append(ptToIdx(pt, m_img.columns)); } else { pushCommand(new DrawCommand(&m_img, ptToIdx(pt, m_img.columns), palIdx)); - m_updated = true; } } @@ -70,6 +69,7 @@ void TileSheetEditorModel::getFillPixels(bool *pixels, const geo::Point &pt, int void TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept { m_undoStack.push(cmd); m_ongoingDrawCommand = dynamic_cast(cmd); + m_updated = true; } } \ No newline at end of file diff --git a/src/nostalgia/core/studio/tilesheeteditormodel.hpp b/src/nostalgia/core/studio/tilesheeteditormodel.hpp index 04cedeca2..22bee50a2 100644 --- a/src/nostalgia/core/studio/tilesheeteditormodel.hpp +++ b/src/nostalgia/core/studio/tilesheeteditormodel.hpp @@ -68,9 +68,15 @@ struct DrawCommand: public studio::UndoCommand { constexpr bool append(std::size_t idx) noexcept { if (m_changes.back().value.idx != idx) { - m_changes.emplace_back(idx, m_img->pixels[idx]); - m_img->setPixel(idx, m_palIdx); - return true; + // duplicate entries are bad + auto existing = std::find_if(m_changes.cbegin(), m_changes.cend(), [idx](const auto &c) { + return c.idx == idx; + }); + if (existing == m_changes.cend()) { + m_changes.emplace_back(idx, m_img->pixels[idx]); + m_img->setPixel(idx, m_palIdx); + return true; + } } return false; }