summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2011-02-10 08:47:35 -0700
committerAndrei Karas <akaras@inbox.ru>2011-02-10 19:38:22 +0200
commita12172bc3f8e291f464678c92d5ebf566d4cad2c (patch)
tree3d9aa7da651e193485e881380bdf572c9d05b345
parenteb1428dded5d2be98eff034fd26a08c109d2376c (diff)
downloadmanaverse-a12172bc3f8e291f464678c92d5ebf566d4cad2c.tar.gz
manaverse-a12172bc3f8e291f464678c92d5ebf566d4cad2c.tar.bz2
manaverse-a12172bc3f8e291f464678c92d5ebf566d4cad2c.tar.xz
manaverse-a12172bc3f8e291f464678c92d5ebf566d4cad2c.zip
Add support for CSV map data
Reviewed-by: Freeyorp
-rw-r--r--src/resources/mapreader.cpp35
1 files changed, 34 insertions, 1 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index a2e81ae07..c3a854c92 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -454,7 +454,7 @@ void MapReader::readLayer(xmlNodePtr node, Map *map)
int len = static_cast<int>(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)
@@ -521,6 +521,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