@@ -46,6 +46,11 @@ Tile *Tileset::tileAt(int id) const
46
46
return (id < mTiles .size ()) ? mTiles .at (id) : nullptr ;
47
47
}
48
48
49
+ void Tileset::removeLastTile ()
50
+ {
51
+ delete mTiles .takeLast ();
52
+ }
53
+
49
54
/* *
50
55
* Load this tileset from the given tileset \a image. This will replace
51
56
* existing tile images in this tileset with new ones. If the new image
@@ -113,21 +118,54 @@ bool Tileset::loadFromImage(const QImage &image,
113
118
return true ;
114
119
}
115
120
121
+ static bool sameTileImages (const Tileset &a, const Tileset &b)
122
+ {
123
+ Q_ASSERT (a.tileCount () == b.tileCount ());
124
+
125
+ for (int i = 0 ; i < a.tileCount (); ++i) {
126
+ const Tile *tileA = a.tileAt (i);
127
+ const Tile *tileB = b.tileAt (i);
128
+ if (tileA->imageSource () != tileB->imageSource ())
129
+ return false ;
130
+ }
131
+
132
+ return true ;
133
+ }
134
+
116
135
SharedTileset Tileset::findSimilarTileset (const QVector<SharedTileset> &tilesets) const
117
136
{
118
137
foreach (const SharedTileset &candidate, tilesets) {
119
- if (candidate != this
120
- && candidate->imageSource () == imageSource ()
121
- && candidate->tileWidth () == tileWidth ()
122
- && candidate->tileHeight () == tileHeight ()
123
- && candidate->tileSpacing () == tileSpacing ()
124
- && candidate->margin () == margin ()) {
125
- return candidate;
126
- }
138
+ Q_ASSERT (candidate != this );
139
+
140
+ if (candidate->tileCount () != tileCount ())
141
+ continue ;
142
+ if (candidate->imageSource () != imageSource ())
143
+ continue ;
144
+ if (candidate->tileSize () != tileSize ())
145
+ continue ;
146
+ if (candidate->tileSpacing () != tileSpacing ())
147
+ continue ;
148
+ if (candidate->margin () != margin ())
149
+ continue ;
150
+ if (candidate->tileOffset () != tileOffset ())
151
+ continue ;
152
+
153
+ // For an image collection tileset, check the image sources
154
+ if (imageSource ().isEmpty ())
155
+ if (!sameTileImages (*this , *candidate))
156
+ continue ;
157
+
158
+ return candidate;
127
159
}
160
+
128
161
return SharedTileset ();
129
162
}
130
163
164
+ void Tileset::setImageSource (const QString &imageSource)
165
+ {
166
+ mImageSource = imageSource;
167
+ }
168
+
131
169
int Tileset::columnCountForWidth (int width) const
132
170
{
133
171
Q_ASSERT (mTileWidth > 0 );
0 commit comments