diff options
author | Jared Adams <jaxad0127@gmail.com> | 2011-02-10 08:47:35 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2011-02-10 10:11:51 -0700 |
commit | 13a9a40fb01912aa9fb879426eddf2e43cd30109 (patch) | |
tree | 90b102f1d324de3d6e63ee9bbf556c636eef6f59 | |
parent | 27d3e801629cc952979f48bb507dae782bbab34a (diff) | |
download | mana-13a9a40fb01912aa9fb879426eddf2e43cd30109.tar.gz mana-13a9a40fb01912aa9fb879426eddf2e43cd30109.tar.bz2 mana-13a9a40fb01912aa9fb879426eddf2e43cd30109.tar.xz mana-13a9a40fb01912aa9fb879426eddf2e43cd30109.zip |
Add support for CSV map data
Reviewed-by: Freeyorp
-rw-r--r-- | src/resources/mapreader.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index b0720af5..6c06ec50 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -290,7 +290,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) @@ -359,6 +359,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 |