TiledMapObjectContent.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) Craftwork Games. All rights reserved.
  2. // Licensed under the MIT license.
  3. // See LICENSE file in the project root for full license information.
  4. using System.Collections.Generic;
  5. using System.Xml.Serialization;
  6. using MonoGame.Extended.Content.Tiled;
  7. namespace MonoGame.Extended.Content.Tiled;
  8. // This content class is going to be a lot more complex than the others we use.
  9. // Objects can reference a template file which has starting values for the
  10. // object. The value in the object file overrides any value specified in the
  11. // template. All values have to be able to store a null value so we know if the
  12. // XML parser actually found a value for the property and not just a default
  13. // value. Default values are used when the object and any templates don't
  14. // specify a value.
  15. public class TiledMapObjectContent
  16. {
  17. // TODO: HACK These shouldn't be public
  18. public uint? _globalIdentifier;
  19. public int? _identifier;
  20. public float? _height;
  21. public float? _rotation;
  22. public bool? _visible;
  23. public float? _width;
  24. public float? _x;
  25. public float? _y;
  26. [XmlAttribute(DataType = "int", AttributeName = "id")]
  27. public int Identifier { get => _identifier ?? 0; set => _identifier = value; }
  28. [XmlAttribute(DataType = "string", AttributeName = "name")]
  29. public string Name { get; set; }
  30. // Deprecated as of Tiled 1.9.0 (replaced by "class" attribute)
  31. [XmlAttribute(DataType = "string", AttributeName = "type")]
  32. public string Type { get; set; }
  33. [XmlAttribute(DataType = "string", AttributeName = "class")]
  34. public string Class { get; set; }
  35. [XmlAttribute(DataType = "float", AttributeName = "x")]
  36. public float X { get => _x ?? 0; set => _x = value; }
  37. [XmlAttribute(DataType = "float", AttributeName = "y")]
  38. public float Y { get => _y ?? 0; set => _y = value; }
  39. [XmlAttribute(DataType = "float", AttributeName = "width")]
  40. public float Width { get => _width ?? 0; set => _width = value; }
  41. [XmlAttribute(DataType = "float", AttributeName = "height")]
  42. public float Height { get => _height ?? 0; set => _height = value; }
  43. [XmlAttribute(DataType = "float", AttributeName = "rotation")]
  44. public float Rotation { get => _rotation ?? 0; set => _rotation = value; }
  45. [XmlAttribute(DataType = "boolean", AttributeName = "visible")]
  46. public bool Visible { get => _visible ?? true; set => _visible = value; }
  47. [XmlArray("properties")]
  48. [XmlArrayItem("property")]
  49. public List<TiledMapPropertyContent> Properties { get; set; }
  50. [XmlAttribute(DataType = "unsignedInt", AttributeName = "gid")]
  51. public uint GlobalIdentifier { get => _globalIdentifier ?? 0; set => _globalIdentifier = value; }
  52. [XmlElement(ElementName = "ellipse")]
  53. public TiledMapEllipseContent Ellipse { get; set; }
  54. [XmlElement(ElementName = "polygon")]
  55. public TiledMapPolygonContent Polygon { get; set; }
  56. [XmlElement(ElementName = "polyline")]
  57. public TiledMapPolylineContent Polyline { get; set; }
  58. [XmlAttribute(DataType = "string", AttributeName = "template")]
  59. public string TemplateSource { get; set; }
  60. }