Skip to content

Commit

Permalink
AutoMapping: Recognize "//" layer name prefix for ignoring layers
Browse files Browse the repository at this point in the history
Also made a few other small improvements:

* Unrecognized layers are now a warning instead of an error
* Warnings no longer appear twice in the popup
* Clicking on the warnings in the Issues view select the relevant
  unrecognized layer or property

Closes #3262
  • Loading branch information
bjorn committed Feb 4, 2022
1 parent b3ad516 commit 0582cf6
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 22 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Added automatic fading out of the grid when zooming out a lot
* AutoMapping: Made it find layers within groups (#1771)
* AutoMapping: `regions` layer can now be used alongside `region_input/output` layers
* AutoMapping: Recognize "//" layer name prefix for ignoring layers (#3262)
* AutoMapping: Allow setting a rule map as project rules file (#3221)
* Tweaked focus behavior in the Template Editor
* Changed the default Terrain Brush shortcut back to T
Expand Down
53 changes: 34 additions & 19 deletions src/tiled/automapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,11 @@ bool AutoMapper::setupRuleMapProperties()
}
}

QString warning = tr("Ignoring unknown property '%2' = '%3' (rule map '%1')")
.arg(mRulesMapFileName, name, value.toString());

WARNING(warning, OpenFile { mRulesMapFileName });

mWarning += warning;
mWarning += QLatin1Char('\n');
addWarning(tr("Ignoring unknown property '%2' = '%3' (rule map '%1')")
.arg(mRulesMapFileName,
name,
value.toString()),
SelectCustomProperty { mRulesMapFileName, name, mRulesMap.get() });
}

// OverflowBorder and WrapBorder make no sense for infinite maps
Expand Down Expand Up @@ -175,13 +173,12 @@ void AutoMapper::setupInputLayerProperties(InputLayer &inputLayer)
}
}

QString warning = tr("Ignoring unknown property '%2' = '%3' on layer '%4' (rule map '%1')")
.arg(mRulesMapFileName, name, value.toString(), inputLayer.tileLayer->name());

WARNING(warning, SelectLayer { inputLayer.tileLayer });

mWarning += warning;
mWarning += QLatin1Char('\n');
addWarning(tr("Ignoring unknown property '%2' = '%3' on layer '%4' (rule map '%1')")
.arg(mRulesMapFileName,
name,
value.toString(),
inputLayer.tileLayer->name()),
SelectCustomProperty { mRulesMapFileName, name, inputLayer.tileLayer });
}
}

Expand All @@ -202,6 +199,10 @@ bool AutoMapper::setupRuleMapLayers()

const QString &layerName = layer->name();

// Ignore commented out layers
if (layerName.startsWith(QLatin1String("//")))
continue;

auto checkRegionsLayer = [&](const QString &layerName, Layer *layer, const TileLayer* &out) -> bool {
if (layerName.compare(layer->name(), Qt::CaseInsensitive) != 0)
return false;
Expand All @@ -221,9 +222,13 @@ bool AutoMapper::setupRuleMapLayers()
};

if (layerName.startsWith(QLatin1String("regions"), Qt::CaseInsensitive)) {
checkRegionsLayer(QStringLiteral("regions"), layer, mLayerRegions)
|| checkRegionsLayer(QStringLiteral("regions_input"), layer, mLayerInputRegions)
|| checkRegionsLayer(QStringLiteral("regions_output"), layer, mLayerOutputRegions);
if (!(checkRegionsLayer(QStringLiteral("regions"), layer, mLayerRegions) ||
checkRegionsLayer(QStringLiteral("regions_input"), layer, mLayerInputRegions) ||
checkRegionsLayer(QStringLiteral("regions_output"), layer, mLayerOutputRegions))) {

addWarning(tr("Layer '%1' is not recognized as a valid layer for Automapping.").arg(layerName),
SelectLayer { layer });
}
continue;
}

Expand Down Expand Up @@ -295,8 +300,8 @@ bool AutoMapper::setupRuleMapLayers()
continue;
}

error += tr("Layer '%1' is not recognized as a valid layer for Automapping.")
.arg(layerName) + QLatin1Char('\n');
addWarning(tr("Layer '%1' is not recognized as a valid layer for Automapping.").arg(layerName),
SelectLayer { layer });
}

if (!mLayerRegions && !mLayerInputRegions)
Expand Down Expand Up @@ -386,6 +391,9 @@ bool AutoMapper::setupRuleList()

void AutoMapper::prepareAutoMap()
{
mWarning.clear();
mError.clear();

setupWorkMapLayers();
setupTilesets();
}
Expand Down Expand Up @@ -1003,4 +1011,11 @@ void AutoMapper::cleanEmptyLayers()
mAddedLayers.clear();
}

void AutoMapper::addWarning(const QString &message, std::function<void ()> callback)
{
WARNING(message, std::move(callback));
mWarning += message;
mWarning += QLatin1Char('\n');
}

#include "moc_automapper.cpp"
3 changes: 3 additions & 0 deletions src/tiled/automapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ class AutoMapper : public QObject
*/
void cleanEmptyLayers();

void addWarning(const QString &text,
std::function<void()> callback = std::function<void()>());

/**
* where to work in
*/
Expand Down
6 changes: 3 additions & 3 deletions src/tiled/automappingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ void AutomappingManager::autoMapInternal(const QRegion &where,
undoStack->endMacro();
}

for (auto &automapper : qAsConst(mAutoMappers)) {
mWarning += automapper->warningString();
mError += automapper->errorString();
for (auto &autoMapper : qAsConst(passedAutoMappers)) {
mWarning += autoMapper->warningString();
mError += autoMapper->errorString();
}

if (!mWarning.isEmpty())
Expand Down

0 comments on commit 0582cf6

Please sign in to comment.