Skip to content

Commit

Permalink
Fixed importing of flipped tile chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyPrinny committed Dec 7, 2021
1 parent 2b9c88b commit 47a963f
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/plugins/gmx/gmxplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,16 +333,17 @@ static SharedTileset tilesetWithName(const QString &bgName, Map *map, QDir &imag

static bool lesThanLayer(Layer *lay1, Layer *lay2)
{
int depth1 = 9999999;
int depth1 = 99999990;
int depth2 = depth1;

QVariant aux = lay1->inheritedProperty(QString("depth"));
QVariant aux = lay1->property(QStringLiteral("depth"));
if(aux.isValid())
depth1=aux.toInt();
aux = lay2->inheritedProperty(QString("depth"));
aux = lay2->property(QStringLiteral("depth"));
if(aux.isValid())
depth2 = aux.toInt();
return depth1>depth2;

return depth1>depth2;
}

void GmxPlugin::writeAttribute(const QString &qualifiedName, QString &value, QIODevice* d, QTextCodec* codec)
Expand Down Expand Up @@ -592,10 +593,7 @@ Tiled::Map *GmxPlugin::read(const QString &fileName, QSettings *appSettings)
int yo = QString(tile->first_attribute("yo")->value()).toInt();
int scaleX = QString(tile->first_attribute("scaleX")->value()).toInt();
int scaleY = QString(tile->first_attribute("scaleY")->value()).toInt();
if(scaleX==-1)
x-=tileWidth;
if(scaleY==-1)
y-=tileHeight;

int xoff = x%tileWidth;
int yoff = y%tileHeight;
x = (x/tileWidth)*tileWidth;
Expand All @@ -615,6 +613,24 @@ Tiled::Map *GmxPlugin::read(const QString &fileName, QSettings *appSettings)
tile = tile->next_sibling();
continue;
}

if(scaleX > 0)
{
scaleX /= abs(scaleX);
}
if(scaleY > 0)
{
scaleX /= abs(scaleX);
}

if(scaleX==-1)
{
x-=tileWidth;
}
if(scaleY==-1)
{
y-=tileHeight;
}
if(htiles > 1)
{
int xInTileset = (xo/tileWidth);
Expand Down Expand Up @@ -649,12 +665,13 @@ Tiled::Map *GmxPlugin::read(const QString &fileName, QSettings *appSettings)
}
else
{

ncell.setTile(tileset.get(),tileID);
if(scaleX==-1)
ncell.setFlippedHorizontally(true);
if(scaleY==-1)
ncell.setFlippedVertically(true);
layer->setCell(x/tileWidth+ht, y/tileHeight+vt,ncell);
layer->setCell(x/tileWidth+ht*scaleX, y/tileHeight+vt*scaleY,ncell);
}
}
}
Expand Down Expand Up @@ -822,7 +839,7 @@ Tiled::Map *GmxPlugin::read(const QString &fileName, QSettings *appSettings)
QList<Layer*> *mLayers = newMap->layersNoConst();
if(!mLayers->isEmpty())
{
std::sort(mLayers->begin(),mLayers->end(),lesThanLayer);
std::stable_sort(mLayers->begin(),mLayers->end(),lesThanLayer);
}

doc.clear();
Expand Down

0 comments on commit 47a963f

Please sign in to comment.