Fix compare_docs() to compare cels correctly + added more comparisons

This commit is contained in:
David Capello 2022-11-08 19:26:27 -03:00
parent bd674dcb31
commit 7f8df8a08d

View File

@ -22,9 +22,25 @@
#include "doc/tag.h"
#include "doc/tileset.h"
#include "doc/tilesets.h"
#include "doc/user_data.h"
#ifdef _DEBUG
static std::ostream& operator<<(std::ostream& os, const doc::UserData& userData)
{
return os << "("
<< userData.text() << ", "
<< userData.color() << ")";
}
#endif
namespace app {
#ifdef _DEBUG
#define TRACEDIFF(a, b) if (a != b) { TRACEARGS(#a " != " #b, a, b); }
#else
#define TRACEDIFF(a, b)
#endif
DocDiff compare_docs(const Doc* a,
const Doc* b)
{
@ -36,18 +52,27 @@ DocDiff compare_docs(const Doc* a,
// Compare sprite specs
if (a->sprite()->width() != b->sprite()->width() ||
a->sprite()->height() != b->sprite()->height() ||
a->sprite()->pixelFormat() != b->sprite()->pixelFormat()) {
a->sprite()->pixelFormat() != b->sprite()->pixelFormat() ||
a->sprite()->userData() != b->sprite()->userData()) {
diff.anything = diff.canvas = true;
TRACEDIFF(a->sprite()->size(), b->sprite()->size());
TRACEDIFF(a->sprite()->pixelFormat(), b->sprite()->pixelFormat());
TRACEDIFF(a->sprite()->userData(), b->sprite()->userData());
}
// Frames layers
if (a->sprite()->totalFrames() != b->sprite()->totalFrames()) {
diff.anything = diff.totalFrames = true;
TRACEDIFF(a->sprite()->totalFrames(), b->sprite()->totalFrames());
}
else {
for (frame_t f=0; f<a->sprite()->totalFrames(); ++f) {
if (a->sprite()->frameDuration(f) != b->sprite()->frameDuration(f)) {
diff.anything = diff.frameDuration = true;
TRACEDIFF(a->sprite()->frameDuration(f), b->sprite()->frameDuration(f));
break;
}
}
@ -56,6 +81,8 @@ DocDiff compare_docs(const Doc* a,
// Tags
if (a->sprite()->tags().size() != b->sprite()->tags().size()) {
diff.anything = diff.tags = true;
TRACEDIFF(a->sprite()->tags().size(), b->sprite()->tags().size());
}
else {
auto aIt = a->sprite()->tags().begin(), aEnd = a->sprite()->tags().end();
@ -68,8 +95,17 @@ DocDiff compare_docs(const Doc* a,
aTag->name() != bTag->name() ||
aTag->color() != bTag->color() ||
aTag->aniDir() != bTag->aniDir() ||
aTag->repeat() != bTag->repeat()) {
aTag->repeat() != bTag->repeat() ||
aTag->userData() != bTag->userData()) {
diff.anything = diff.tags = true;
TRACEDIFF(aTag->fromFrame(), bTag->fromFrame());
TRACEDIFF(aTag->toFrame(), bTag->toFrame());
TRACEDIFF(aTag->name(), bTag->name());
TRACEDIFF(aTag->color(), bTag->color());
TRACEDIFF((int)aTag->aniDir(), (int)bTag->aniDir());
TRACEDIFF(aTag->repeat(), bTag->repeat());
TRACEDIFF(aTag->userData(), bTag->userData());
}
}
}
@ -104,8 +140,13 @@ DocDiff compare_docs(const Doc* a,
Tileset* bTileset = b->sprite()->tilesets()->get(i);
if (aTileset->grid().tileSize() != bTileset->grid().tileSize() ||
aTileset->size() != bTileset->size()) {
aTileset->size() != bTileset->size() ||
aTileset->userData() != bTileset->userData()) {
diff.anything = diff.tilesets = true;
TRACEDIFF(aTileset->grid().tileSize(), bTileset->grid().tileSize());
TRACEDIFF(aTileset->size(), bTileset->size());
TRACEDIFF(aTileset->userData(), bTileset->userData());
break;
}
else {
@ -137,6 +178,7 @@ DocDiff compare_docs(const Doc* a,
if (aLay->type() != bLay->type() ||
aLay->name() != bLay->name() ||
aLay->userData() != bLay->userData() ||
((int(aLay->flags()) & int(LayerFlags::PersistentFlagsMask)) !=
(int(bLay->flags()) & int(LayerFlags::PersistentFlagsMask))) ||
(aLay->isImage() && bLay->isImage() &&
@ -147,7 +189,7 @@ DocDiff compare_docs(const Doc* a,
break;
}
if (diff.totalFrames) {
if (!diff.totalFrames) {
for (frame_t f=0; f<a->sprite()->totalFrames(); ++f) {
const Cel* aCel = aLay->cel(f);
const Cel* bCel = bLay->cel(f);
@ -157,16 +199,23 @@ DocDiff compare_docs(const Doc* a,
diff.anything = diff.cels = true;
}
else if (aCel && bCel) {
if (aCel->frame() == bCel->frame() ||
aCel->bounds() == bCel->bounds() ||
aCel->opacity() == bCel->opacity()) {
if (aCel->frame() != bCel->frame() ||
aCel->bounds() != bCel->bounds() ||
aCel->opacity() != bCel->opacity() ||
aCel->data()->userData() != bCel->data()->userData()) {
diff.anything = diff.cels = true;
TRACEDIFF(aCel->frame(), bCel->frame());
TRACEDIFF(aCel->bounds(), bCel->bounds());
TRACEDIFF(aCel->opacity(), bCel->opacity());
TRACEDIFF(aCel->data()->userData(), bCel->data()->userData());
}
if (aCel->image() && bCel->image()) {
if (aCel->image()->bounds() != bCel->image()->bounds() ||
!is_same_image(aCel->image(), bCel->image()))
diff.anything = diff.images = true;
}
// In case one is nullptr and the other not
else if (aCel->image() != bCel->image())
diff.anything = diff.images = true;
}