summaryrefslogtreecommitdiff
path: root/src/resources/mapreader.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2011-02-10 08:47:35 -0700
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-02-20 00:40:10 +0100
commit81c640c96d46a8791bf29291d4c8179b77306ce7 (patch)
tree7562ccdaccfc36a3ce18c4777e7a0d080db759b7 /src/resources/mapreader.cpp
parent3c93bde383fad59972ae3004471b2bb567438b9d (diff)
downloadmana-81c640c96d46a8791bf29291d4c8179b77306ce7.tar.gz
mana-81c640c96d46a8791bf29291d4c8179b77306ce7.tar.bz2
mana-81c640c96d46a8791bf29291d4c8179b77306ce7.tar.xz
mana-81c640c96d46a8791bf29291d4c8179b77306ce7.zip
Add support for CSV map data
Reviewed-by: Freeyorp
Diffstat (limited to 'src/resources/mapreader.cpp')
-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 07a1262c..14021406 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -288,7 +288,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)
@@ -357,6 +357,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