Skip to content

Commit

Permalink
tBIN plugin: Fixed hang when locating missing tileset image
Browse files Browse the repository at this point in the history
Was caused by trying to cut the tileset into 0x0 tiles, of which there
are infinitely many.

Now the plugin uses Tileset::findOrCreateTile to create the tiles for
loading the tile properties, which does not affect the tile size
(Tileset::addTiles does, because it's meant to be used by image
collection tilesets).

Closes #2068
  • Loading branch information
bjorn committed Feb 4, 2019
1 parent c7080ab commit 1972975
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/plugins/tbin/tbinplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,11 @@ Tiled::Map *TbinMapFormat::read(const QString &fileName)
if (ttilesheet.margin.x != ttilesheet.margin.y)
throw std::invalid_argument(QT_TR_NOOP("Tilesheet must have equal margins."));

auto tilesheet = Tiled::Tileset::create(ttilesheet.id.c_str(), ttilesheet.tileSize.x, ttilesheet.tileSize.y, ttilesheet.spacing.x, ttilesheet.margin.x);
tilesheet->setImageSource(Tiled::toUrl(QString::fromStdString(ttilesheet.image), fileDir));
if (!tilesheet->loadImage()) {
QList<Tiled::Tile*> tiles;
for (int i = 0; i < ttilesheet.sheetSize.x * ttilesheet.sheetSize.y; ++i) {
tiles.append(new Tiled::Tile(i, tilesheet.data()));
}
tilesheet->addTiles(tiles);
}
tbinToTiledProperties(ttilesheet.props, tilesheet.data());
auto tileset = Tiled::Tileset::create(ttilesheet.id.c_str(), ttilesheet.tileSize.x, ttilesheet.tileSize.y, ttilesheet.spacing.x, ttilesheet.margin.x);
tileset->setImageSource(Tiled::toUrl(QString::fromStdString(ttilesheet.image), fileDir));
tileset->loadImage();

tbinToTiledProperties(ttilesheet.props, tileset.data());

for (auto prop : ttilesheet.props) {
if (prop.first[0] != '@')
Expand All @@ -166,15 +161,15 @@ Tiled::Map *TbinMapFormat::read(const QString &fileName)
int index = strs[2].toInt();
tbin::Properties dummyProps;
dummyProps.insert(std::make_pair(strs[3].toStdString(), prop.second));
Tiled::Tile* tile = tilesheet->tileAt(index);
Tiled::Tile *tile = tileset->findOrCreateTile(index);
tbinToTiledProperties(dummyProps, tile);
}
// TODO: 'AutoTile' ?
// Purely for map making. Appears to be similar to terrains
// (In tIDE, right click a tilesheet and choose "Auto Tiles..."
}

map->addTileset(tilesheet);
map->addTileset(tileset);
}
for (const tbin::Layer& tlayer : tmap.layers) {
if (tlayer.tileSize.x != firstLayer.tileSize.x || tlayer.tileSize.y != firstLayer.tileSize.y)
Expand Down

0 comments on commit 1972975

Please sign in to comment.