Skip to content

Commit

Permalink
Fixed tile replacement to add tileset when needed (#1641)
Browse files Browse the repository at this point in the history
Make sure tileset is added to the map when replacing a tile of an object.
  • Loading branch information
thabetx authored and bjorn committed Jul 6, 2017
1 parent 82f473c commit 92408e1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/tiled/changemapobject.cpp
Expand Up @@ -118,6 +118,18 @@ static void setObjectCell(MapObject *object,
object->setSize(cell.tile()->size());
}

void ChangeMapObjectsTile::undo()
{
restoreTiles();
QUndoCommand::undo(); // undo child commands
}

void ChangeMapObjectsTile::redo()
{
QUndoCommand::redo(); // redo child commands
changeTiles();
}

void ChangeMapObjectsTile::restoreTiles()
{
for (int i = 0; i < mMapObjects.size(); ++i)
Expand Down
4 changes: 2 additions & 2 deletions src/tiled/changemapobject.h
Expand Up @@ -94,8 +94,8 @@ class ChangeMapObjectsTile : public QUndoCommand
const QList<MapObject *> &mapObjects,
Tile *tile);

void undo() override { restoreTiles(); }
void redo() override { changeTiles(); }
void undo() override;
void redo() override;

private:
void changeTiles();
Expand Down
10 changes: 8 additions & 2 deletions src/tiled/tilesetdock.cpp
Expand Up @@ -1006,6 +1006,12 @@ void TilesetDock::changeSelectedMapObjectsTile(Tile *tile)
if (tileObjects.isEmpty())
return;

QUndoStack *undoStack = mMapDocument->undoStack();
undoStack->push(new ChangeMapObjectsTile(mMapDocument, tileObjects, tile));
auto changeMapObjectCommand = new ChangeMapObjectsTile(mMapDocument, tileObjects, tile);

// Make sure the tileset is part of the map
SharedTileset sharedTileset = tile->tileset()->sharedPointer();
if (!mMapDocument->map()->tilesets().contains(sharedTileset))
new AddTileset(mMapDocument, sharedTileset, changeMapObjectCommand);

mMapDocument->undoStack()->push(changeMapObjectCommand);
}

0 comments on commit 92408e1

Please sign in to comment.