summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-08-09 23:16:24 +0300
committerAndrei Karas <akaras@inbox.ru>2012-08-12 01:30:01 +0300
commit0671c9981e922e37b8caacc84abfceb60b32aaff (patch)
tree7e5b40d7131e0b6b091475df0ed27766b6845391 /src
parent5692fe8584be17966f7bed2e97d22139f71619e3 (diff)
downloadplus-0671c9981e922e37b8caacc84abfceb60b32aaff.tar.gz
plus-0671c9981e922e37b8caacc84abfceb60b32aaff.tar.bz2
plus-0671c9981e922e37b8caacc84abfceb60b32aaff.tar.xz
plus-0671c9981e922e37b8caacc84abfceb60b32aaff.zip
Add support for tileset properties.
Diffstat (limited to 'src')
-rw-r--r--src/resources/mapreader.cpp25
-rw-r--r--src/tileset.h20
2 files changed, 42 insertions, 3 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index 67959b819..4e38d5b0f 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -678,6 +678,7 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
XML::Document* doc = nullptr;
Tileset *set = nullptr;
std::string pathDir(path);
+ std::map<std::string, std::string> props;
if (xmlHasProp(node, BAD_CAST "source"))
{
@@ -723,6 +724,19 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
}
}
}
+ else if (xmlNameEqual(childNode, "properties"))
+ {
+ for_each_xml_child_node(propertyNode, childNode)
+ {
+ if (!xmlNameEqual(propertyNode, "property"))
+ continue;
+ std::string name = XML::getProperty(propertyNode, "name", "");
+ std::string value = XML::getProperty(
+ propertyNode, "value", "");
+ if (!name.empty())
+ props[name] = value;
+ }
+ }
else if (xmlNameEqual(childNode, "tile"))
{
for_each_xml_child_node(tileNode, childNode)
@@ -741,9 +755,12 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
std::string name = XML::getProperty(
propertyNode, "name", "");
int value = XML::getProperty(propertyNode, "value", 0);
- tileProperties[name] = value;
- logger->log("Tile Prop of %d \"%s\" = \"%d\"",
- tileGID, name.c_str(), value);
+ if (!name.empty())
+ {
+ tileProperties[name] = value;
+ logger->log("Tile Prop of %d \"%s\" = \"%d\"",
+ tileGID, name.c_str(), value);
+ }
}
// create animation
@@ -787,6 +804,8 @@ Tileset *MapReader::readTileset(XmlNodePtr node, const std::string &path,
delete doc;
+ if (set)
+ set->setProperties(props);
return set;
}
diff --git a/src/tileset.h b/src/tileset.h
index c21d6948a..5c21e8835 100644
--- a/src/tileset.h
+++ b/src/tileset.h
@@ -47,8 +47,28 @@ class Tileset : public ImageSet
int getFirstGid() const
{ return mFirstGid; }
+ /**
+ * Set tileset property.
+ */
+ void setProperties(std::map<std::string, std::string> props)
+ { mProperties = props; }
+
+ /**
+ * Returns property value.
+ */
+ std::string getProperty(std::string name)
+ {
+ std::map<std::string, std::string>::const_iterator
+ it = mProperties.find(name);
+ if (it == mProperties.end())
+ return "";
+ return mProperties[name];
+ }
+
private:
int mFirstGid;
+
+ std::map<std::string, std::string> mProperties;
};
#endif