diff --git a/src/TiledCS.csproj b/src/TiledCS.csproj index cf0637a..bf71f54 100644 --- a/src/TiledCS.csproj +++ b/src/TiledCS.csproj @@ -1,7 +1,7 @@ - 2.4.2 + 2.5.0 Ruben Labruyere Ruben Labruyere TiledCS diff --git a/src/TiledMap.cs b/src/TiledMap.cs index 0ea1fd9..0028f87 100755 --- a/src/TiledMap.cs +++ b/src/TiledMap.cs @@ -442,6 +442,9 @@ private TiledObject[] ParseObjects(XmlNodeList nodeList) foreach (XmlNode node in nodeList) { var nodesProperty = node.SelectNodes("properties/property"); + var nodePolygon = node.SelectSingleNode("polygon"); + var nodePoint = node.SelectSingleNode("point"); + var nodeEllipse = node.SelectSingleNode("ellipse"); var obj = new TiledObject(); obj.id = int.Parse(node.Attributes["id"].Value); @@ -456,6 +459,33 @@ private TiledObject[] ParseObjects(XmlNodeList nodeList) obj.properties = ParseProperties(nodesProperty); } + if (nodePolygon != null) + { + var points = nodePolygon.Attributes["points"].Value; + var vertices = points.Split(' '); + + var polygon = new TiledPolygon(); + polygon.points = new float[vertices.Length * 2]; + + for (var i = 0; i < vertices.Length; i++) + { + polygon.points[(i * 2) + 0] = float.Parse(vertices[i].Split(',')[0], CultureInfo.InvariantCulture); + polygon.points[(i * 2) + 1] = float.Parse(vertices[i].Split(',')[1], CultureInfo.InvariantCulture); + } + + obj.polygon = polygon; + } + + if (nodeEllipse != null) + { + obj.ellipse = new TiledEllipse(); + } + + if (nodePoint != null) + { + obj.point = new TiledPoint(); + } + if (node.Attributes["width"] != null) { obj.width = float.Parse(node.Attributes["width"].Value, CultureInfo.InvariantCulture); diff --git a/src/TiledModels.cs b/src/TiledModels.cs index 8f016c7..2f178f7 100644 --- a/src/TiledModels.cs +++ b/src/TiledModels.cs @@ -148,6 +148,45 @@ public class TiledObject /// An array of properties. Is null if none were defined. /// public TiledProperty[] properties; + /// + /// If an object was set to a polygon shape, this property will be set and can be used to access the polygon's data + /// + public TiledPolygon polygon; + /// + /// If an object was set to a point shape, this property will be set + /// + public TiledPoint point; + /// + /// If an object was set to an ellipse shape, this property will be set + /// + public TiledEllipse ellipse; + } + + /// + /// Represents a polygon shape + /// + public class TiledPolygon + { + /// + /// The array of vertices where each two elements represent an x and y position. Like 'x,y,x,y,x,y,x,y'. + /// + public float[] points; + } + + /// + /// Represents a point shape + /// + public class TiledPoint + { + + } + + /// + /// Represents an ellipse shape + /// + public class TiledEllipse + { + } ///