Skip to content

Commit

Permalink
AutoMapping: Match in order by default, when input regions are defined
Browse files Browse the repository at this point in the history
This improves compatibility with AutoMapping rules written for older
versions of Tiled.

Closes mapeditor#3559
  • Loading branch information
bjorn authored and dogboydog committed Feb 4, 2023
1 parent 873f820 commit 5c4fec4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Added action search popup on Ctrl+Shift+P (with dogboydog, #3449)
* Added file system actions also for tileset image based tilesets (#3448)
* Fixed new layer names to be always unique (by Logan Higinbotham, #3452)
* AutoMapping: Match in order by default, when input regions are defined (#3559)
* Scripting: Added Object.setColorProperty and Object.setFloatProperty (#3423)
* Scripting: Added tiled.projectFilePath
* Scripting: Added TileMap.toImage (#3519)
Expand Down
6 changes: 5 additions & 1 deletion src/tiled/automapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ void AutoMapper::setupRules()
regionInput |= inputLayer.tileLayer->region();
}
}
} else if (!mOptions.matchInOrder.has_value()) {
// For backwards compatibility, when the input regions have been
// explicitly defined, we default MatchInOrder to true.
mOptions.matchInOrder = true;
}

// When no output regions have been defined at all, derive them from the
Expand Down Expand Up @@ -985,7 +989,7 @@ void AutoMapper::autoMap(const QRegion &where,

ApplyContext applyContext(appliedRegion);

if (mOptions.matchInOrder) {
if (mOptions.matchInOrder.value_or(false)) {
for (const Rule &rule : mRules) {
if (rule.options.disabled)
continue;
Expand Down
3 changes: 2 additions & 1 deletion src/tiled/automapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QVector>

#include <memory>
#include <optional>
#include <type_traits>
#include <unordered_map>
#include <vector>
Expand Down Expand Up @@ -260,7 +261,7 @@ class TILED_EDITOR_EXPORT AutoMapper : public QObject
/**
* Determines whether the rules on the map need to be matched in order.
*/
bool matchInOrder = false;
std::optional<bool> matchInOrder;

/**
* This variable determines, how many overlapping tiles should be used.
Expand Down

0 comments on commit 5c4fec4

Please sign in to comment.