[nostalgia/core/studio] Fix DrawCommand not to allow appending of duplicates
This commit is contained in:
parent
95f3c5b62a
commit
0e041a666a
@ -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));
|
m_updated = m_ongoingDrawCommand->append(ptToIdx(pt, m_img.columns));
|
||||||
} else {
|
} else {
|
||||||
pushCommand(new DrawCommand(&m_img, ptToIdx(pt, m_img.columns), palIdx));
|
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 {
|
void TileSheetEditorModel::pushCommand(studio::UndoCommand *cmd) noexcept {
|
||||||
m_undoStack.push(cmd);
|
m_undoStack.push(cmd);
|
||||||
m_ongoingDrawCommand = dynamic_cast<DrawCommand*>(cmd);
|
m_ongoingDrawCommand = dynamic_cast<DrawCommand*>(cmd);
|
||||||
|
m_updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -68,10 +68,16 @@ struct DrawCommand: public studio::UndoCommand {
|
|||||||
|
|
||||||
constexpr bool append(std::size_t idx) noexcept {
|
constexpr bool append(std::size_t idx) noexcept {
|
||||||
if (m_changes.back().value.idx != idx) {
|
if (m_changes.back().value.idx != idx) {
|
||||||
|
// 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_changes.emplace_back(idx, m_img->pixels[idx]);
|
||||||
m_img->setPixel(idx, m_palIdx);
|
m_img->setPixel(idx, m_palIdx);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user