summaryrefslogtreecommitdiff
path: root/Plugins/MonoGame.Extended/source/MonoGame.Extended.Tiled/Serialization/TiledMapObjectContent.cs
blob: 76e2ba2ce34652e1334f9272b290967d0f7b43ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace MonoGame.Extended.Tiled.Serialization
{
	// This content class is going to be a lot more complex than the others we use.
	// Objects can reference a template file which has starting values for the
	// object. The value in the object file overrides any value specified in the
	// template. All values have to be able to store a null value so we know if the
	// XML parser actually found a value for the property and not just a default
	// value. Default values are used when the object and any templates don't 
	// specify a value.
	public class TiledMapObjectContent
	{
        // TODO: HACK These shouldn't be public
		public uint? _globalIdentifier;
	    public int? _identifier;
	    public float? _height;
	    public float? _rotation;
	    public bool? _visible;
	    public float? _width;
	    public float? _x;
	    public float? _y;

		[XmlAttribute(DataType = "int", AttributeName = "id")]
		public int Identifier { get => _identifier ?? 0; set => _identifier = value; }

		[XmlAttribute(DataType = "string", AttributeName = "name")]
		public string Name { get; set; }

        // Deprecated as of Tiled 1.9.0 (replaced by "class" attribute)
		[XmlAttribute(DataType = "string", AttributeName = "type")]
		public string Type { get; set; }

		[XmlAttribute(DataType = "string", AttributeName = "class")]
		public string Class { get; set; }

		[XmlAttribute(DataType = "float", AttributeName = "x")]
		public float X { get => _x ?? 0; set => _x = value; }

		[XmlAttribute(DataType = "float", AttributeName = "y")]
		public float Y { get => _y ?? 0; set => _y = value; }

		[XmlAttribute(DataType = "float", AttributeName = "width")]
		public float Width { get => _width ?? 0; set => _width = value; }

		[XmlAttribute(DataType = "float", AttributeName = "height")]
		public float Height { get => _height ?? 0; set => _height = value; }

		[XmlAttribute(DataType = "float", AttributeName = "rotation")]
		public float Rotation { get => _rotation ?? 0; set => _rotation = value; }

		[XmlAttribute(DataType = "boolean", AttributeName = "visible")]
		public bool Visible { get => _visible ?? true; set => _visible = value; }

		[XmlArray("properties")]
		[XmlArrayItem("property")]
		public List<TiledMapPropertyContent> Properties { get; set; }

		[XmlAttribute(DataType = "unsignedInt", AttributeName = "gid")]
		public uint GlobalIdentifier { get => _globalIdentifier??0; set => _globalIdentifier = value; }

		[XmlElement(ElementName = "ellipse")]
		public TiledMapEllipseContent Ellipse { get; set; }

		[XmlElement(ElementName = "polygon")]
		public TiledMapPolygonContent Polygon { get; set; }

		[XmlElement(ElementName = "polyline")]
		public TiledMapPolylineContent Polyline { get; set; }

		[XmlAttribute(DataType = "string", AttributeName = "template")]
		public string TemplateSource { get; set; }


	}
}