[nostalgia/core/studio] Fix DrawCommand not to allow appending of duplicates

This commit is contained in:
2022-02-13 23:46:45 -06:00
parent 95f3c5b62a
commit 0e041a666a
2 changed files with 10 additions and 4 deletions
@@ -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;
}