Skip to content

Commit

Permalink
Defold plugin: Allow overriding z value also when exporting to .colle…
Browse files Browse the repository at this point in the history
…ction

See issue #3214
  • Loading branch information
bjorn committed Sep 22, 2022
1 parent 4797cf4 commit 6ed2a6f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### Unreleased

* Defold plugin: Allow overriding z value also when exporting to .collection (#3214)

### Tiled 1.9.2 (16 September 2022)

* Allow adding maps to image collection tilesets (#3447)
Expand Down
16 changes: 9 additions & 7 deletions src/plugins/defoldcollection/defoldcollectionplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@

#include "layer.h"
#include "map.h"
#include "mapobject.h"
#include "objectgroup.h"
#include "savefile.h"
#include "tile.h"
#include "tilelayer.h"
#include "grouplayer.h"

Expand Down Expand Up @@ -189,10 +186,15 @@ static QString tilesetRelativePath(const QString &filePath)
}

/*
* Returns z-Index for a layer, depending on its order in the map
* Returns z-Index for a layer, depending on its order in the map or a custom
* "z" property.
*/
static float zIndexForLayer(const Tiled::Map &map, const Tiled::Layer &inLayer, bool isTopLayer)
{
bool ok;
if (float z = inLayer.property(QStringLiteral("z")).toFloat(&ok); ok)
return z;

if (isTopLayer) {
int topLayerOrder = 0;
for (auto layer : map.layers()) {
Expand All @@ -202,10 +204,10 @@ static float zIndexForLayer(const Tiled::Map &map, const Tiled::Layer &inLayer,
return qBound(0, topLayerOrder, 9999) * 0.0001f;
topLayerOrder++;
}
} else if (inLayer.parentLayer()) {
float zIndex = zIndexForLayer(map, *inLayer.parentLayer(), true);
} else if (auto parentLayer = inLayer.parentLayer()) {
float zIndex = zIndexForLayer(map, *parentLayer, true);
int subLayerOrder = 0;
for (auto subLayer : inLayer.parentLayer()->layers()) {
for (auto subLayer : parentLayer->layers()) {
if (subLayer == &inLayer) {
zIndex += qBound(0, subLayerOrder, 9999) * 0.00000001f;
return zIndex;
Expand Down

0 comments on commit 6ed2a6f

Please sign in to comment.