From 73eabc92cafbdb8a9d6cb53cdf11860432504022 Mon Sep 17 00:00:00 2001 From: GriffinR Date: Wed, 29 Jun 2022 14:53:14 -0400 Subject: [PATCH] Prevent duplicate metatile pastes in the tileset editor --- include/core/metatile.h | 14 ++++++++++++++ include/core/tile.h | 11 +++++++++++ src/ui/tileseteditor.cpp | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/include/core/metatile.h b/include/core/metatile.h index 7c744dc4..ef8ce0eb 100644 --- a/include/core/metatile.h +++ b/include/core/metatile.h @@ -54,4 +54,18 @@ public: static int getAttributesSize(BaseGameVersion version); }; +inline bool operator==(const Metatile &a, const Metatile &b) { + return a.behavior == b.behavior && + a.layerType == b.layerType && + a.encounterType == b.encounterType && + a.terrainType == b.terrainType && + a.unusedAttributes == b.unusedAttributes && + a.label == b.label && + a.tiles == b.tiles; +} + +inline bool operator!=(const Metatile &a, const Metatile &b) { + return !(operator==(a, b)); +} + #endif // METATILE_H diff --git a/include/core/tile.h b/include/core/tile.h index b97c1775..1a862987 100644 --- a/include/core/tile.h +++ b/include/core/tile.h @@ -22,4 +22,15 @@ public: static int getIndexInTileset(int); }; +inline bool operator==(const Tile &a, const Tile &b) { + return a.tileId == b.tileId && + a.xflip == b.xflip && + a.yflip == b.yflip && + a.palette == b.palette; +} + +inline bool operator!=(const Tile &a, const Tile &b) { + return !(operator==(a, b)); +} + #endif // TILE_H diff --git a/src/ui/tileseteditor.cpp b/src/ui/tileseteditor.cpp index 0ff44c7b..2d006cf4 100644 --- a/src/ui/tileseteditor.cpp +++ b/src/ui/tileseteditor.cpp @@ -815,7 +815,7 @@ void TilesetEditor::onPaletteEditorChangedPalette(int paletteId) { bool TilesetEditor::replaceMetatile(uint16_t metatileId, Metatile * src) { Metatile * dest = Tileset::getMetatile(metatileId, this->primaryTileset, this->secondaryTileset); - if (!dest || !src) + if (!dest || !src || *dest == *src) return false; this->metatile = dest;