| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935 |
- using System.Collections.Generic;
- using System.Text.Json;
- using System.Text.Json.Serialization;
- namespace MonoGame.Extended.Tilemaps.LDtk;
- // JSON deserialization models for LDtk JSON files
- // These classes are public to support JSON serialization, but represent internal parsing structures
- #region Project
- /// <summary>
- /// Represents the root of an LDtk project JSON file.
- /// </summary>
- public class LDtkProject
- {
- /// <summary>
- /// Gets or sets the unique project instance identifier.
- /// </summary>
- [JsonPropertyName("iid")]
- public string Iid { get; set; }
- /// <summary>
- /// Gets or sets the LDtk JSON format version.
- /// </summary>
- [JsonPropertyName("jsonVersion")]
- public string JsonVersion { get; set; }
- /// <summary>
- /// Gets or sets the LDtk application build identifier.
- /// </summary>
- [JsonPropertyName("appBuildId")]
- public int AppBuildId { get; set; }
- [JsonPropertyName("nextUid")]
- public int NextUid { get; set; }
- [JsonPropertyName("identifierStyle")]
- public string IdentifierStyle { get; set; }
- /// <summary>
- /// Gets or sets the world layout mode (Free, GridVania, LinearHorizontal, LinearVertical).
- /// </summary>
- [JsonPropertyName("worldLayout")]
- public string WorldLayout { get; set; }
- [JsonPropertyName("worldGridWidth")]
- public int? WorldGridWidth { get; set; }
- [JsonPropertyName("worldGridHeight")]
- public int? WorldGridHeight { get; set; }
- [JsonPropertyName("defaultLevelWidth")]
- public int? DefaultLevelWidth { get; set; }
- [JsonPropertyName("defaultLevelHeight")]
- public int? DefaultLevelHeight { get; set; }
- /// <summary>
- /// Gets or sets the default grid size for layers.
- /// </summary>
- [JsonPropertyName("defaultGridSize")]
- public int DefaultGridSize { get; set; }
- [JsonPropertyName("defaultPivotX")]
- public float DefaultPivotX { get; set; }
- [JsonPropertyName("defaultPivotY")]
- public float DefaultPivotY { get; set; }
- /// <summary>
- /// Gets or sets the project background color in #RRGGBB format.
- /// </summary>
- [JsonPropertyName("bgColor")]
- public string BgColor { get; set; }
- [JsonPropertyName("defaultLevelBgColor")]
- public string DefaultLevelBgColor { get; set; }
- [JsonPropertyName("externalLevels")]
- public bool ExternalLevels { get; set; }
- /// <summary>
- /// Gets or sets the collection of levels in this project.
- /// </summary>
- [JsonPropertyName("levels")]
- public List<LDtkLevel> Levels { get; set; } = new List<LDtkLevel>();
- /// <summary>
- /// Gets or sets the project definitions (layers, entities, tilesets, enums).
- /// </summary>
- [JsonPropertyName("defs")]
- public LDtkDefinitions Defs { get; set; }
- [JsonPropertyName("worlds")]
- public List<LDtkWorld> Worlds { get; set; } = new List<LDtkWorld>();
- [JsonPropertyName("dummyWorldIid")]
- public string DummyWorldIid { get; set; }
- /// <summary>
- /// Gets or sets the table of contents listing all entity instances with exportToToc enabled.
- /// </summary>
- [JsonPropertyName("toc")]
- public List<LDtkTableOfContentEntry> Toc { get; set; } = new List<LDtkTableOfContentEntry>();
- }
- /// <summary>
- /// Represents a table of contents entry for an entity type in LDtk.
- /// </summary>
- public class LDtkTableOfContentEntry
- {
- /// <summary>
- /// Gets or sets the entity identifier.
- /// </summary>
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- /// <summary>
- /// Gets or sets the collection of entity instance data.
- /// </summary>
- [JsonPropertyName("instancesData")]
- public List<LDtkTocInstanceData> InstancesData { get; set; } = new List<LDtkTocInstanceData>();
- }
- /// <summary>
- /// Represents instance data for a table of contents entry in LDtk.
- /// </summary>
- public class LDtkTocInstanceData
- {
- /// <summary>
- /// Gets or sets the IID information for this instance.
- /// </summary>
- [JsonPropertyName("iids")]
- public LDtkEntityReferenceInfos Iids { get; set; }
- /// <summary>
- /// Gets or sets the world X coordinate in pixels.
- /// </summary>
- [JsonPropertyName("worldX")]
- public int WorldX { get; set; }
- /// <summary>
- /// Gets or sets the world Y coordinate in pixels.
- /// </summary>
- [JsonPropertyName("worldY")]
- public int WorldY { get; set; }
- /// <summary>
- /// Gets or sets the width in pixels.
- /// </summary>
- [JsonPropertyName("widPx")]
- public int WidPx { get; set; }
- /// <summary>
- /// Gets or sets the height in pixels.
- /// </summary>
- [JsonPropertyName("heiPx")]
- public int HeiPx { get; set; }
- /// <summary>
- /// Gets or sets the entity custom field values (exportToToc fields only).
- /// </summary>
- [JsonPropertyName("fields")]
- public JsonElement? Fields { get; set; }
- }
- /// <summary>
- /// Represents all definitions in an LDtk project.
- /// </summary>
- public class LDtkDefinitions
- {
- /// <summary>
- /// Gets or sets the collection of layer definitions.
- /// </summary>
- [JsonPropertyName("layers")]
- public List<LDtkLayerDefinition> Layers { get; set; } = new List<LDtkLayerDefinition>();
- /// <summary>
- /// Gets or sets the collection of entity definitions.
- /// </summary>
- [JsonPropertyName("entities")]
- public List<LDtkEntityDefinition> Entities { get; set; } = new List<LDtkEntityDefinition>();
- /// <summary>
- /// Gets or sets the collection of tileset definitions.
- /// </summary>
- [JsonPropertyName("tilesets")]
- public List<LDtkTilesetDefinition> Tilesets { get; set; } = new List<LDtkTilesetDefinition>();
- /// <summary>
- /// Gets or sets the collection of enum definitions.
- /// </summary>
- [JsonPropertyName("enums")]
- public List<LDtkEnumDefinition> Enums { get; set; } = new List<LDtkEnumDefinition>();
- [JsonPropertyName("externalEnums")]
- public List<LDtkEnumDefinition> ExternalEnums { get; set; } = new List<LDtkEnumDefinition>();
- [JsonPropertyName("levelFields")]
- public List<LDtkFieldDefinition> LevelFields { get; set; } = new List<LDtkFieldDefinition>();
- }
- /// <summary>
- /// Represents a world in an LDtk project (multi-worlds support).
- /// </summary>
- public class LDtkWorld
- {
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- [JsonPropertyName("iid")]
- public string Iid { get; set; }
- [JsonPropertyName("levels")]
- public List<LDtkLevel> Levels { get; set; } = new List<LDtkLevel>();
- [JsonPropertyName("worldGridWidth")]
- public int WorldGridWidth { get; set; }
- [JsonPropertyName("worldGridHeight")]
- public int WorldGridHeight { get; set; }
- [JsonPropertyName("worldLayout")]
- public string WorldLayout { get; set; }
- [JsonPropertyName("defaultLevelWidth")]
- public int DefaultLevelWidth { get; set; }
- [JsonPropertyName("defaultLevelHeight")]
- public int DefaultLevelHeight { get; set; }
- }
- #endregion
- #region Level
- /// <summary>
- /// Represents a level in an LDtk project.
- /// </summary>
- public class LDtkLevel
- {
- /// <summary>
- /// Gets or sets the level identifier.
- /// </summary>
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- /// <summary>
- /// Gets or sets the unique level instance identifier.
- /// </summary>
- [JsonPropertyName("iid")]
- public string Iid { get; set; }
- [JsonPropertyName("uid")]
- public int Uid { get; set; }
- /// <summary>
- /// Gets or sets the world X coordinate in pixels.
- /// </summary>
- [JsonPropertyName("worldX")]
- public int WorldX { get; set; }
- /// <summary>
- /// Gets or sets the world Y coordinate in pixels.
- /// </summary>
- [JsonPropertyName("worldY")]
- public int WorldY { get; set; }
- [JsonPropertyName("worldDepth")]
- public int WorldDepth { get; set; }
- /// <summary>
- /// Gets or sets the level width in pixels.
- /// </summary>
- [JsonPropertyName("pxWid")]
- public int PxWid { get; set; }
- /// <summary>
- /// Gets or sets the level height in pixels.
- /// </summary>
- [JsonPropertyName("pxHei")]
- public int PxHei { get; set; }
- /// <summary>
- /// Gets or sets the level background color in #RRGGBB format.
- /// </summary>
- [JsonPropertyName("__bgColor")]
- public string BgColor { get; set; }
- [JsonPropertyName("bgColor")]
- public string BgColorOverride { get; set; }
- [JsonPropertyName("bgRelPath")]
- public string BgRelPath { get; set; }
- [JsonPropertyName("bgPos")]
- public string BgPos { get; set; }
- [JsonPropertyName("bgPivotX")]
- public float BgPivotX { get; set; }
- [JsonPropertyName("bgPivotY")]
- public float BgPivotY { get; set; }
- [JsonPropertyName("externalRelPath")]
- public string ExternalRelPath { get; set; }
- /// <summary>
- /// Gets or sets the custom field instances for this level.
- /// </summary>
- [JsonPropertyName("fieldInstances")]
- public List<LDtkFieldInstance> FieldInstances { get; set; } = new List<LDtkFieldInstance>();
- /// <summary>
- /// Gets or sets the collection of layer instances in this level.
- /// </summary>
- [JsonPropertyName("layerInstances")]
- public List<LDtkLayerInstance> LayerInstances { get; set; }
- /// <summary>
- /// Gets or sets the collection of neighbor levels touching this one.
- /// </summary>
- [JsonPropertyName("__neighbours")]
- public List<LDtkNeighbourLevel> Neighbours { get; set; } = new List<LDtkNeighbourLevel>();
- }
- /// <summary>
- /// Represents a neighbor level in LDtk.
- /// </summary>
- public class LDtkNeighbourLevel
- {
- /// <summary>
- /// Gets or sets the direction to the neighbor (n, s, e, w, ne, nw, se, sw, <, >, o).
- /// </summary>
- [JsonPropertyName("dir")]
- public string Dir { get; set; }
- /// <summary>
- /// Gets or sets the neighbor level's instance identifier.
- /// </summary>
- [JsonPropertyName("levelIid")]
- public string LevelIid { get; set; }
- /// <summary>
- /// Gets or sets the neighbor level's UID (deprecated, use levelIid).
- /// </summary>
- [JsonPropertyName("levelUid")]
- public int? LevelUid { get; set; }
- }
- #endregion
- #region Layer
- /// <summary>
- /// Represents a layer definition in LDtk.
- /// </summary>
- public class LDtkLayerDefinition
- {
- /// <summary>
- /// Gets or sets the layer type (IntGrid, Entities, Tiles, AutoLayer).
- /// </summary>
- [JsonPropertyName("__type")]
- public string Type { get; set; }
- /// <summary>
- /// Gets or sets the layer identifier.
- /// </summary>
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- [JsonPropertyName("type")]
- public string TypeEnum { get; set; }
- [JsonPropertyName("uid")]
- public int Uid { get; set; }
- /// <summary>
- /// Gets or sets the grid size for this layer in pixels.
- /// </summary>
- [JsonPropertyName("gridSize")]
- public int GridSize { get; set; }
- [JsonPropertyName("displayOpacity")]
- public float DisplayOpacity { get; set; }
- [JsonPropertyName("pxOffsetX")]
- public int PxOffsetX { get; set; }
- [JsonPropertyName("pxOffsetY")]
- public int PxOffsetY { get; set; }
- [JsonPropertyName("parallaxFactorX")]
- public float ParallaxFactorX { get; set; }
- [JsonPropertyName("parallaxFactorY")]
- public float ParallaxFactorY { get; set; }
- /// <summary>
- /// Gets or sets the tileset definition UID for this layer (null if not a tile layer).
- /// </summary>
- [JsonPropertyName("tilesetDefUid")]
- public int? TilesetDefUid { get; set; }
- [JsonPropertyName("autoSourceLayerDefUid")]
- public int? AutoSourceLayerDefUid { get; set; }
- /// <summary>
- /// Gets or sets the IntGrid value definitions for IntGrid layers.
- /// </summary>
- [JsonPropertyName("intGridValues")]
- public List<LDtkIntGridValueDefinition> IntGridValues { get; set; } = new List<LDtkIntGridValueDefinition>();
- [JsonPropertyName("autoRuleGroups")]
- public List<LDtkAutoLayerRuleGroup> AutoRuleGroups { get; set; } = new List<LDtkAutoLayerRuleGroup>();
- }
- /// <summary>
- /// Represents a layer instance in an LDtk level.
- /// </summary>
- public class LDtkLayerInstance
- {
- /// <summary>
- /// Gets or sets the layer identifier.
- /// </summary>
- [JsonPropertyName("__identifier")]
- public string Identifier { get; set; }
- /// <summary>
- /// Gets or sets the layer type (IntGrid, Entities, Tiles, AutoLayer).
- /// </summary>
- [JsonPropertyName("__type")]
- public string Type { get; set; }
- /// <summary>
- /// Gets or sets the layer width in grid cells.
- /// </summary>
- [JsonPropertyName("__cWid")]
- public int CWid { get; set; }
- /// <summary>
- /// Gets or sets the layer height in grid cells.
- /// </summary>
- [JsonPropertyName("__cHei")]
- public int CHei { get; set; }
- /// <summary>
- /// Gets or sets the grid size in pixels.
- /// </summary>
- [JsonPropertyName("__gridSize")]
- public int GridSize { get; set; }
- /// <summary>
- /// Gets or sets the layer opacity (0.0 to 1.0).
- /// </summary>
- [JsonPropertyName("__opacity")]
- public float Opacity { get; set; }
- [JsonPropertyName("__pxTotalOffsetX")]
- public int PxTotalOffsetX { get; set; }
- [JsonPropertyName("__pxTotalOffsetY")]
- public int PxTotalOffsetY { get; set; }
- /// <summary>
- /// Gets or sets the tileset definition UID for this layer instance.
- /// </summary>
- [JsonPropertyName("__tilesetDefUid")]
- public int? TilesetDefUid { get; set; }
- [JsonPropertyName("__tilesetRelPath")]
- public string TilesetRelPath { get; set; }
- [JsonPropertyName("iid")]
- public string Iid { get; set; }
- [JsonPropertyName("levelId")]
- public int LevelId { get; set; }
- [JsonPropertyName("layerDefUid")]
- public int LayerDefUid { get; set; }
- [JsonPropertyName("pxOffsetX")]
- public int PxOffsetX { get; set; }
- [JsonPropertyName("pxOffsetY")]
- public int PxOffsetY { get; set; }
- /// <summary>
- /// Gets or sets whether the layer is visible.
- /// </summary>
- [JsonPropertyName("visible")]
- public bool Visible { get; set; }
- /// <summary>
- /// Gets or sets the parallax horizontal factor (from -1 to 1, defaults to 0).
- /// </summary>
- [JsonPropertyName("__parallaxFactorX")]
- public float ParallaxFactorX { get; set; }
- /// <summary>
- /// Gets or sets the parallax vertical factor (from -1 to 1, defaults to 0).
- /// </summary>
- [JsonPropertyName("__parallaxFactorY")]
- public float ParallaxFactorY { get; set; }
- /// <summary>
- /// Gets or sets the tile instances for Tiles layers.
- /// </summary>
- [JsonPropertyName("gridTiles")]
- public List<LDtkTileInstance> GridTiles { get; set; } = new List<LDtkTileInstance>();
- /// <summary>
- /// Gets or sets the auto-layer tile instances for IntGrid layers.
- /// </summary>
- [JsonPropertyName("autoLayerTiles")]
- public List<LDtkTileInstance> AutoLayerTiles { get; set; } = new List<LDtkTileInstance>();
- /// <summary>
- /// Gets or sets the entity instances for Entities layers.
- /// </summary>
- [JsonPropertyName("entityInstances")]
- public List<LDtkEntityInstance> EntityInstances { get; set; } = new List<LDtkEntityInstance>();
- /// <summary>
- /// Gets or sets the IntGrid values in CSV format for IntGrid layers.
- /// </summary>
- [JsonPropertyName("intGridCsv")]
- public List<int> IntGridCsv { get; set; } = new List<int>();
- }
- #endregion
- #region Tileset
- /// <summary>
- /// Represents a tileset definition in LDtk.
- /// </summary>
- public class LDtkTilesetDefinition
- {
- /// <summary>
- /// Gets or sets the tileset identifier.
- /// </summary>
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- [JsonPropertyName("uid")]
- public int Uid { get; set; }
- /// <summary>
- /// Gets or sets the relative path to the tileset image.
- /// </summary>
- [JsonPropertyName("relPath")]
- public string RelPath { get; set; }
- [JsonPropertyName("embedAtlas")]
- public string EmbedAtlas { get; set; }
- /// <summary>
- /// Gets or sets the tileset image width in pixels.
- /// </summary>
- [JsonPropertyName("pxWid")]
- public int PxWid { get; set; }
- /// <summary>
- /// Gets or sets the tileset image height in pixels.
- /// </summary>
- [JsonPropertyName("pxHei")]
- public int PxHei { get; set; }
- /// <summary>
- /// Gets or sets the tile grid size in pixels.
- /// </summary>
- [JsonPropertyName("tileGridSize")]
- public int TileGridSize { get; set; }
- /// <summary>
- /// Gets or sets the spacing in pixels between tiles.
- /// </summary>
- [JsonPropertyName("spacing")]
- public int Spacing { get; set; }
- /// <summary>
- /// Gets or sets the padding in pixels around tiles.
- /// </summary>
- [JsonPropertyName("padding")]
- public int Padding { get; set; }
- /// <summary>
- /// Gets or sets the tileset width in grid cells.
- /// </summary>
- [JsonPropertyName("__cWid")]
- public int CWid { get; set; }
- /// <summary>
- /// Gets or sets the tileset height in grid cells.
- /// </summary>
- [JsonPropertyName("__cHei")]
- public int CHei { get; set; }
- }
- /// <summary>
- /// Represents a tile instance in an LDtk layer.
- /// </summary>
- public class LDtkTileInstance
- {
- /// <summary>
- /// Gets or sets the pixel coordinates [x, y] of the tile in the layer.
- /// </summary>
- [JsonPropertyName("px")]
- public List<int> Px { get; set; } = new List<int>();
- /// <summary>
- /// Gets or sets the source pixel coordinates [x, y] in the tileset.
- /// </summary>
- [JsonPropertyName("src")]
- public List<int> Src { get; set; } = new List<int>();
- /// <summary>
- /// Gets or sets the flip flags (0=none, 1=X, 2=Y, 3=XY).
- /// </summary>
- [JsonPropertyName("f")]
- public int F { get; set; }
- /// <summary>
- /// Gets or sets the tile ID in the tileset.
- /// </summary>
- [JsonPropertyName("t")]
- public int T { get; set; }
- [JsonPropertyName("d")]
- public List<int> D { get; set; } = new List<int>();
- /// <summary>
- /// Gets or sets the tile alpha/opacity (0.0 to 1.0).
- /// </summary>
- [JsonPropertyName("a")]
- public float A { get; set; } = 1.0f;
- }
- /// <summary>
- /// Represents an IntGrid value definition in LDtk.
- /// </summary>
- public class LDtkIntGridValueDefinition
- {
- [JsonPropertyName("value")]
- public int Value { get; set; }
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- [JsonPropertyName("color")]
- public string Color { get; set; }
- }
- #endregion
- #region Entity
- /// <summary>
- /// Represents an entity definition in LDtk.
- /// </summary>
- public class LDtkEntityDefinition
- {
- /// <summary>
- /// Gets or sets the entity identifier.
- /// </summary>
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- [JsonPropertyName("uid")]
- public int Uid { get; set; }
- /// <summary>
- /// Gets or sets the entity width in pixels.
- /// </summary>
- [JsonPropertyName("width")]
- public int Width { get; set; }
- /// <summary>
- /// Gets or sets the entity height in pixels.
- /// </summary>
- [JsonPropertyName("height")]
- public int Height { get; set; }
- /// <summary>
- /// Gets or sets the entity color in #RRGGBB format.
- /// </summary>
- [JsonPropertyName("color")]
- public string Color { get; set; }
- [JsonPropertyName("pivotX")]
- public float PivotX { get; set; }
- [JsonPropertyName("pivotY")]
- public float PivotY { get; set; }
- /// <summary>
- /// Gets or sets the custom field definitions for this entity.
- /// </summary>
- [JsonPropertyName("fieldDefs")]
- public List<LDtkFieldDefinition> FieldDefs { get; set; } = new List<LDtkFieldDefinition>();
- [JsonPropertyName("tags")]
- public List<string> Tags { get; set; } = new List<string>();
- }
- /// <summary>
- /// Represents an entity instance in an LDtk level.
- /// </summary>
- public class LDtkEntityInstance
- {
- /// <summary>
- /// Gets or sets the entity identifier.
- /// </summary>
- [JsonPropertyName("__identifier")]
- public string Identifier { get; set; }
- /// <summary>
- /// Gets or sets the unique entity instance identifier.
- /// </summary>
- [JsonPropertyName("iid")]
- public string Iid { get; set; }
- [JsonPropertyName("defUid")]
- public int DefUid { get; set; }
- /// <summary>
- /// Gets or sets the pixel coordinates [x, y] of the entity.
- /// </summary>
- [JsonPropertyName("px")]
- public List<int> Px { get; set; } = new List<int>();
- /// <summary>
- /// Gets or sets the entity width in pixels.
- /// </summary>
- [JsonPropertyName("width")]
- public int Width { get; set; }
- /// <summary>
- /// Gets or sets the entity height in pixels.
- /// </summary>
- [JsonPropertyName("height")]
- public int Height { get; set; }
- [JsonPropertyName("__pivot")]
- public List<float> Pivot { get; set; } = new List<float>();
- [JsonPropertyName("__tags")]
- public List<string> Tags { get; set; } = new List<string>();
- /// <summary>
- /// Gets or sets the custom field instances for this entity.
- /// </summary>
- [JsonPropertyName("fieldInstances")]
- public List<LDtkFieldInstance> FieldInstances { get; set; } = new List<LDtkFieldInstance>();
- }
- #endregion
- #region Fields
- /// <summary>
- /// Represents a field definition in LDtk.
- /// </summary>
- public class LDtkFieldDefinition
- {
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- /// <summary>
- /// Gets or sets the field type (Int, Float, String, Bool, Color, Point, FilePath, EntityRef, Enum, etc.).
- /// </summary>
- [JsonPropertyName("__type")]
- public string Type { get; set; }
- [JsonPropertyName("uid")]
- public int Uid { get; set; }
- [JsonPropertyName("type")]
- public string TypeEnum { get; set; }
- /// <summary>
- /// Gets or sets whether this field is an array.
- /// </summary>
- [JsonPropertyName("isArray")]
- public bool IsArray { get; set; }
- [JsonPropertyName("canBeNull")]
- public bool CanBeNull { get; set; }
- }
- /// <summary>
- /// Represents a field instance (custom property value) in LDtk.
- /// </summary>
- public class LDtkFieldInstance
- {
- /// <summary>
- /// Gets or sets the field identifier.
- /// </summary>
- [JsonPropertyName("__identifier")]
- public string Identifier { get; set; }
- /// <summary>
- /// Gets or sets the field type.
- /// </summary>
- [JsonPropertyName("__type")]
- public string Type { get; set; }
- /// <summary>
- /// Gets or sets the field value (can be various types).
- /// </summary>
- [JsonPropertyName("__value")]
- public JsonElement? Value { get; set; }
- [JsonPropertyName("defUid")]
- public int DefUid { get; set; }
- [JsonPropertyName("realEditorValues")]
- public List<object> RealEditorValues { get; set; } = new List<object>();
- }
- #endregion
- #region Auto-Layer
- /// <summary>
- /// Represents an auto-layer rule group in LDtk.
- /// </summary>
- public class LDtkAutoLayerRuleGroup
- {
- [JsonPropertyName("uid")]
- public int Uid { get; set; }
- [JsonPropertyName("name")]
- public string Name { get; set; }
- [JsonPropertyName("active")]
- public bool Active { get; set; }
- [JsonPropertyName("rules")]
- public List<LDtkAutoLayerRule> Rules { get; set; } = new List<LDtkAutoLayerRule>();
- }
- /// <summary>
- /// Represents an auto-layer rule in LDtk.
- /// </summary>
- public class LDtkAutoLayerRule
- {
- [JsonPropertyName("uid")]
- public int Uid { get; set; }
- [JsonPropertyName("active")]
- public bool Active { get; set; }
- [JsonPropertyName("size")]
- public int Size { get; set; }
- [JsonPropertyName("tileRectsIds")]
- public List<List<int>> TileRectsIds { get; set; } = new List<List<int>>();
- [JsonPropertyName("pattern")]
- public List<int> Pattern { get; set; } = new List<int>();
- }
- #endregion
- #region Enum
- /// <summary>
- /// Represents an enum definition in LDtk.
- /// </summary>
- public class LDtkEnumDefinition
- {
- [JsonPropertyName("identifier")]
- public string Identifier { get; set; }
- [JsonPropertyName("uid")]
- public int Uid { get; set; }
- [JsonPropertyName("values")]
- public List<LDtkEnumValue> Values { get; set; } = new List<LDtkEnumValue>();
- [JsonPropertyName("externalRelPath")]
- public string ExternalRelPath { get; set; }
- }
- /// <summary>
- /// Represents an enum value in LDtk.
- /// </summary>
- public class LDtkEnumValue
- {
- [JsonPropertyName("id")]
- public string Id { get; set; }
- [JsonPropertyName("color")]
- public int Color { get; set; }
- }
- #endregion
- #region Supporting Types
- /// <summary>
- /// Represents a grid point coordinate in LDtk.
- /// </summary>
- public class LDtkGridPoint
- {
- [JsonPropertyName("cx")]
- public int Cx { get; set; }
- [JsonPropertyName("cy")]
- public int Cy { get; set; }
- }
- /// <summary>
- /// Represents entity reference information in LDtk.
- /// </summary>
- public class LDtkEntityReferenceInfos
- {
- [JsonPropertyName("entityIid")]
- public string EntityIid { get; set; }
- [JsonPropertyName("layerIid")]
- public string LayerIid { get; set; }
- [JsonPropertyName("levelIid")]
- public string LevelIid { get; set; }
- [JsonPropertyName("worldIid")]
- public string WorldIid { get; set; }
- }
- #endregion
|