Browse Source

Add properties.

aster2013 11 years ago
parent
commit
564343c3a6
2 changed files with 25 additions and 1 deletions
  1. 18 0
      Source/Engine/Urho2D/TmxFile2D.cpp
  2. 7 1
      Source/Engine/Urho2D/TmxFile2D.h

+ 18 - 0
Source/Engine/Urho2D/TmxFile2D.cpp

@@ -243,6 +243,9 @@ bool TmxFile2D::LoadLayer(const XMLElement& element)
         }
     }
 
+    if (element.HasChild("properties"))
+        LoadProperties(element.GetChild("properties"), tileLayer->properties_);
+
     return true;
 }
 
@@ -304,8 +307,14 @@ bool TmxFile2D::LoadObjectGroup(const XMLElement& element)
                 object.points_[i] = point;
             }
         }
+
+        if (objectElem.HasChild("properties"))
+            LoadProperties(objectElem.GetChild("properties"), object.properties_);
     }
 
+    if (element.HasChild("properties"))
+        LoadProperties(element.GetChild("properties"), objectGroup->properties_);
+
     return true;
 }
 
@@ -339,7 +348,16 @@ bool TmxFile2D::LoadImageLayer(const XMLElement& element)
     
     imageLayer->sprite_ = sprite;
 
+    if (element.HasChild("properties"))
+        LoadProperties(element.GetChild("properties"), imageLayer->properties_);
+
     return true;
 }
 
+void TmxFile2D::LoadProperties(const XMLElement& element, HashMap<String, String>& peoperties)
+{
+    for (XMLElement propertyElem = element.GetChild("property"); propertyElem; propertyElem = propertyElem.GetNext("property"))
+        peoperties[propertyElem.GetAttribute("name")] = propertyElem.GetAttribute("value");
+}
+
 }

+ 7 - 1
Source/Engine/Urho2D/TmxFile2D.h

@@ -71,6 +71,8 @@ struct URHO3D_API TmxLayer2D
     int width_;
     /// Height.
     int height_;
+    /// Properties.
+    HashMap<String, String> properties_;
 };
 
 /// Tmx tile layer.
@@ -111,6 +113,8 @@ struct URHO3D_API TmxObject
     Vector<Vector2> points_;
     /// Gid (for tile).
     int gid_;
+    /// Properties.
+    HashMap<String, String> properties_;
 };
 
 /// Tmx image layer.
@@ -177,7 +181,9 @@ private:
     bool LoadObjectGroup(const XMLElement& element);
     /// Load image layer.
     bool LoadImageLayer(const XMLElement& element);
-    
+    /// Load properties.
+    void LoadProperties(const XMLElement& element, HashMap<String, String>& peoperties);
+
     /// XML file used during loading.
     SharedPtr<XMLFile> loadXMLFile_;
     /// Width.