[nostalgia/core/studio] Fix issue with pixel idx lookup in draw command
This commit is contained in:
@@ -23,32 +23,6 @@ enum class CommandId {
|
||||
ClipboardPaste = 5,
|
||||
};
|
||||
|
||||
enum class TileSheetTool: int {
|
||||
Select,
|
||||
Draw,
|
||||
Fill,
|
||||
};
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr auto toString(TileSheetTool t) noexcept {
|
||||
switch (t) {
|
||||
case TileSheetTool::Select:
|
||||
return "Select";
|
||||
case TileSheetTool::Draw:
|
||||
return "Draw";
|
||||
case TileSheetTool::Fill:
|
||||
return "Fill";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
struct PixelChunk {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.PixelChunk";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
geo::Point pt;
|
||||
int size = 0;
|
||||
};
|
||||
|
||||
struct DrawCommand: public studio::UndoCommand {
|
||||
private:
|
||||
struct Change {
|
||||
@@ -62,18 +36,18 @@ struct DrawCommand: public studio::UndoCommand {
|
||||
public:
|
||||
constexpr DrawCommand(NostalgiaGraphic *img, std::size_t idx, int palIdx) noexcept {
|
||||
m_img = img;
|
||||
m_changes.emplace_back(idx, m_img->pixels[idx]);
|
||||
m_changes.emplace_back(idx, m_img->getPixel(idx));
|
||||
m_palIdx = palIdx;
|
||||
}
|
||||
|
||||
constexpr bool append(std::size_t idx) noexcept {
|
||||
if (m_changes.back().value.idx != idx) {
|
||||
if (m_changes.back().value.idx != idx && m_img->getPixel(idx) != m_palIdx) {
|
||||
// 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->getPixel(idx));
|
||||
m_img->setPixel(idx, m_palIdx);
|
||||
return true;
|
||||
}
|
||||
@@ -82,24 +56,19 @@ struct DrawCommand: public studio::UndoCommand {
|
||||
}
|
||||
|
||||
void redo() noexcept override {
|
||||
for (auto c : m_changes) {
|
||||
for (const auto &c : m_changes) {
|
||||
m_img->setPixel(c.idx, m_palIdx);
|
||||
}
|
||||
}
|
||||
|
||||
void undo() noexcept override {
|
||||
for (auto c : m_changes) {
|
||||
for (const auto &c : m_changes) {
|
||||
m_img->setPixel(c.idx, c.oldPalIdx);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
oxModelBegin(PixelChunk)
|
||||
oxModelField(pt)
|
||||
oxModelField(size)
|
||||
oxModelEnd()
|
||||
|
||||
struct TileSheetClipboard {
|
||||
static constexpr auto TypeName = "net.drinkingtea.nostalgia.core.studio.TileSheetClipboard";
|
||||
static constexpr auto TypeVersion = 1;
|
||||
|
||||
Reference in New Issue
Block a user