Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AdjustTileMetaData also updates tile types #3237

Merged
merged 2 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/tiled/adjusttileindexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "changemapobject.h"
#include "changeproperties.h"
#include "changetile.h"
#include "changetileanimation.h"
#include "changetileobjectgroup.h"
#include "changetileprobability.h"
Expand Down Expand Up @@ -158,6 +159,7 @@ AdjustTileMetaData::AdjustTileMetaData(TilesetDocument *tilesetDocument)
};

// Adjust tile meta data
QMap<QString, QList<Tile*>> tilesChangingTypeByType;
QList<Tile*> tilesChangingProbability;
QList<qreal> tileProbabilities;
QSet<Tile*> tilesToReset;
Expand All @@ -175,6 +177,7 @@ AdjustTileMetaData::AdjustTileMetaData(TilesetDocument *tilesetDocument)

auto applyMetaData = [&](Tile *toTile,
const Properties &properties,
const QString& type,
bjorn marked this conversation as resolved.
Show resolved Hide resolved
qreal probability,
std::unique_ptr<ObjectGroup> objectGroup,
const QVector<Frame> &frames)
Expand All @@ -187,6 +190,9 @@ AdjustTileMetaData::AdjustTileMetaData(TilesetDocument *tilesetDocument)
this);
}

if (type != toTile->type())
tilesChangingTypeByType[type].append(toTile);

if (probability != toTile->probability()) {
tilesChangingProbability.append(toTile);
tileProbabilities.append(probability);
Expand Down Expand Up @@ -219,6 +225,7 @@ AdjustTileMetaData::AdjustTileMetaData(TilesetDocument *tilesetDocument)

applyMetaData(toTile,
fromTile->properties(),
fromTile->type(),
fromTile->probability(),
std::move(objectGroup),
adjustAnimationFrames(fromTile->frames()));
Expand All @@ -241,7 +248,7 @@ AdjustTileMetaData::AdjustTileMetaData(TilesetDocument *tilesetDocument)
QSetIterator<Tile*> resetIterator(tilesToReset);
while (resetIterator.hasNext()) {
applyMetaData(resetIterator.next(),
Properties(), 1.0, nullptr, QVector<Frame>());
Properties(), QString(), 1.0, nullptr, QVector<Frame>());
}

// Translate tile references in Wang sets and Wang colors
Expand Down Expand Up @@ -297,6 +304,12 @@ AdjustTileMetaData::AdjustTileMetaData(TilesetDocument *tilesetDocument)
new ChangeTileWangId(tilesetDocument, wangSet, changes, this);
}

QMapIterator<QString, QList<Tile*>> it(tilesChangingTypeByType);
while (it.hasNext()) {
it.next();
new ChangeTileType(tilesetDocument, it.value(), it.key(), this);
}

if (!tilesChangingProbability.isEmpty()) {
new ChangeTileProbability(tilesetDocument,
tilesChangingProbability,
Expand Down
5 changes: 3 additions & 2 deletions src/tiled/changetile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ namespace Tiled {

ChangeTileType::ChangeTileType(TilesetDocument *tilesetDocument,
const QList<Tile *> &tiles,
const QString &type)
: QUndoCommand(QCoreApplication::translate("Undo Commands", "Change Tile Type"))
const QString &type,
QUndoCommand *parent)
: QUndoCommand(QCoreApplication::translate("Undo Commands", "Change Tile Type"), parent)
, mTilesetDocument(tilesetDocument)
, mTiles(tiles)
{
Expand Down
3 changes: 2 additions & 1 deletion src/tiled/changetile.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ class ChangeTileType : public QUndoCommand
*/
ChangeTileType(TilesetDocument *tilesetDocument,
const QList<Tile*> &tiles,
const QString &type);
const QString &type,
QUndoCommand *parent = nullptr);

void undo() override { swap(); }
void redo() override { swap(); }
Expand Down