TiledXmlContent.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Xml.Serialization;
  4. using Microsoft.Xna.Framework.Graphics;
  5. namespace MonoGame.Extended.Tilemaps.Tiled;
  6. // XML deserialization models for Tiled TMX/TSX files
  7. // These classes are public to support XML serialization, but represent internal parsing structures
  8. #region Map
  9. /// <summary>
  10. /// Represents the root map element from a Tiled TMX file.
  11. /// </summary>
  12. [XmlRoot("map")]
  13. public class TiledMapXml
  14. {
  15. /// <summary>
  16. /// Gets or sets the TMX format version.
  17. /// </summary>
  18. [XmlAttribute("version")]
  19. public string Version { get; set; }
  20. /// <summary>
  21. /// Gets or sets the Tiled version used to save the file.
  22. /// </summary>
  23. [XmlAttribute("tiledversion")]
  24. public string TiledVersion { get; set; }
  25. /// <summary>
  26. /// Gets or sets the map orientation (orthogonal, isometric, staggered, hexagonal).
  27. /// </summary>
  28. [XmlAttribute("orientation")]
  29. public string Orientation { get; set; }
  30. /// <summary>
  31. /// Gets or sets the tile render order (right-down, right-up, left-down, left-up).
  32. /// </summary>
  33. [XmlAttribute("renderorder")]
  34. public string RenderOrder { get; set; }
  35. /// <summary>
  36. /// Gets or sets the map width in tiles.
  37. /// </summary>
  38. [XmlAttribute("width")]
  39. public int Width { get; set; }
  40. /// <summary>
  41. /// Gets or sets the map height in tiles.
  42. /// </summary>
  43. [XmlAttribute("height")]
  44. public int Height { get; set; }
  45. /// <summary>
  46. /// Gets or sets the tile width in pixels.
  47. /// </summary>
  48. [XmlAttribute("tilewidth")]
  49. public int TileWidth { get; set; }
  50. /// <summary>
  51. /// Gets or sets the tile height in pixels.
  52. /// </summary>
  53. [XmlAttribute("tileheight")]
  54. public int TileHeight { get; set; }
  55. /// <summary>
  56. /// Gets or sets whether the map is infinite (1) or fixed size (0).
  57. /// </summary>
  58. [XmlAttribute("infinite")]
  59. public int Infinite { get; set; }
  60. /// <summary>
  61. /// Gets or sets the background color in #AARRGGBB or #RRGGBB format.
  62. /// </summary>
  63. [XmlAttribute("backgroundcolor")]
  64. public string BackgroundColor { get; set; }
  65. /// <summary>
  66. /// Gets or sets the next available layer ID.
  67. /// </summary>
  68. [XmlAttribute("nextlayerid")]
  69. public int NextLayerId { get; set; }
  70. /// <summary>
  71. /// Gets or sets the next available object ID.
  72. /// </summary>
  73. [XmlAttribute("nextobjectid")]
  74. public int NextObjectId { get; set; }
  75. /// <summary>
  76. /// Gets or sets the custom properties for this map.
  77. /// </summary>
  78. [XmlElement("properties")]
  79. public TiledPropertiesXml Properties { get; set; }
  80. /// <summary>
  81. /// Gets or sets the collection of tilesets used by this map.
  82. /// </summary>
  83. [XmlElement("tileset")]
  84. public List<TiledTilesetRefXml> Tilesets { get; set; } = new List<TiledTilesetRefXml>();
  85. /// <summary>
  86. /// Gets or sets the collection of layers in this map.
  87. /// </summary>
  88. [XmlElement("layer", typeof(TiledTileLayerXml))]
  89. [XmlElement("objectgroup", typeof(TiledObjectLayerXml))]
  90. [XmlElement("imagelayer", typeof(TiledImageLayerXml))]
  91. [XmlElement("group", typeof(TiledGroupLayerXml))]
  92. public List<TiledLayerXml> Layers { get; set; } = new List<TiledLayerXml>();
  93. }
  94. #endregion
  95. #region Tileset
  96. /// <summary>
  97. /// Represents a tileset element from a Tiled TMX or TSX file.
  98. /// </summary>
  99. [XmlRoot("tileset")]
  100. public class TiledTilesetXml
  101. {
  102. /// <summary>
  103. /// Gets or sets the first global tile ID of this tileset.
  104. /// </summary>
  105. [XmlAttribute("firstgid")]
  106. public int FirstGlobalId { get; set; }
  107. /// <summary>
  108. /// Gets or sets the name of the tileset.
  109. /// </summary>
  110. [XmlAttribute("name")]
  111. public string Name { get; set; }
  112. /// <summary>
  113. /// Gets or sets the width of tiles in this tileset in pixels.
  114. /// </summary>
  115. [XmlAttribute("tilewidth")]
  116. public int TileWidth { get; set; }
  117. /// <summary>
  118. /// Gets or sets the height of tiles in this tileset in pixels.
  119. /// </summary>
  120. [XmlAttribute("tileheight")]
  121. public int TileHeight { get; set; }
  122. /// <summary>
  123. /// Gets or sets the total number of tiles in this tileset.
  124. /// </summary>
  125. [XmlAttribute("tilecount")]
  126. public int TileCount { get; set; }
  127. /// <summary>
  128. /// Gets or sets the number of tile columns in the tileset image.
  129. /// </summary>
  130. [XmlAttribute("columns")]
  131. public int Columns { get; set; }
  132. /// <summary>
  133. /// Gets or sets the spacing in pixels between tiles in the tileset image.
  134. /// </summary>
  135. [XmlAttribute("spacing")]
  136. public int Spacing { get; set; }
  137. /// <summary>
  138. /// Gets or sets the margin in pixels around tiles in the tileset image.
  139. /// </summary>
  140. [XmlAttribute("margin")]
  141. public int Margin { get; set; }
  142. /// <summary>
  143. /// Gets or sets the alignment for tile objects (unspecified, topleft, top, topright, left, center, right, bottomleft, bottom, bottomright).
  144. /// </summary>
  145. [XmlAttribute("objectalignment")]
  146. public string ObjectAlignment { get; set; }
  147. /// <summary>
  148. /// Gets or sets the tile offset configuration.
  149. /// </summary>
  150. [XmlElement("tileoffset")]
  151. public TiledTileOffsetXml TileOffset { get; set; }
  152. /// <summary>
  153. /// Gets or sets the grid configuration for isometric or staggered tilesets.
  154. /// </summary>
  155. [XmlElement("grid")]
  156. public TiledGridXml Grid { get; set; }
  157. /// <summary>
  158. /// Gets or sets the tileset image.
  159. /// </summary>
  160. [XmlElement("image")]
  161. public TiledImageXml Image { get; set; }
  162. /// <summary>
  163. /// Gets or sets the collection of individual tile data (animations, collisions, properties).
  164. /// </summary>
  165. [XmlElement("tile")]
  166. public List<TiledTileXml> Tiles { get; set; } = new List<TiledTileXml>();
  167. /// <summary>
  168. /// Gets or sets the custom properties for this tileset.
  169. /// </summary>
  170. [XmlElement("properties")]
  171. public TiledPropertiesXml Properties { get; set; }
  172. /// <summary>
  173. /// Gets or sets the loaded texture for this tileset.
  174. /// </summary>
  175. /// <remarks>
  176. /// This property is set during parsing and is not part of the TMX file format.
  177. /// </remarks>
  178. [XmlIgnore]
  179. public Texture2D Texture { get; set; }
  180. }
  181. /// <summary>
  182. /// Represents a tileset reference in a Tiled TMX file (can be inline or external).
  183. /// </summary>
  184. public class TiledTilesetRefXml : TiledTilesetXml
  185. {
  186. /// <summary>
  187. /// Gets or sets the path to an external TSX file.
  188. /// </summary>
  189. /// <remarks>
  190. /// If this property is set, the tileset data is loaded from the external file.
  191. /// Otherwise, the tileset is defined inline in the TMX file.
  192. /// </remarks>
  193. [XmlAttribute("source")]
  194. public string Source { get; set; }
  195. /// <summary>
  196. /// Gets or sets the tileset data loaded from an external TSX file.
  197. /// </summary>
  198. /// <remarks>
  199. /// This property is populated during parsing when <see cref="Source"/> is specified.
  200. /// </remarks>
  201. [XmlIgnore]
  202. public TiledTilesetXml TilesetData { get; set; }
  203. }
  204. /// <summary>
  205. /// Represents the tile offset configuration for a tileset.
  206. /// </summary>
  207. public class TiledTileOffsetXml
  208. {
  209. /// <summary>
  210. /// Gets or sets the horizontal offset in pixels.
  211. /// </summary>
  212. [XmlAttribute("x")]
  213. public int X { get; set; }
  214. /// <summary>
  215. /// Gets or sets the vertical offset in pixels.
  216. /// </summary>
  217. [XmlAttribute("y")]
  218. public int Y { get; set; }
  219. }
  220. /// <summary>
  221. /// Represents the grid configuration for isometric or staggered tilesets.
  222. /// </summary>
  223. public class TiledGridXml
  224. {
  225. /// <summary>
  226. /// Gets or sets the grid orientation (orthogonal or isometric).
  227. /// </summary>
  228. [XmlAttribute("orientation")]
  229. public string Orientation { get; set; }
  230. /// <summary>
  231. /// Gets or sets the grid width in pixels.
  232. /// </summary>
  233. [XmlAttribute("width")]
  234. public int Width { get; set; }
  235. /// <summary>
  236. /// Gets or sets the grid height in pixels.
  237. /// </summary>
  238. [XmlAttribute("height")]
  239. public int Height { get; set; }
  240. }
  241. #endregion
  242. #region Tile
  243. /// <summary>
  244. /// Represents an individual tile definition within a tileset.
  245. /// </summary>
  246. public class TiledTileXml
  247. {
  248. /// <summary>
  249. /// Gets or sets the local tile ID within the tileset.
  250. /// </summary>
  251. [XmlAttribute("id")]
  252. public int Id { get; set; }
  253. /// <summary>
  254. /// Gets or sets the tile type (deprecated, use <see cref="Class"/> instead).
  255. /// </summary>
  256. [XmlAttribute("type")]
  257. public string Type { get; set; }
  258. /// <summary>
  259. /// Gets or sets the tile class (Tiled 1.9+).
  260. /// </summary>
  261. [XmlAttribute("class")]
  262. public string Class { get; set; }
  263. /// <summary>
  264. /// Gets or sets the probability that this tile is chosen over others when painting with random mode.
  265. /// </summary>
  266. [XmlAttribute("probability")]
  267. public float Probability { get; set; }
  268. /// <summary>
  269. /// Gets or sets the custom properties for this tile.
  270. /// </summary>
  271. [XmlElement("properties")]
  272. public TiledPropertiesXml Properties { get; set; }
  273. /// <summary>
  274. /// Gets or sets the image for this tile (for image collection tilesets).
  275. /// </summary>
  276. [XmlElement("image")]
  277. public TiledImageXml Image { get; set; }
  278. /// <summary>
  279. /// Gets or sets the collision object group for this tile.
  280. /// </summary>
  281. [XmlElement("objectgroup")]
  282. public TiledObjectGroupXml ObjectGroup { get; set; }
  283. /// <summary>
  284. /// Gets or sets the animation data for this tile.
  285. /// </summary>
  286. [XmlElement("animation")]
  287. public TiledAnimationXml Animation { get; set; }
  288. }
  289. /// <summary>
  290. /// Represents a tile animation sequence.
  291. /// </summary>
  292. public class TiledAnimationXml
  293. {
  294. /// <summary>
  295. /// Gets or sets the collection of animation frames.
  296. /// </summary>
  297. [XmlElement("frame")]
  298. public List<TiledAnimationFrameXml> Frames { get; set; } = new List<TiledAnimationFrameXml>();
  299. }
  300. /// <summary>
  301. /// Represents a single frame in a tile animation.
  302. /// </summary>
  303. public class TiledAnimationFrameXml
  304. {
  305. /// <summary>
  306. /// Gets or sets the local tile ID for this frame.
  307. /// </summary>
  308. [XmlAttribute("tileid")]
  309. public int TileId { get; set; }
  310. /// <summary>
  311. /// Gets or sets the duration of this frame in milliseconds.
  312. /// </summary>
  313. [XmlAttribute("duration")]
  314. public int Duration { get; set; }
  315. }
  316. #endregion
  317. #region Layers
  318. /// <summary>
  319. /// Base class for all Tiled layer types.
  320. /// </summary>
  321. public class TiledLayerXml
  322. {
  323. /// <summary>
  324. /// Gets or sets the unique layer ID.
  325. /// </summary>
  326. [XmlAttribute("id")]
  327. public int Id { get; set; }
  328. /// <summary>
  329. /// Gets or sets the layer name.
  330. /// </summary>
  331. [XmlAttribute("name")]
  332. public string Name { get; set; }
  333. /// <summary>
  334. /// Gets or sets the layer class (Tiled 1.9+).
  335. /// </summary>
  336. [XmlAttribute("class")]
  337. public string Class { get; set; }
  338. /// <summary>
  339. /// Gets or sets the horizontal offset in pixels.
  340. /// </summary>
  341. [XmlAttribute("offsetx")]
  342. public float OffsetX { get; set; }
  343. /// <summary>
  344. /// Gets or sets the vertical offset in pixels.
  345. /// </summary>
  346. [XmlAttribute("offsety")]
  347. public float OffsetY { get; set; }
  348. /// <summary>
  349. /// Gets or sets the horizontal parallax factor (Tiled 1.5+).
  350. /// </summary>
  351. [XmlAttribute("parallaxx")]
  352. public float ParallaxX { get; set; } = 1.0f;
  353. /// <summary>
  354. /// Gets or sets the vertical parallax factor (Tiled 1.5+).
  355. /// </summary>
  356. [XmlAttribute("parallaxy")]
  357. public float ParallaxY { get; set; } = 1.0f;
  358. /// <summary>
  359. /// Gets or sets the layer opacity (0.0 to 1.0).
  360. /// </summary>
  361. [XmlAttribute("opacity")]
  362. public float Opacity { get; set; } = 1.0f;
  363. /// <summary>
  364. /// Gets or sets whether the layer is visible (1 = visible, 0 = hidden).
  365. /// </summary>
  366. [XmlAttribute("visible")]
  367. public int Visible { get; set; } = 1;
  368. /// <summary>
  369. /// Gets or sets the layer tint color in #AARRGGBB or #RRGGBB format.
  370. /// </summary>
  371. [XmlAttribute("tintcolor")]
  372. public string TintColor { get; set; }
  373. /// <summary>
  374. /// Gets or sets the custom properties for this layer.
  375. /// </summary>
  376. [XmlElement("properties")]
  377. public TiledPropertiesXml Properties { get; set; }
  378. }
  379. /// <summary>
  380. /// Represents a tile layer from a Tiled TMX file.
  381. /// </summary>
  382. public class TiledTileLayerXml : TiledLayerXml
  383. {
  384. /// <summary>
  385. /// Gets or sets the layer width in tiles.
  386. /// </summary>
  387. [XmlAttribute("width")]
  388. public int Width { get; set; }
  389. /// <summary>
  390. /// Gets or sets the layer height in tiles.
  391. /// </summary>
  392. [XmlAttribute("height")]
  393. public int Height { get; set; }
  394. /// <summary>
  395. /// Gets or sets the tile data for this layer.
  396. /// </summary>
  397. [XmlElement("data")]
  398. public TiledTileLayerDataXml Data { get; set; }
  399. }
  400. /// <summary>
  401. /// Represents the tile data element of a tile layer.
  402. /// </summary>
  403. public class TiledTileLayerDataXml
  404. {
  405. /// <summary>
  406. /// Gets or sets the encoding format (csv, base64, or null for XML).
  407. /// </summary>
  408. [XmlAttribute("encoding")]
  409. public string Encoding { get; set; }
  410. /// <summary>
  411. /// Gets or sets the compression format (gzip, zlib, or null for uncompressed).
  412. /// </summary>
  413. [XmlAttribute("compression")]
  414. public string Compression { get; set; }
  415. /// <summary>
  416. /// Gets or sets the tile data as a string (for CSV or Base64 encoding).
  417. /// </summary>
  418. [XmlText]
  419. public string Value { get; set; }
  420. /// <summary>
  421. /// Gets or sets the tile data as individual tile elements (for XML encoding).
  422. /// </summary>
  423. [XmlElement("tile")]
  424. public List<TiledDataTileXml> Tiles { get; set; } = new List<TiledDataTileXml>();
  425. /// <summary>
  426. /// Gets or sets the chunk data (for infinite maps).
  427. /// </summary>
  428. [XmlElement("chunk")]
  429. public List<TiledChunkXml> Chunks { get; set; } = new List<TiledChunkXml>();
  430. }
  431. /// <summary>
  432. /// Represents a single tile element in XML-encoded tile data.
  433. /// </summary>
  434. public class TiledDataTileXml
  435. {
  436. /// <summary>
  437. /// Gets or sets the global tile ID (includes flip flags in high bits).
  438. /// </summary>
  439. [XmlAttribute("gid")]
  440. public uint Gid { get; set; }
  441. }
  442. /// <summary>
  443. /// Represents a chunk of tiles in an infinite map.
  444. /// </summary>
  445. public class TiledChunkXml
  446. {
  447. /// <summary>
  448. /// Gets or sets the X coordinate of the chunk in tiles.
  449. /// </summary>
  450. [XmlAttribute("x")]
  451. public int X { get; set; }
  452. /// <summary>
  453. /// Gets or sets the Y coordinate of the chunk in tiles.
  454. /// </summary>
  455. [XmlAttribute("y")]
  456. public int Y { get; set; }
  457. /// <summary>
  458. /// Gets or sets the chunk width in tiles.
  459. /// </summary>
  460. [XmlAttribute("width")]
  461. public int Width { get; set; }
  462. /// <summary>
  463. /// Gets or sets the chunk height in tiles.
  464. /// </summary>
  465. [XmlAttribute("height")]
  466. public int Height { get; set; }
  467. /// <summary>
  468. /// Gets or sets the tile data for this chunk.
  469. /// </summary>
  470. [XmlText]
  471. public string Value { get; set; }
  472. }
  473. /// <summary>
  474. /// Represents an object layer from a Tiled TMX file.
  475. /// </summary>
  476. public class TiledObjectLayerXml : TiledLayerXml
  477. {
  478. /// <summary>
  479. /// Gets or sets the layer color in #AARRGGBB or #RRGGBB format.
  480. /// </summary>
  481. [XmlAttribute("color")]
  482. public string Color { get; set; }
  483. /// <summary>
  484. /// Gets or sets the draw order (topdown or index).
  485. /// </summary>
  486. [XmlAttribute("draworder")]
  487. public string DrawOrder { get; set; }
  488. /// <summary>
  489. /// Gets or sets the collection of objects in this layer.
  490. /// </summary>
  491. [XmlElement("object")]
  492. public List<TiledObjectXml> Objects { get; set; } = new List<TiledObjectXml>();
  493. }
  494. /// <summary>
  495. /// Represents an image layer from a Tiled TMX file.
  496. /// </summary>
  497. public class TiledImageLayerXml : TiledLayerXml
  498. {
  499. /// <summary>
  500. /// Gets or sets whether the image repeats horizontally (Tiled 1.8+).
  501. /// </summary>
  502. [XmlAttribute("repeatx")]
  503. public int RepeatX { get; set; }
  504. /// <summary>
  505. /// Gets or sets whether the image repeats vertically (Tiled 1.8+).
  506. /// </summary>
  507. [XmlAttribute("repeaty")]
  508. public int RepeatY { get; set; }
  509. /// <summary>
  510. /// Gets or sets the image for this layer.
  511. /// </summary>
  512. [XmlElement("image")]
  513. public TiledImageXml Image { get; set; }
  514. /// <summary>
  515. /// Gets or sets the loaded texture for this layer.
  516. /// </summary>
  517. /// <remarks>
  518. /// This property is set during parsing and is not part of the TMX file format.
  519. /// </remarks>
  520. [XmlIgnore]
  521. public Texture2D Texture { get; set; }
  522. }
  523. /// <summary>
  524. /// Represents a group layer from a Tiled TMX file.
  525. /// </summary>
  526. public class TiledGroupLayerXml : TiledLayerXml
  527. {
  528. /// <summary>
  529. /// Gets or sets the child layers in this group.
  530. /// </summary>
  531. [XmlElement("layer", typeof(TiledTileLayerXml))]
  532. [XmlElement("objectgroup", typeof(TiledObjectLayerXml))]
  533. [XmlElement("imagelayer", typeof(TiledImageLayerXml))]
  534. [XmlElement("group", typeof(TiledGroupLayerXml))]
  535. public List<TiledLayerXml> Layers { get; set; } = new List<TiledLayerXml>();
  536. }
  537. #endregion
  538. #region Objects
  539. /// <summary>
  540. /// Represents an object group element (used for tile collision objects).
  541. /// </summary>
  542. public class TiledObjectGroupXml
  543. {
  544. /// <summary>
  545. /// Gets or sets the draw order (topdown or index).
  546. /// </summary>
  547. [XmlAttribute("draworder")]
  548. public string DrawOrder { get; set; }
  549. /// <summary>
  550. /// Gets or sets the collection of objects in this group.
  551. /// </summary>
  552. [XmlElement("object")]
  553. public List<TiledObjectXml> Objects { get; set; } = new List<TiledObjectXml>();
  554. }
  555. /// <summary>
  556. /// Represents an object from a Tiled TMX file.
  557. /// </summary>
  558. public class TiledObjectXml
  559. {
  560. /// <summary>
  561. /// Gets or sets the unique object ID.
  562. /// </summary>
  563. [XmlAttribute("id")]
  564. public int Id { get; set; }
  565. /// <summary>
  566. /// Gets or sets the object name.
  567. /// </summary>
  568. [XmlAttribute("name")]
  569. public string Name { get; set; }
  570. /// <summary>
  571. /// Gets or sets the object type (deprecated, use <see cref="Class"/> instead).
  572. /// </summary>
  573. [XmlAttribute("type")]
  574. public string Type { get; set; }
  575. /// <summary>
  576. /// Gets or sets the object class (Tiled 1.9+).
  577. /// </summary>
  578. [XmlAttribute("class")]
  579. public string Class { get; set; }
  580. /// <summary>
  581. /// Gets or sets the X coordinate in pixels.
  582. /// </summary>
  583. [XmlAttribute("x")]
  584. public float X { get; set; }
  585. /// <summary>
  586. /// Gets or sets the Y coordinate in pixels.
  587. /// </summary>
  588. [XmlAttribute("y")]
  589. public float Y { get; set; }
  590. /// <summary>
  591. /// Gets or sets the width in pixels.
  592. /// </summary>
  593. [XmlAttribute("width")]
  594. public float Width { get; set; }
  595. /// <summary>
  596. /// Gets or sets the height in pixels.
  597. /// </summary>
  598. [XmlAttribute("height")]
  599. public float Height { get; set; }
  600. /// <summary>
  601. /// Gets or sets the rotation in degrees (clockwise).
  602. /// </summary>
  603. [XmlAttribute("rotation")]
  604. public float Rotation { get; set; }
  605. /// <summary>
  606. /// Gets or sets the global tile ID (for tile objects).
  607. /// </summary>
  608. [XmlAttribute("gid")]
  609. public uint Gid { get; set; }
  610. /// <summary>
  611. /// Gets or sets whether the object is visible (1 = visible, 0 = hidden).
  612. /// </summary>
  613. [XmlAttribute("visible")]
  614. public int Visible { get; set; } = 1;
  615. /// <summary>
  616. /// Gets or sets the custom properties for this object.
  617. /// </summary>
  618. [XmlElement("properties")]
  619. public TiledPropertiesXml Properties { get; set; }
  620. /// <summary>
  621. /// Gets or sets the ellipse marker (presence indicates ellipse object).
  622. /// </summary>
  623. [XmlElement("ellipse")]
  624. public TiledEllipseXml Ellipse { get; set; }
  625. /// <summary>
  626. /// Gets or sets the point marker (presence indicates point object).
  627. /// </summary>
  628. [XmlElement("point")]
  629. public TiledPointXml Point { get; set; }
  630. /// <summary>
  631. /// Gets or sets the polygon data (for polygon objects).
  632. /// </summary>
  633. [XmlElement("polygon")]
  634. public TiledPolygonXml Polygon { get; set; }
  635. /// <summary>
  636. /// Gets or sets the polyline data (for polyline objects).
  637. /// </summary>
  638. [XmlElement("polyline")]
  639. public TiledPolylineXml Polyline { get; set; }
  640. /// <summary>
  641. /// Gets or sets the text data (for text objects).
  642. /// </summary>
  643. [XmlElement("text")]
  644. public TiledTextXml Text { get; set; }
  645. }
  646. /// <summary>
  647. /// Marker class indicating an ellipse object.
  648. /// </summary>
  649. public class TiledEllipseXml
  650. {
  651. // Empty element - presence indicates ellipse
  652. }
  653. /// <summary>
  654. /// Marker class indicating a point object.
  655. /// </summary>
  656. public class TiledPointXml
  657. {
  658. // Empty element - presence indicates point
  659. }
  660. /// <summary>
  661. /// Represents polygon point data.
  662. /// </summary>
  663. public class TiledPolygonXml
  664. {
  665. /// <summary>
  666. /// Gets or sets the polygon points as a space-separated list of "x,y" pairs.
  667. /// </summary>
  668. [XmlAttribute("points")]
  669. public string Points { get; set; }
  670. }
  671. /// <summary>
  672. /// Represents polyline point data.
  673. /// </summary>
  674. public class TiledPolylineXml
  675. {
  676. /// <summary>
  677. /// Gets or sets the polyline points as a space-separated list of "x,y" pairs.
  678. /// </summary>
  679. [XmlAttribute("points")]
  680. public string Points { get; set; }
  681. }
  682. /// <summary>
  683. /// Represents text object data.
  684. /// </summary>
  685. public class TiledTextXml
  686. {
  687. /// <summary>
  688. /// Gets or sets the font family.
  689. /// </summary>
  690. [XmlAttribute("fontfamily")]
  691. public string FontFamily { get; set; }
  692. /// <summary>
  693. /// Gets or sets the font size in pixels.
  694. /// </summary>
  695. [XmlAttribute("pixelsize")]
  696. public int PixelSize { get; set; } = 16;
  697. /// <summary>
  698. /// Gets or sets whether text wrapping is enabled.
  699. /// </summary>
  700. [XmlAttribute("wrap")]
  701. public int Wrap { get; set; }
  702. /// <summary>
  703. /// Gets or sets the text color in #AARRGGBB or #RRGGBB format.
  704. /// </summary>
  705. [XmlAttribute("color")]
  706. public string Color { get; set; } = "#000000";
  707. /// <summary>
  708. /// Gets or sets whether the text is bold.
  709. /// </summary>
  710. [XmlAttribute("bold")]
  711. public int Bold { get; set; }
  712. /// <summary>
  713. /// Gets or sets whether the text is italic.
  714. /// </summary>
  715. [XmlAttribute("italic")]
  716. public int Italic { get; set; }
  717. /// <summary>
  718. /// Gets or sets whether the text is underlined.
  719. /// </summary>
  720. [XmlAttribute("underline")]
  721. public int Underline { get; set; }
  722. /// <summary>
  723. /// Gets or sets whether the text has a strikethrough.
  724. /// </summary>
  725. [XmlAttribute("strikeout")]
  726. public int Strikeout { get; set; }
  727. /// <summary>
  728. /// Gets or sets whether kerning is enabled.
  729. /// </summary>
  730. [XmlAttribute("kerning")]
  731. public int Kerning { get; set; } = 1;
  732. /// <summary>
  733. /// Gets or sets the horizontal alignment (left, center, right, justify).
  734. /// </summary>
  735. [XmlAttribute("halign")]
  736. public string HAlign { get; set; } = "left";
  737. /// <summary>
  738. /// Gets or sets the vertical alignment (top, center, bottom).
  739. /// </summary>
  740. [XmlAttribute("valign")]
  741. public string VAlign { get; set; } = "top";
  742. /// <summary>
  743. /// Gets or sets the text content.
  744. /// </summary>
  745. [XmlText]
  746. public string Value { get; set; }
  747. }
  748. #endregion
  749. #region Image
  750. /// <summary>
  751. /// Represents an image element from a Tiled TMX file.
  752. /// </summary>
  753. public class TiledImageXml
  754. {
  755. /// <summary>
  756. /// Gets or sets the image source path (relative to the TMX/TSX file).
  757. /// </summary>
  758. [XmlAttribute("source")]
  759. public string Source { get; set; }
  760. /// <summary>
  761. /// Gets or sets the image width in pixels.
  762. /// </summary>
  763. [XmlAttribute("width")]
  764. public int Width { get; set; }
  765. /// <summary>
  766. /// Gets or sets the image height in pixels.
  767. /// </summary>
  768. [XmlAttribute("height")]
  769. public int Height { get; set; }
  770. /// <summary>
  771. /// Gets or sets the transparent color in #RRGGBB format.
  772. /// </summary>
  773. [XmlAttribute("trans")]
  774. public string Trans { get; set; }
  775. /// <summary>
  776. /// Gets or sets the loaded texture.
  777. /// </summary>
  778. /// <remarks>
  779. /// This property is set during parsing and is not part of the TMX file format.
  780. /// </remarks>
  781. [XmlIgnore]
  782. public Texture2D Texture { get; set; }
  783. }
  784. #endregion
  785. #region Properties
  786. /// <summary>
  787. /// Represents a properties collection from a Tiled TMX file.
  788. /// </summary>
  789. public class TiledPropertiesXml
  790. {
  791. /// <summary>
  792. /// Gets or sets the collection of custom properties.
  793. /// </summary>
  794. [XmlElement("property")]
  795. public List<TiledPropertyXml> Properties { get; set; } = new List<TiledPropertyXml>();
  796. }
  797. /// <summary>
  798. /// Represents a custom property from a Tiled TMX file.
  799. /// </summary>
  800. public class TiledPropertyXml
  801. {
  802. /// <summary>
  803. /// Gets or sets the property name.
  804. /// </summary>
  805. [XmlAttribute("name")]
  806. public string Name { get; set; }
  807. /// <summary>
  808. /// Gets or sets the property type (string, int, float, bool, color, file, object, class).
  809. /// </summary>
  810. [XmlAttribute("type")]
  811. public string Type { get; set; }
  812. /// <summary>
  813. /// Gets or sets the property value as a string.
  814. /// </summary>
  815. [XmlAttribute("value")]
  816. public string Value { get; set; }
  817. }
  818. #endregion