Skip to content

Commit

Permalink
Implemented loading for the way Tiled saves properties since version …
Browse files Browse the repository at this point in the history
…0.6.0 and

updated all current maps.
  • Loading branch information
bjorn committed Jul 19, 2006
1 parent 02ea6ce commit 6722e88
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 18 deletions.
14 changes: 13 additions & 1 deletion ChangeLog
@@ -1,8 +1,16 @@
2006-07-19 Bjørn Lindeijer <bjorn@lindeijer.nl>

* tmw.cbp: Added Code::Blocks project file.
* src/gui/minimap.cpp: Fixed dot size of local player.
* src/engine.cpp: Fixed color of "[TARGET]".
* src/resources/mapreader.cpp, src/resources/mapreader.h,
data/maps/new_12-1.tmx.gz, data/maps/new_3-1.tmx.gz,
data/maps/new_4-1.tmx.gz, data/maps/new_5-1.tmx.gz,
data/maps/new_6-1.tmx.gz, data/maps/new_7-1.tmx.gz,
data/maps/new_8-1.tmx.gz, data/maps/new_9-1.tmx.gz,
data/maps/new_1-1.tmx.gz, data/maps/new_10-1.tmx.gz,
data/maps/new_11-1.tmx.gz, data/maps/new_2-1.tmx.gz: Implemented
loading for the way Tiled saves properties since version 0.6.0 and
updated all current maps.

2006-07-19 Eugenio Favalli <elvenprogrammer@gmail.com>

Expand All @@ -19,6 +27,10 @@
character selection dialog.
* data/graphics/sprites/Makefile.am: Alphabetically correct.

2006-07-19 Bjørn Lindeijer <bjorn@lindeijer.nl>

* tmw.cbp: Added Code::Blocks project file.

2006-07-18 Bjørn Lindeijer <bjorn@lindeijer.nl>

* src/gui/updatewindow.cpp, src/gui/updatewindow.h, src/main.cpp,
Expand Down
50 changes: 33 additions & 17 deletions src/resources/mapreader.cpp
Expand Up @@ -192,26 +192,11 @@ MapReader::readMap(xmlNodePtr node, const std::string &path)
int tilew = getProperty(node, "tilewidth", DEFAULT_TILE_WIDTH);
int tileh = getProperty(node, "tileheight", DEFAULT_TILE_HEIGHT);
int layerNr = 0;
Map* map = new Map(w, h, tilew, tileh);
Map *map = new Map(w, h, tilew, tileh);

for (node = node->xmlChildrenNode; node != NULL; node = node->next)
{
if (xmlStrEqual(node->name, BAD_CAST "property"))
{
// Example: <property name="name" value="value"/>

xmlChar *name = xmlGetProp(node, BAD_CAST "name");
xmlChar *value = xmlGetProp(node, BAD_CAST "value");

if (name && value)
{
map->setProperty((const char*)name, (const char*)value);
}

if (name) xmlFree(name);
if (value) xmlFree(value);
}
else if (xmlStrEqual(node->name, BAD_CAST "tileset"))
if (xmlStrEqual(node->name, BAD_CAST "tileset"))
{
Tileset *tileset = readTileset(node, pathDir, map);
if (tileset) {
Expand All @@ -224,11 +209,42 @@ MapReader::readMap(xmlNodePtr node, const std::string &path)
readLayer(node, map, layerNr);
layerNr++;
}
else if (xmlStrEqual(node->name, BAD_CAST "properties"))
{
readProperties(node, map);
}
}

return map;
}

void
MapReader::readProperties(xmlNodePtr node, Properties* props)
{
node = node->xmlChildrenNode;

while (node != NULL)
{
if (xmlStrEqual(node->name, BAD_CAST "property"))
{
// Example: <property name="name" value="value"/>

xmlChar *name = xmlGetProp(node, BAD_CAST "name");
xmlChar *value = xmlGetProp(node, BAD_CAST "value");

if (name && value)
{
props->setProperty((const char*) name, (const char*) value);
}

if (name) xmlFree(name);
if (value) xmlFree(value);
}

node = node->next;
}
}

void
MapReader::readLayer(xmlNodePtr node, Map *map, int layer)
{
Expand Down
10 changes: 10 additions & 0 deletions src/resources/mapreader.h
Expand Up @@ -28,6 +28,7 @@

#include <libxml/tree.h>

class Properties;
class Map;
class Tileset;

Expand All @@ -51,6 +52,15 @@ class MapReader
readMap(xmlNodePtr node, const std::string &path);

private:
/**
* Reads the properties element.
*
* @param props the Properties instance to which the properties will
* be assigned
*/
static void
readProperties(xmlNodePtr node, Properties* props);

/**
* Reads a map layer.
*/
Expand Down

0 comments on commit 6722e88

Please sign in to comment.