TiledMapTilesetContent.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. namespace MonoGame.Extended.Content.Tiled;
  7. [XmlRoot(ElementName = "tileset")]
  8. public class TiledMapTilesetContent
  9. {
  10. public TiledMapTilesetContent()
  11. {
  12. TileOffset = new TiledMapTileOffsetContent();
  13. Tiles = new List<TiledMapTilesetTileContent>();
  14. Properties = new List<TiledMapPropertyContent>();
  15. }
  16. [XmlAttribute(AttributeName = "firstgid")]
  17. public int FirstGlobalIdentifier { get; set; }
  18. [XmlAttribute(AttributeName = "source")]
  19. public string Source { get; set; }
  20. [XmlAttribute(AttributeName = "name")]
  21. public string Name { get; set; }
  22. // Deprecated as of Tiled 1.9.0 (replaced by "class" attribute)
  23. [XmlAttribute(DataType = "string", AttributeName = "type")]
  24. public string Type { get; set; }
  25. [XmlAttribute(DataType = "string", AttributeName = "class")]
  26. public string Class { get; set; }
  27. [XmlAttribute(AttributeName = "tilewidth")]
  28. public int TileWidth { get; set; }
  29. [XmlAttribute(AttributeName = "tileheight")]
  30. public int TileHeight { get; set; }
  31. [XmlAttribute(AttributeName = "spacing")]
  32. public int Spacing { get; set; }
  33. [XmlAttribute(AttributeName = "margin")]
  34. public int Margin { get; set; }
  35. [XmlAttribute(AttributeName = "columns")]
  36. public int Columns { get; set; }
  37. [XmlAttribute(AttributeName = "tilecount")]
  38. public int TileCount { get; set; }
  39. [XmlElement(ElementName = "tileoffset")]
  40. public TiledMapTileOffsetContent TileOffset { get; set; }
  41. [XmlElement(ElementName = "grid")]
  42. public TiledMapTilesetGridContent Grid { get; set; }
  43. [XmlElement(ElementName = "tile")]
  44. public List<TiledMapTilesetTileContent> Tiles { get; set; }
  45. [XmlArray("properties")]
  46. [XmlArrayItem("property")]
  47. public List<TiledMapPropertyContent> Properties { get; set; }
  48. [XmlElement(ElementName = "image")]
  49. public TiledMapImageContent Image { get; set; }
  50. public bool ContainsGlobalIdentifier(int globalIdentifier)
  51. {
  52. return globalIdentifier >= FirstGlobalIdentifier && globalIdentifier < FirstGlobalIdentifier + TileCount;
  53. }
  54. public override string ToString()
  55. {
  56. return $"{Name}: {Image}";
  57. }
  58. }