Skip to content

Commit

Permalink
Make sure tileset is added to the map when replacing a tile of an object
Browse files Browse the repository at this point in the history
  • Loading branch information
thabetx committed Jul 5, 2017
1 parent 419444b commit 2220c71
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/tiled/changemapobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,18 @@ ChangeMapObjectsTile::ChangeMapObjectsTile(MapDocument *mapDocument,
}
}

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

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

static void setObjectCell(MapObject *object,
const Cell &cell,
const bool updateSize)
Expand Down
4 changes: 2 additions & 2 deletions src/tiled/changemapobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,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
13 changes: 11 additions & 2 deletions src/tiled/tilesetdock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,15 @@ 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);

if (Tileset *tileset = tile->tileset()) {
SharedTileset sharedTileset = tileset->sharedPointer();

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

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

0 comments on commit 2220c71

Please sign in to comment.