Skip to content

Commit

Permalink
Automapping: Apply rules to selected area when there is one
Browse files Browse the repository at this point in the history
Suggested on the forum and seems like a sensible thing to do.

See http://discourse.mapeditor.org/t/selective-automapping/3093
  • Loading branch information
bjorn committed Mar 27, 2018
1 parent b3e461b commit 935401d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/tiled/automapperwrapper.h
Expand Up @@ -43,7 +43,7 @@ class AutoMapperWrapper : public QUndoCommand
public:
AutoMapperWrapper(MapDocument *mapDocument, QVector<AutoMapper*> autoMapper,
QRegion *where);
~AutoMapperWrapper();
~AutoMapperWrapper() override;

void undo() override;
void redo() override;
Expand Down
27 changes: 15 additions & 12 deletions src/tiled/automappingmanager.cpp
Expand Up @@ -52,23 +52,26 @@ void AutomappingManager::autoMap()
return;

Map *map = mMapDocument->map();
QRegion region = mMapDocument->selectedArea();

QRect bounds;
if (region.isEmpty()) {
if (map->infinite()) {
LayerIterator iterator(map);

if (map->infinite()) {
LayerIterator iterator(map);

while (Layer *layer = iterator.next()) {
if (TileLayer *tileLayer = dynamic_cast<TileLayer*>(layer))
bounds = bounds.united(tileLayer->bounds());
QRect bounds;
while (Layer *layer = iterator.next()) {
if (TileLayer *tileLayer = dynamic_cast<TileLayer*>(layer))
bounds = bounds.united(tileLayer->bounds());
}
region = bounds;
} else {
int w = map->width();
int h = map->height();
region = QRect(0, 0, w, h);
}
} else {
int w = map->width();
int h = map->height();
bounds = QRect(0, 0, w, h);
}

autoMapInternal(bounds, nullptr);
autoMapInternal(region, nullptr);
}

void AutomappingManager::autoMap(const QRegion &where, Layer *touchedLayer)
Expand Down
3 changes: 2 additions & 1 deletion src/tiled/automappingmanager.h
Expand Up @@ -69,7 +69,8 @@ class AutomappingManager : public QObject

public slots:
/**
* This triggers an automapping on the whole current map document.
* This triggers an automapping on the current map document. Starts with
* the currently selected area, or the entire map if there is no selection.
*/
void autoMap();

Expand Down

0 comments on commit 935401d

Please sign in to comment.