diff options
Diffstat (limited to 'src/resources/mapreader.cpp')
-rw-r--r-- | src/resources/mapreader.cpp | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index b7c4fd72..c866c680 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -277,9 +277,11 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) if (encoding == "base64") { - if (!compression.empty() && compression != "gzip") + if (!compression.empty() && compression != "gzip" + && compression != "zlib") { - logger->log("Warning: only gzip layer compression supported!"); + logger->log("Warning: only gzip or zlib layer " + "compression supported!"); return; } @@ -290,7 +292,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) int len = strlen((const char*)dataChild->content) + 1; unsigned char *charData = new unsigned char[len + 1]; - const char *charStart = (const char*)dataChild->content; + const char *charStart = (const char*) xmlNodeGetContent(dataChild); unsigned char *charIndex = charData; while (*charStart) @@ -313,7 +315,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) if (binData) { - if (compression == "gzip") + if (compression == "gzip" || compression == "zlib") { // Inflate the gzipped layer data unsigned char *inflated; @@ -359,6 +361,39 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) free(binData); } } + else if (encoding == "csv") + { + xmlNodePtr dataChild = childNode->xmlChildrenNode; + if (!dataChild) + continue; + + const char *data = (const char*) xmlNodeGetContent(dataChild); + std::string csv(data); + + size_t pos = 0; + size_t oldPos = 0; + + while (oldPos != csv.npos) + { + pos = csv.find_first_of(",", oldPos); + + const int gid = atoi(csv.substr(oldPos, pos - oldPos).c_str()); + + setTile(map, layer, x, y, gid); + + x++; + if (x == w) + { + x = 0; y++; + + // When we're done, don't crash on too much data + if (y == h) + break; + } + + oldPos = pos + 1; + } + } else { // Read plain XML map file |