diff options
author | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-02-20 20:03:33 +0100 |
---|---|---|
committer | Yohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer> | 2011-02-20 20:03:33 +0100 |
commit | 1f2d9d4723d3fb4973f11764fed0063757b8f3a4 (patch) | |
tree | b0875e7d8311488384876a30ef5c021ca2e6d23a /src | |
parent | 30384d064a3f81e626dd38a1122e126fc1f04659 (diff) | |
download | manaserv-1f2d9d4723d3fb4973f11764fed0063757b8f3a4.tar.gz manaserv-1f2d9d4723d3fb4973f11764fed0063757b8f3a4.tar.bz2 manaserv-1f2d9d4723d3fb4973f11764fed0063757b8f3a4.tar.xz manaserv-1f2d9d4723d3fb4973f11764fed0063757b8f3a4.zip |
Adding CSV support from Jaxad's client implementation.
Reviewed-by: Jaxad0127.
Resolves: Mana-Mantis #286.
Diffstat (limited to 'src')
-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 8eae8fd1..f96de174 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; + } } } |