-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Wang Tiles #1582
Wang Tiles #1582
Changes from 17 commits
904e8bc
cb8d9ae
e93cc74
c329a97
4757fb6
31689c6
e10151e
c7e67d0
0ef5add
74dbae3
400d47c
ff6c624
3916cd6
acae98a
68bd9af
52ae862
4398cea
7f58709
bb6b98a
0969d46
8b959a9
1df48f5
25f8494
888ea7b
825774a
0d3f353
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
#include "tilelayer.h" | ||
#include "tilesetmanager.h" | ||
#include "terrain.h" | ||
#include "wangset.h" | ||
|
||
#include <QCoreApplication> | ||
#include <QDebug> | ||
|
@@ -84,6 +85,7 @@ class MapReaderPrivate | |
void readTilesetGrid(Tileset &tileset); | ||
void readTilesetImage(Tileset &tileset); | ||
void readTilesetTerrainTypes(Tileset &tileset); | ||
void readTilesetWangSet(Tileset &tileset); | ||
ImageReference readImage(); | ||
|
||
Layer *tryReadLayer(); | ||
|
@@ -353,6 +355,8 @@ SharedTileset MapReaderPrivate::readTileset() | |
} | ||
} else if (xml.name() == QLatin1String("terraintypes")) { | ||
readTilesetTerrainTypes(*tileset); | ||
} else if (xml.name() == QLatin1String("wangsets")) { | ||
readTilesetWangSet(*tileset); | ||
} else { | ||
readUnknownElement(); | ||
} | ||
|
@@ -564,6 +568,42 @@ void MapReaderPrivate::readTilesetTerrainTypes(Tileset &tileset) | |
} | ||
} | ||
|
||
void MapReaderPrivate::readTilesetWangSet(Tileset &tileset) | ||
{ | ||
Q_ASSERT(xml.isStartElement() && xml.name() == QLatin1String("wangsets")); | ||
|
||
while (xml.readNextStartElement()) { | ||
if (xml.name() == QLatin1String("wangset")) { | ||
const QXmlStreamAttributes atts = xml.attributes(); | ||
QString name = atts.value(QLatin1String("name")).toString(); | ||
int edges = atts.value(QLatin1String("edges")).toInt(); | ||
int corners = atts.value(QLatin1String("corners")).toInt(); | ||
int tile = atts.value(QLatin1String("tile")).toInt(); | ||
|
||
WangSet *wangSet = new WangSet(&tileset, edges, corners, name, tile); | ||
|
||
tileset.insertWangSet(wangSet); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naming: this should be called |
||
|
||
while (xml.readNextStartElement()) { | ||
if (xml.name() == QLatin1String("properties")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style: should have |
||
wangSet->mergeProperties(readProperties()); | ||
else if (xml.name() == QLatin1String("wangsettile")) { | ||
const QXmlStreamAttributes tileAtts = xml.attributes(); | ||
int tileId = tileAtts.value(QLatin1String("tileid")).toInt(); | ||
int wangId = tileAtts.value(QLatin1String("wangid")).toInt(); | ||
|
||
wangSet->addTile(tileset.tileAt(tileId), wangId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
|
||
xml.skipCurrentElement(); | ||
} else | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Coding style: Should have |
||
readUnknownElement(); | ||
} | ||
} else { | ||
readUnknownElement(); | ||
} | ||
} | ||
} | ||
|
||
static void readLayerAttributes(Layer &layer, | ||
const QXmlStreamAttributes &atts) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
#include "tilelayer.h" | ||
#include "tileset.h" | ||
#include "terrain.h" | ||
#include "wangset.h" | ||
|
||
#include <QBuffer> | ||
#include <QCoreApplication> | ||
|
@@ -361,7 +362,6 @@ void MapWriterPrivate::writeTileset(QXmlStreamWriter &w, const Tileset &tileset, | |
} | ||
w.writeEndElement(); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't remove the empty line. |
||
// Write the properties for those tiles that have them | ||
for (const Tile *tile : tileset.tiles()) { | ||
if (imageSource.isEmpty() || includeTile(tile)) { | ||
|
@@ -421,11 +421,38 @@ void MapWriterPrivate::writeTileset(QXmlStreamWriter &w, const Tileset &tileset, | |
} | ||
w.writeEndElement(); // </animation> | ||
} | ||
|
||
w.writeEndElement(); // </tile> | ||
} | ||
} | ||
|
||
// Write the wangsets | ||
if (tileset.wangSetCount() > 0) { | ||
w.writeStartElement(QLatin1String("wangsets")); | ||
for (int i = 0; i < tileset.wangSetCount(); ++i) { | ||
const WangSet *ws = tileset.wangSet(i); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we don't care about the index, please write it as a range-based for: for (const WangSet *ws : tileset.wangSets()) { |
||
w.writeStartElement(QLatin1String("wangset")); | ||
|
||
w.writeAttribute(QLatin1String("name"), ws->name()); | ||
w.writeAttribute(QLatin1String("edges"), QString::number(ws->edgeColors())); | ||
w.writeAttribute(QLatin1String("corners"), QString::number(ws->cornerColors())); | ||
w.writeAttribute(QLatin1String("tile"), QString::number(ws->imageTileId())); | ||
|
||
//write each tile with a valid wangId | ||
for (const Tile *tile : tileset.tiles()) { | ||
if (int wId = ws->wangIdOfTile(tile)) { | ||
w.writeStartElement(QLatin1String("wangsettile")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the point of this? I think all the relevant tiles are already written out above? The reader does not use the "wangsettile" elements. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept it around while I wrote the new version, and forgot to remove it after... |
||
w.writeAttribute(QLatin1String("tileid"), QString::number(tile->id())); | ||
w.writeAttribute(QLatin1String("wangid"), QString::number(wId)); | ||
w.writeEndElement(); // </wangsettile> | ||
} | ||
} | ||
writeProperties(w, ws->properties()); | ||
|
||
w.writeEndElement(); // </wangset> | ||
} | ||
w.writeEndElement(); // </wangsets> | ||
} | ||
|
||
w.writeEndElement(); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Naming: should be
readTilesetWangSets
, since it will read multiple sets.