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

AutoMapping: Ignore rules with empty input or output regions #4115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 9 additions & 4 deletions src/tiled/automapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,16 @@ void AutoMapper::setupRules()
mRules.reserve(combinedRegions.size());

for (const QRegion &combinedRegion : combinedRegions) {
QRegion inputRegion = combinedRegion & regionInput;
QRegion outputRegion = combinedRegion & regionOutput;

// Skip rules where either input or output region is empty
if (inputRegion.isEmpty() || outputRegion.isEmpty())
continue;

Rule &rule = mRules.emplace_back();
rule.inputRegion = combinedRegion & regionInput;
rule.outputRegion = combinedRegion & regionOutput;
rule.inputRegion = std::move(inputRegion);
rule.outputRegion = std::move(outputRegion);
rule.options = mRuleOptions;

for (const auto &optionsArea : setup.mRuleOptionsAreas)
Expand Down Expand Up @@ -1474,5 +1481,3 @@ void AutoMapper::addWarning(const QString &message, std::function<void ()> callb
}

} // namespace Tiled

#include "moc_automapper.cpp"
7 changes: 4 additions & 3 deletions src/tiled/automapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "tilelayer.h"
#include "tileset.h"

#include <QCoreApplication>
#include <QList>
#include <QMap>
#include <QRegion>
Expand Down Expand Up @@ -275,9 +276,9 @@ struct TILED_EDITOR_EXPORT AutoMappingContext
* - copy regions of Maps (multiple Layers, the layerlist is a
* lookup-table for matching the Layers)
*/
class TILED_EDITOR_EXPORT AutoMapper : public QObject
class TILED_EDITOR_EXPORT AutoMapper
{
Q_OBJECT
Q_DECLARE_TR_FUNCTIONS(Tiled::AutoMapper)

public:
struct Options
Expand Down Expand Up @@ -333,7 +334,7 @@ class TILED_EDITOR_EXPORT AutoMapper : public QObject
* AutoMapper takes ownership of this map.
*/
AutoMapper(std::unique_ptr<Map> rulesMap, const QRegularExpression &mapNameFilter = {});
~AutoMapper() override;
~AutoMapper();

QString rulesMapFileName() const;
const QRegularExpression &mapNameFilter() const;
Expand Down
Loading