Skip to content

Commit

Permalink
Fixed an issue with identifying similar image collection tilesets
Browse files Browse the repository at this point in the history
Image collection tilesets were trivially seen as "similar"
in most cases, as long as they were using tiles of the same size. Now,
they need to have the same number of the images and all of the images
need to refer to the same image file.

Closes mapeditor#1113
  • Loading branch information
bjorn committed Oct 12, 2015
1 parent e8055ae commit a033e70
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Fixed layer offsets missing in the Lua export
* Fixed JSON tileset format missing in 'Add External Tileset' action
* Fixed language selection entries for Portuguese
* Fixed an issue with copy/pasting when using image collection tilesets
* Updated Brazilian Portuguese translation

0.14.1 (28 September 2015)
Expand Down
44 changes: 36 additions & 8 deletions src/libtiled/tileset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,46 @@ bool Tileset::loadFromImage(const QImage &image,
return true;
}

static bool sameTileImages(const Tileset &a, const Tileset &b)
{
Q_ASSERT(a.tileCount() == b.tileCount());

for (int i = 0; i < a.tileCount(); ++i) {
const Tile *tileA = a.tileAt(i);
const Tile *tileB = b.tileAt(i);
if (tileA->imageSource() != tileB->imageSource())
return false;
}

return true;
}

SharedTileset Tileset::findSimilarTileset(const QVector<SharedTileset> &tilesets) const
{
foreach (const SharedTileset &candidate, tilesets) {
if (candidate != this
&& candidate->imageSource() == imageSource()
&& candidate->tileWidth() == tileWidth()
&& candidate->tileHeight() == tileHeight()
&& candidate->tileSpacing() == tileSpacing()
&& candidate->margin() == margin()) {
return candidate;
}
Q_ASSERT(candidate != this);

if (candidate->tileCount() != tileCount())
continue;
if (candidate->imageSource() != imageSource())
continue;
if (candidate->tileSize() != tileSize())
continue;
if (candidate->tileSpacing() != tileSpacing())
continue;
if (candidate->margin() != margin())
continue;
if (candidate->tileOffset() != tileOffset())
continue;

// For an image collection tileset, check the image sources
if (imageSource().isEmpty())
if (!sameTileImages(*this, *candidate))
continue;

return candidate;
}

return SharedTileset();
}

Expand Down

0 comments on commit a033e70

Please sign in to comment.