| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959 |
- using System;
- using System.Collections.Generic;
- using System.Xml.Serialization;
- using Microsoft.Xna.Framework.Graphics;
- namespace MonoGame.Extended.Tilemaps.Tiled;
- // XML deserialization models for Tiled TMX/TSX files
- // These classes are public to support XML serialization, but represent internal parsing structures
- #region Map
- /// <summary>
- /// Represents the root map element from a Tiled TMX file.
- /// </summary>
- [XmlRoot("map")]
- public class TiledMapXml
- {
- /// <summary>
- /// Gets or sets the TMX format version.
- /// </summary>
- [XmlAttribute("version")]
- public string Version { get; set; }
- /// <summary>
- /// Gets or sets the Tiled version used to save the file.
- /// </summary>
- [XmlAttribute("tiledversion")]
- public string TiledVersion { get; set; }
- /// <summary>
- /// Gets or sets the map orientation (orthogonal, isometric, staggered, hexagonal).
- /// </summary>
- [XmlAttribute("orientation")]
- public string Orientation { get; set; }
- /// <summary>
- /// Gets or sets the tile render order (right-down, right-up, left-down, left-up).
- /// </summary>
- [XmlAttribute("renderorder")]
- public string RenderOrder { get; set; }
- /// <summary>
- /// Gets or sets the map width in tiles.
- /// </summary>
- [XmlAttribute("width")]
- public int Width { get; set; }
- /// <summary>
- /// Gets or sets the map height in tiles.
- /// </summary>
- [XmlAttribute("height")]
- public int Height { get; set; }
- /// <summary>
- /// Gets or sets the tile width in pixels.
- /// </summary>
- [XmlAttribute("tilewidth")]
- public int TileWidth { get; set; }
- /// <summary>
- /// Gets or sets the tile height in pixels.
- /// </summary>
- [XmlAttribute("tileheight")]
- public int TileHeight { get; set; }
- /// <summary>
- /// Gets or sets whether the map is infinite (1) or fixed size (0).
- /// </summary>
- [XmlAttribute("infinite")]
- public int Infinite { get; set; }
- /// <summary>
- /// Gets or sets the background color in #AARRGGBB or #RRGGBB format.
- /// </summary>
- [XmlAttribute("backgroundcolor")]
- public string BackgroundColor { get; set; }
- /// <summary>
- /// Gets or sets the next available layer ID.
- /// </summary>
- [XmlAttribute("nextlayerid")]
- public int NextLayerId { get; set; }
- /// <summary>
- /// Gets or sets the next available object ID.
- /// </summary>
- [XmlAttribute("nextobjectid")]
- public int NextObjectId { get; set; }
- /// <summary>
- /// Gets or sets the custom properties for this map.
- /// </summary>
- [XmlElement("properties")]
- public TiledPropertiesXml Properties { get; set; }
- /// <summary>
- /// Gets or sets the collection of tilesets used by this map.
- /// </summary>
- [XmlElement("tileset")]
- public List<TiledTilesetRefXml> Tilesets { get; set; } = new List<TiledTilesetRefXml>();
- /// <summary>
- /// Gets or sets the collection of layers in this map.
- /// </summary>
- [XmlElement("layer", typeof(TiledTileLayerXml))]
- [XmlElement("objectgroup", typeof(TiledObjectLayerXml))]
- [XmlElement("imagelayer", typeof(TiledImageLayerXml))]
- [XmlElement("group", typeof(TiledGroupLayerXml))]
- public List<TiledLayerXml> Layers { get; set; } = new List<TiledLayerXml>();
- }
- #endregion
- #region Tileset
- /// <summary>
- /// Represents a tileset element from a Tiled TMX or TSX file.
- /// </summary>
- [XmlRoot("tileset")]
- public class TiledTilesetXml
- {
- /// <summary>
- /// Gets or sets the first global tile ID of this tileset.
- /// </summary>
- [XmlAttribute("firstgid")]
- public int FirstGlobalId { get; set; }
- /// <summary>
- /// Gets or sets the name of the tileset.
- /// </summary>
- [XmlAttribute("name")]
- public string Name { get; set; }
- /// <summary>
- /// Gets or sets the width of tiles in this tileset in pixels.
- /// </summary>
- [XmlAttribute("tilewidth")]
- public int TileWidth { get; set; }
- /// <summary>
- /// Gets or sets the height of tiles in this tileset in pixels.
- /// </summary>
- [XmlAttribute("tileheight")]
- public int TileHeight { get; set; }
- /// <summary>
- /// Gets or sets the total number of tiles in this tileset.
- /// </summary>
- [XmlAttribute("tilecount")]
- public int TileCount { get; set; }
- /// <summary>
- /// Gets or sets the number of tile columns in the tileset image.
- /// </summary>
- [XmlAttribute("columns")]
- public int Columns { get; set; }
- /// <summary>
- /// Gets or sets the spacing in pixels between tiles in the tileset image.
- /// </summary>
- [XmlAttribute("spacing")]
- public int Spacing { get; set; }
- /// <summary>
- /// Gets or sets the margin in pixels around tiles in the tileset image.
- /// </summary>
- [XmlAttribute("margin")]
- public int Margin { get; set; }
- /// <summary>
- /// Gets or sets the alignment for tile objects (unspecified, topleft, top, topright, left, center, right, bottomleft, bottom, bottomright).
- /// </summary>
- [XmlAttribute("objectalignment")]
- public string ObjectAlignment { get; set; }
- /// <summary>
- /// Gets or sets the tile offset configuration.
- /// </summary>
- [XmlElement("tileoffset")]
- public TiledTileOffsetXml TileOffset { get; set; }
- /// <summary>
- /// Gets or sets the grid configuration for isometric or staggered tilesets.
- /// </summary>
- [XmlElement("grid")]
- public TiledGridXml Grid { get; set; }
- /// <summary>
- /// Gets or sets the tileset image.
- /// </summary>
- [XmlElement("image")]
- public TiledImageXml Image { get; set; }
- /// <summary>
- /// Gets or sets the collection of individual tile data (animations, collisions, properties).
- /// </summary>
- [XmlElement("tile")]
- public List<TiledTileXml> Tiles { get; set; } = new List<TiledTileXml>();
- /// <summary>
- /// Gets or sets the custom properties for this tileset.
- /// </summary>
- [XmlElement("properties")]
- public TiledPropertiesXml Properties { get; set; }
- /// <summary>
- /// Gets or sets the loaded texture for this tileset.
- /// </summary>
- /// <remarks>
- /// This property is set during parsing and is not part of the TMX file format.
- /// </remarks>
- [XmlIgnore]
- public Texture2D Texture { get; set; }
- }
- /// <summary>
- /// Represents a tileset reference in a Tiled TMX file (can be inline or external).
- /// </summary>
- public class TiledTilesetRefXml : TiledTilesetXml
- {
- /// <summary>
- /// Gets or sets the path to an external TSX file.
- /// </summary>
- /// <remarks>
- /// If this property is set, the tileset data is loaded from the external file.
- /// Otherwise, the tileset is defined inline in the TMX file.
- /// </remarks>
- [XmlAttribute("source")]
- public string Source { get; set; }
- /// <summary>
- /// Gets or sets the tileset data loaded from an external TSX file.
- /// </summary>
- /// <remarks>
- /// This property is populated during parsing when <see cref="Source"/> is specified.
- /// </remarks>
- [XmlIgnore]
- public TiledTilesetXml TilesetData { get; set; }
- }
- /// <summary>
- /// Represents the tile offset configuration for a tileset.
- /// </summary>
- public class TiledTileOffsetXml
- {
- /// <summary>
- /// Gets or sets the horizontal offset in pixels.
- /// </summary>
- [XmlAttribute("x")]
- public int X { get; set; }
- /// <summary>
- /// Gets or sets the vertical offset in pixels.
- /// </summary>
- [XmlAttribute("y")]
- public int Y { get; set; }
- }
- /// <summary>
- /// Represents the grid configuration for isometric or staggered tilesets.
- /// </summary>
- public class TiledGridXml
- {
- /// <summary>
- /// Gets or sets the grid orientation (orthogonal or isometric).
- /// </summary>
- [XmlAttribute("orientation")]
- public string Orientation { get; set; }
- /// <summary>
- /// Gets or sets the grid width in pixels.
- /// </summary>
- [XmlAttribute("width")]
- public int Width { get; set; }
- /// <summary>
- /// Gets or sets the grid height in pixels.
- /// </summary>
- [XmlAttribute("height")]
- public int Height { get; set; }
- }
- #endregion
- #region Tile
- /// <summary>
- /// Represents an individual tile definition within a tileset.
- /// </summary>
- public class TiledTileXml
- {
- /// <summary>
- /// Gets or sets the local tile ID within the tileset.
- /// </summary>
- [XmlAttribute("id")]
- public int Id { get; set; }
- /// <summary>
- /// Gets or sets the tile type (deprecated, use <see cref="Class"/> instead).
- /// </summary>
- [XmlAttribute("type")]
- public string Type { get; set; }
- /// <summary>
- /// Gets or sets the tile class (Tiled 1.9+).
- /// </summary>
- [XmlAttribute("class")]
- public string Class { get; set; }
- /// <summary>
- /// Gets or sets the probability that this tile is chosen over others when painting with random mode.
- /// </summary>
- [XmlAttribute("probability")]
- public float Probability { get; set; }
- /// <summary>
- /// Gets or sets the custom properties for this tile.
- /// </summary>
- [XmlElement("properties")]
- public TiledPropertiesXml Properties { get; set; }
- /// <summary>
- /// Gets or sets the image for this tile (for image collection tilesets).
- /// </summary>
- [XmlElement("image")]
- public TiledImageXml Image { get; set; }
- /// <summary>
- /// Gets or sets the collision object group for this tile.
- /// </summary>
- [XmlElement("objectgroup")]
- public TiledObjectGroupXml ObjectGroup { get; set; }
- /// <summary>
- /// Gets or sets the animation data for this tile.
- /// </summary>
- [XmlElement("animation")]
- public TiledAnimationXml Animation { get; set; }
- }
- /// <summary>
- /// Represents a tile animation sequence.
- /// </summary>
- public class TiledAnimationXml
- {
- /// <summary>
- /// Gets or sets the collection of animation frames.
- /// </summary>
- [XmlElement("frame")]
- public List<TiledAnimationFrameXml> Frames { get; set; } = new List<TiledAnimationFrameXml>();
- }
- /// <summary>
- /// Represents a single frame in a tile animation.
- /// </summary>
- public class TiledAnimationFrameXml
- {
- /// <summary>
- /// Gets or sets the local tile ID for this frame.
- /// </summary>
- [XmlAttribute("tileid")]
- public int TileId { get; set; }
- /// <summary>
- /// Gets or sets the duration of this frame in milliseconds.
- /// </summary>
- [XmlAttribute("duration")]
- public int Duration { get; set; }
- }
- #endregion
- #region Layers
- /// <summary>
- /// Base class for all Tiled layer types.
- /// </summary>
- public class TiledLayerXml
- {
- /// <summary>
- /// Gets or sets the unique layer ID.
- /// </summary>
- [XmlAttribute("id")]
- public int Id { get; set; }
- /// <summary>
- /// Gets or sets the layer name.
- /// </summary>
- [XmlAttribute("name")]
- public string Name { get; set; }
- /// <summary>
- /// Gets or sets the layer class (Tiled 1.9+).
- /// </summary>
- [XmlAttribute("class")]
- public string Class { get; set; }
- /// <summary>
- /// Gets or sets the horizontal offset in pixels.
- /// </summary>
- [XmlAttribute("offsetx")]
- public float OffsetX { get; set; }
- /// <summary>
- /// Gets or sets the vertical offset in pixels.
- /// </summary>
- [XmlAttribute("offsety")]
- public float OffsetY { get; set; }
- /// <summary>
- /// Gets or sets the horizontal parallax factor (Tiled 1.5+).
- /// </summary>
- [XmlAttribute("parallaxx")]
- public float ParallaxX { get; set; } = 1.0f;
- /// <summary>
- /// Gets or sets the vertical parallax factor (Tiled 1.5+).
- /// </summary>
- [XmlAttribute("parallaxy")]
- public float ParallaxY { get; set; } = 1.0f;
- /// <summary>
- /// Gets or sets the layer opacity (0.0 to 1.0).
- /// </summary>
- [XmlAttribute("opacity")]
- public float Opacity { get; set; } = 1.0f;
- /// <summary>
- /// Gets or sets whether the layer is visible (1 = visible, 0 = hidden).
- /// </summary>
- [XmlAttribute("visible")]
- public int Visible { get; set; } = 1;
- /// <summary>
- /// Gets or sets the layer tint color in #AARRGGBB or #RRGGBB format.
- /// </summary>
- [XmlAttribute("tintcolor")]
- public string TintColor { get; set; }
- /// <summary>
- /// Gets or sets the custom properties for this layer.
- /// </summary>
- [XmlElement("properties")]
- public TiledPropertiesXml Properties { get; set; }
- }
- /// <summary>
- /// Represents a tile layer from a Tiled TMX file.
- /// </summary>
- public class TiledTileLayerXml : TiledLayerXml
- {
- /// <summary>
- /// Gets or sets the layer width in tiles.
- /// </summary>
- [XmlAttribute("width")]
- public int Width { get; set; }
- /// <summary>
- /// Gets or sets the layer height in tiles.
- /// </summary>
- [XmlAttribute("height")]
- public int Height { get; set; }
- /// <summary>
- /// Gets or sets the tile data for this layer.
- /// </summary>
- [XmlElement("data")]
- public TiledTileLayerDataXml Data { get; set; }
- }
- /// <summary>
- /// Represents the tile data element of a tile layer.
- /// </summary>
- public class TiledTileLayerDataXml
- {
- /// <summary>
- /// Gets or sets the encoding format (csv, base64, or null for XML).
- /// </summary>
- [XmlAttribute("encoding")]
- public string Encoding { get; set; }
- /// <summary>
- /// Gets or sets the compression format (gzip, zlib, or null for uncompressed).
- /// </summary>
- [XmlAttribute("compression")]
- public string Compression { get; set; }
- /// <summary>
- /// Gets or sets the tile data as a string (for CSV or Base64 encoding).
- /// </summary>
- [XmlText]
- public string Value { get; set; }
- /// <summary>
- /// Gets or sets the tile data as individual tile elements (for XML encoding).
- /// </summary>
- [XmlElement("tile")]
- public List<TiledDataTileXml> Tiles { get; set; } = new List<TiledDataTileXml>();
- /// <summary>
- /// Gets or sets the chunk data (for infinite maps).
- /// </summary>
- [XmlElement("chunk")]
- public List<TiledChunkXml> Chunks { get; set; } = new List<TiledChunkXml>();
- }
- /// <summary>
- /// Represents a single tile element in XML-encoded tile data.
- /// </summary>
- public class TiledDataTileXml
- {
- /// <summary>
- /// Gets or sets the global tile ID (includes flip flags in high bits).
- /// </summary>
- [XmlAttribute("gid")]
- public uint Gid { get; set; }
- }
- /// <summary>
- /// Represents a chunk of tiles in an infinite map.
- /// </summary>
- public class TiledChunkXml
- {
- /// <summary>
- /// Gets or sets the X coordinate of the chunk in tiles.
- /// </summary>
- [XmlAttribute("x")]
- public int X { get; set; }
- /// <summary>
- /// Gets or sets the Y coordinate of the chunk in tiles.
- /// </summary>
- [XmlAttribute("y")]
- public int Y { get; set; }
- /// <summary>
- /// Gets or sets the chunk width in tiles.
- /// </summary>
- [XmlAttribute("width")]
- public int Width { get; set; }
- /// <summary>
- /// Gets or sets the chunk height in tiles.
- /// </summary>
- [XmlAttribute("height")]
- public int Height { get; set; }
- /// <summary>
- /// Gets or sets the tile data for this chunk.
- /// </summary>
- [XmlText]
- public string Value { get; set; }
- }
- /// <summary>
- /// Represents an object layer from a Tiled TMX file.
- /// </summary>
- public class TiledObjectLayerXml : TiledLayerXml
- {
- /// <summary>
- /// Gets or sets the layer color in #AARRGGBB or #RRGGBB format.
- /// </summary>
- [XmlAttribute("color")]
- public string Color { get; set; }
- /// <summary>
- /// Gets or sets the draw order (topdown or index).
- /// </summary>
- [XmlAttribute("draworder")]
- public string DrawOrder { get; set; }
- /// <summary>
- /// Gets or sets the collection of objects in this layer.
- /// </summary>
- [XmlElement("object")]
- public List<TiledObjectXml> Objects { get; set; } = new List<TiledObjectXml>();
- }
- /// <summary>
- /// Represents an image layer from a Tiled TMX file.
- /// </summary>
- public class TiledImageLayerXml : TiledLayerXml
- {
- /// <summary>
- /// Gets or sets whether the image repeats horizontally (Tiled 1.8+).
- /// </summary>
- [XmlAttribute("repeatx")]
- public int RepeatX { get; set; }
- /// <summary>
- /// Gets or sets whether the image repeats vertically (Tiled 1.8+).
- /// </summary>
- [XmlAttribute("repeaty")]
- public int RepeatY { get; set; }
- /// <summary>
- /// Gets or sets the image for this layer.
- /// </summary>
- [XmlElement("image")]
- public TiledImageXml Image { get; set; }
- /// <summary>
- /// Gets or sets the loaded texture for this layer.
- /// </summary>
- /// <remarks>
- /// This property is set during parsing and is not part of the TMX file format.
- /// </remarks>
- [XmlIgnore]
- public Texture2D Texture { get; set; }
- }
- /// <summary>
- /// Represents a group layer from a Tiled TMX file.
- /// </summary>
- public class TiledGroupLayerXml : TiledLayerXml
- {
- /// <summary>
- /// Gets or sets the child layers in this group.
- /// </summary>
- [XmlElement("layer", typeof(TiledTileLayerXml))]
- [XmlElement("objectgroup", typeof(TiledObjectLayerXml))]
- [XmlElement("imagelayer", typeof(TiledImageLayerXml))]
- [XmlElement("group", typeof(TiledGroupLayerXml))]
- public List<TiledLayerXml> Layers { get; set; } = new List<TiledLayerXml>();
- }
- #endregion
- #region Objects
- /// <summary>
- /// Represents an object group element (used for tile collision objects).
- /// </summary>
- public class TiledObjectGroupXml
- {
- /// <summary>
- /// Gets or sets the draw order (topdown or index).
- /// </summary>
- [XmlAttribute("draworder")]
- public string DrawOrder { get; set; }
- /// <summary>
- /// Gets or sets the collection of objects in this group.
- /// </summary>
- [XmlElement("object")]
- public List<TiledObjectXml> Objects { get; set; } = new List<TiledObjectXml>();
- }
- /// <summary>
- /// Represents an object from a Tiled TMX file.
- /// </summary>
- public class TiledObjectXml
- {
- /// <summary>
- /// Gets or sets the unique object ID.
- /// </summary>
- [XmlAttribute("id")]
- public int Id { get; set; }
- /// <summary>
- /// Gets or sets the object name.
- /// </summary>
- [XmlAttribute("name")]
- public string Name { get; set; }
- /// <summary>
- /// Gets or sets the object type (deprecated, use <see cref="Class"/> instead).
- /// </summary>
- [XmlAttribute("type")]
- public string Type { get; set; }
- /// <summary>
- /// Gets or sets the object class (Tiled 1.9+).
- /// </summary>
- [XmlAttribute("class")]
- public string Class { get; set; }
- /// <summary>
- /// Gets or sets the X coordinate in pixels.
- /// </summary>
- [XmlAttribute("x")]
- public float X { get; set; }
- /// <summary>
- /// Gets or sets the Y coordinate in pixels.
- /// </summary>
- [XmlAttribute("y")]
- public float Y { get; set; }
- /// <summary>
- /// Gets or sets the width in pixels.
- /// </summary>
- [XmlAttribute("width")]
- public float Width { get; set; }
- /// <summary>
- /// Gets or sets the height in pixels.
- /// </summary>
- [XmlAttribute("height")]
- public float Height { get; set; }
- /// <summary>
- /// Gets or sets the rotation in degrees (clockwise).
- /// </summary>
- [XmlAttribute("rotation")]
- public float Rotation { get; set; }
- /// <summary>
- /// Gets or sets the global tile ID (for tile objects).
- /// </summary>
- [XmlAttribute("gid")]
- public uint Gid { get; set; }
- /// <summary>
- /// Gets or sets whether the object is visible (1 = visible, 0 = hidden).
- /// </summary>
- [XmlAttribute("visible")]
- public int Visible { get; set; } = 1;
- /// <summary>
- /// Gets or sets the custom properties for this object.
- /// </summary>
- [XmlElement("properties")]
- public TiledPropertiesXml Properties { get; set; }
- /// <summary>
- /// Gets or sets the ellipse marker (presence indicates ellipse object).
- /// </summary>
- [XmlElement("ellipse")]
- public TiledEllipseXml Ellipse { get; set; }
- /// <summary>
- /// Gets or sets the point marker (presence indicates point object).
- /// </summary>
- [XmlElement("point")]
- public TiledPointXml Point { get; set; }
- /// <summary>
- /// Gets or sets the polygon data (for polygon objects).
- /// </summary>
- [XmlElement("polygon")]
- public TiledPolygonXml Polygon { get; set; }
- /// <summary>
- /// Gets or sets the polyline data (for polyline objects).
- /// </summary>
- [XmlElement("polyline")]
- public TiledPolylineXml Polyline { get; set; }
- /// <summary>
- /// Gets or sets the text data (for text objects).
- /// </summary>
- [XmlElement("text")]
- public TiledTextXml Text { get; set; }
- }
- /// <summary>
- /// Marker class indicating an ellipse object.
- /// </summary>
- public class TiledEllipseXml
- {
- // Empty element - presence indicates ellipse
- }
- /// <summary>
- /// Marker class indicating a point object.
- /// </summary>
- public class TiledPointXml
- {
- // Empty element - presence indicates point
- }
- /// <summary>
- /// Represents polygon point data.
- /// </summary>
- public class TiledPolygonXml
- {
- /// <summary>
- /// Gets or sets the polygon points as a space-separated list of "x,y" pairs.
- /// </summary>
- [XmlAttribute("points")]
- public string Points { get; set; }
- }
- /// <summary>
- /// Represents polyline point data.
- /// </summary>
- public class TiledPolylineXml
- {
- /// <summary>
- /// Gets or sets the polyline points as a space-separated list of "x,y" pairs.
- /// </summary>
- [XmlAttribute("points")]
- public string Points { get; set; }
- }
- /// <summary>
- /// Represents text object data.
- /// </summary>
- public class TiledTextXml
- {
- /// <summary>
- /// Gets or sets the font family.
- /// </summary>
- [XmlAttribute("fontfamily")]
- public string FontFamily { get; set; }
- /// <summary>
- /// Gets or sets the font size in pixels.
- /// </summary>
- [XmlAttribute("pixelsize")]
- public int PixelSize { get; set; } = 16;
- /// <summary>
- /// Gets or sets whether text wrapping is enabled.
- /// </summary>
- [XmlAttribute("wrap")]
- public int Wrap { get; set; }
- /// <summary>
- /// Gets or sets the text color in #AARRGGBB or #RRGGBB format.
- /// </summary>
- [XmlAttribute("color")]
- public string Color { get; set; } = "#000000";
- /// <summary>
- /// Gets or sets whether the text is bold.
- /// </summary>
- [XmlAttribute("bold")]
- public int Bold { get; set; }
- /// <summary>
- /// Gets or sets whether the text is italic.
- /// </summary>
- [XmlAttribute("italic")]
- public int Italic { get; set; }
- /// <summary>
- /// Gets or sets whether the text is underlined.
- /// </summary>
- [XmlAttribute("underline")]
- public int Underline { get; set; }
- /// <summary>
- /// Gets or sets whether the text has a strikethrough.
- /// </summary>
- [XmlAttribute("strikeout")]
- public int Strikeout { get; set; }
- /// <summary>
- /// Gets or sets whether kerning is enabled.
- /// </summary>
- [XmlAttribute("kerning")]
- public int Kerning { get; set; } = 1;
- /// <summary>
- /// Gets or sets the horizontal alignment (left, center, right, justify).
- /// </summary>
- [XmlAttribute("halign")]
- public string HAlign { get; set; } = "left";
- /// <summary>
- /// Gets or sets the vertical alignment (top, center, bottom).
- /// </summary>
- [XmlAttribute("valign")]
- public string VAlign { get; set; } = "top";
- /// <summary>
- /// Gets or sets the text content.
- /// </summary>
- [XmlText]
- public string Value { get; set; }
- }
- #endregion
- #region Image
- /// <summary>
- /// Represents an image element from a Tiled TMX file.
- /// </summary>
- public class TiledImageXml
- {
- /// <summary>
- /// Gets or sets the image source path (relative to the TMX/TSX file).
- /// </summary>
- [XmlAttribute("source")]
- public string Source { get; set; }
- /// <summary>
- /// Gets or sets the image width in pixels.
- /// </summary>
- [XmlAttribute("width")]
- public int Width { get; set; }
- /// <summary>
- /// Gets or sets the image height in pixels.
- /// </summary>
- [XmlAttribute("height")]
- public int Height { get; set; }
- /// <summary>
- /// Gets or sets the transparent color in #RRGGBB format.
- /// </summary>
- [XmlAttribute("trans")]
- public string Trans { get; set; }
- /// <summary>
- /// Gets or sets the loaded texture.
- /// </summary>
- /// <remarks>
- /// This property is set during parsing and is not part of the TMX file format.
- /// </remarks>
- [XmlIgnore]
- public Texture2D Texture { get; set; }
- }
- #endregion
- #region Properties
- /// <summary>
- /// Represents a properties collection from a Tiled TMX file.
- /// </summary>
- public class TiledPropertiesXml
- {
- /// <summary>
- /// Gets or sets the collection of custom properties.
- /// </summary>
- [XmlElement("property")]
- public List<TiledPropertyXml> Properties { get; set; } = new List<TiledPropertyXml>();
- }
- /// <summary>
- /// Represents a custom property from a Tiled TMX file.
- /// </summary>
- public class TiledPropertyXml
- {
- /// <summary>
- /// Gets or sets the property name.
- /// </summary>
- [XmlAttribute("name")]
- public string Name { get; set; }
- /// <summary>
- /// Gets or sets the property type (string, int, float, bool, color, file, object, class).
- /// </summary>
- [XmlAttribute("type")]
- public string Type { get; set; }
- /// <summary>
- /// Gets or sets the property value as a string.
- /// </summary>
- [XmlAttribute("value")]
- public string Value { get; set; }
- }
- #endregion
|