diff options
-rw-r--r-- | src/game-server/mapreader.cpp | 53 |
1 files changed, 45 insertions, 8 deletions
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp index 8eae8fd..f96de17 100644 --- a/src/game-server/mapreader.cpp +++ b/src/game-server/mapreader.cpp @@ -488,25 +488,62 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) free(binData); return; } + else if (encoding == "csv") + { + xmlNodePtr dataChild = node->xmlChildrenNode; + if (!dataChild) + return; - // Read plain XML map file - node = node->xmlChildrenNode; + const char *data = (const char*) xmlNodeGetContent(dataChild); + std::string csv(data); - while (node) - { - if (xmlStrEqual(node->name, BAD_CAST "tile") && y < h) + size_t pos = 0; + size_t oldPos = 0; + + while (oldPos != csv.npos) { - int gid = XML::getProperty(node, "gid", -1); + pos = csv.find_first_of(",", oldPos); + + const int gid = atoi(csv.substr(oldPos, pos - oldPos).c_str()); + setTileWithGid(map, x, y, gid); - if (++x == w) + 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 + { - node = node->next; + // Read plain XML map file + node = node->xmlChildrenNode; + + while (node) + { + if (xmlStrEqual(node->name, BAD_CAST "tile") && y < h) + { + int gid = XML::getProperty(node, "gid", -1); + setTileWithGid(map, x, y, gid); + + if (++x == w) + { + x = 0; + ++y; + } + } + + node = node->next; + } } } |