LDtkJsonContent.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. using System.Collections.Generic;
  2. using System.Text.Json;
  3. using System.Text.Json.Serialization;
  4. namespace MonoGame.Extended.Tilemaps.LDtk;
  5. // JSON deserialization models for LDtk JSON files
  6. // These classes are public to support JSON serialization, but represent internal parsing structures
  7. #region Project
  8. /// <summary>
  9. /// Represents the root of an LDtk project JSON file.
  10. /// </summary>
  11. public class LDtkProject
  12. {
  13. /// <summary>
  14. /// Gets or sets the unique project instance identifier.
  15. /// </summary>
  16. [JsonPropertyName("iid")]
  17. public string Iid { get; set; }
  18. /// <summary>
  19. /// Gets or sets the LDtk JSON format version.
  20. /// </summary>
  21. [JsonPropertyName("jsonVersion")]
  22. public string JsonVersion { get; set; }
  23. /// <summary>
  24. /// Gets or sets the LDtk application build identifier.
  25. /// </summary>
  26. [JsonPropertyName("appBuildId")]
  27. public int AppBuildId { get; set; }
  28. [JsonPropertyName("nextUid")]
  29. public int NextUid { get; set; }
  30. [JsonPropertyName("identifierStyle")]
  31. public string IdentifierStyle { get; set; }
  32. /// <summary>
  33. /// Gets or sets the world layout mode (Free, GridVania, LinearHorizontal, LinearVertical).
  34. /// </summary>
  35. [JsonPropertyName("worldLayout")]
  36. public string WorldLayout { get; set; }
  37. [JsonPropertyName("worldGridWidth")]
  38. public int? WorldGridWidth { get; set; }
  39. [JsonPropertyName("worldGridHeight")]
  40. public int? WorldGridHeight { get; set; }
  41. [JsonPropertyName("defaultLevelWidth")]
  42. public int? DefaultLevelWidth { get; set; }
  43. [JsonPropertyName("defaultLevelHeight")]
  44. public int? DefaultLevelHeight { get; set; }
  45. /// <summary>
  46. /// Gets or sets the default grid size for layers.
  47. /// </summary>
  48. [JsonPropertyName("defaultGridSize")]
  49. public int DefaultGridSize { get; set; }
  50. [JsonPropertyName("defaultPivotX")]
  51. public float DefaultPivotX { get; set; }
  52. [JsonPropertyName("defaultPivotY")]
  53. public float DefaultPivotY { get; set; }
  54. /// <summary>
  55. /// Gets or sets the project background color in #RRGGBB format.
  56. /// </summary>
  57. [JsonPropertyName("bgColor")]
  58. public string BgColor { get; set; }
  59. [JsonPropertyName("defaultLevelBgColor")]
  60. public string DefaultLevelBgColor { get; set; }
  61. [JsonPropertyName("externalLevels")]
  62. public bool ExternalLevels { get; set; }
  63. /// <summary>
  64. /// Gets or sets the collection of levels in this project.
  65. /// </summary>
  66. [JsonPropertyName("levels")]
  67. public List<LDtkLevel> Levels { get; set; } = new List<LDtkLevel>();
  68. /// <summary>
  69. /// Gets or sets the project definitions (layers, entities, tilesets, enums).
  70. /// </summary>
  71. [JsonPropertyName("defs")]
  72. public LDtkDefinitions Defs { get; set; }
  73. [JsonPropertyName("worlds")]
  74. public List<LDtkWorld> Worlds { get; set; } = new List<LDtkWorld>();
  75. [JsonPropertyName("dummyWorldIid")]
  76. public string DummyWorldIid { get; set; }
  77. /// <summary>
  78. /// Gets or sets the table of contents listing all entity instances with exportToToc enabled.
  79. /// </summary>
  80. [JsonPropertyName("toc")]
  81. public List<LDtkTableOfContentEntry> Toc { get; set; } = new List<LDtkTableOfContentEntry>();
  82. }
  83. /// <summary>
  84. /// Represents a table of contents entry for an entity type in LDtk.
  85. /// </summary>
  86. public class LDtkTableOfContentEntry
  87. {
  88. /// <summary>
  89. /// Gets or sets the entity identifier.
  90. /// </summary>
  91. [JsonPropertyName("identifier")]
  92. public string Identifier { get; set; }
  93. /// <summary>
  94. /// Gets or sets the collection of entity instance data.
  95. /// </summary>
  96. [JsonPropertyName("instancesData")]
  97. public List<LDtkTocInstanceData> InstancesData { get; set; } = new List<LDtkTocInstanceData>();
  98. }
  99. /// <summary>
  100. /// Represents instance data for a table of contents entry in LDtk.
  101. /// </summary>
  102. public class LDtkTocInstanceData
  103. {
  104. /// <summary>
  105. /// Gets or sets the IID information for this instance.
  106. /// </summary>
  107. [JsonPropertyName("iids")]
  108. public LDtkEntityReferenceInfos Iids { get; set; }
  109. /// <summary>
  110. /// Gets or sets the world X coordinate in pixels.
  111. /// </summary>
  112. [JsonPropertyName("worldX")]
  113. public int WorldX { get; set; }
  114. /// <summary>
  115. /// Gets or sets the world Y coordinate in pixels.
  116. /// </summary>
  117. [JsonPropertyName("worldY")]
  118. public int WorldY { get; set; }
  119. /// <summary>
  120. /// Gets or sets the width in pixels.
  121. /// </summary>
  122. [JsonPropertyName("widPx")]
  123. public int WidPx { get; set; }
  124. /// <summary>
  125. /// Gets or sets the height in pixels.
  126. /// </summary>
  127. [JsonPropertyName("heiPx")]
  128. public int HeiPx { get; set; }
  129. /// <summary>
  130. /// Gets or sets the entity custom field values (exportToToc fields only).
  131. /// </summary>
  132. [JsonPropertyName("fields")]
  133. public JsonElement? Fields { get; set; }
  134. }
  135. /// <summary>
  136. /// Represents all definitions in an LDtk project.
  137. /// </summary>
  138. public class LDtkDefinitions
  139. {
  140. /// <summary>
  141. /// Gets or sets the collection of layer definitions.
  142. /// </summary>
  143. [JsonPropertyName("layers")]
  144. public List<LDtkLayerDefinition> Layers { get; set; } = new List<LDtkLayerDefinition>();
  145. /// <summary>
  146. /// Gets or sets the collection of entity definitions.
  147. /// </summary>
  148. [JsonPropertyName("entities")]
  149. public List<LDtkEntityDefinition> Entities { get; set; } = new List<LDtkEntityDefinition>();
  150. /// <summary>
  151. /// Gets or sets the collection of tileset definitions.
  152. /// </summary>
  153. [JsonPropertyName("tilesets")]
  154. public List<LDtkTilesetDefinition> Tilesets { get; set; } = new List<LDtkTilesetDefinition>();
  155. /// <summary>
  156. /// Gets or sets the collection of enum definitions.
  157. /// </summary>
  158. [JsonPropertyName("enums")]
  159. public List<LDtkEnumDefinition> Enums { get; set; } = new List<LDtkEnumDefinition>();
  160. [JsonPropertyName("externalEnums")]
  161. public List<LDtkEnumDefinition> ExternalEnums { get; set; } = new List<LDtkEnumDefinition>();
  162. [JsonPropertyName("levelFields")]
  163. public List<LDtkFieldDefinition> LevelFields { get; set; } = new List<LDtkFieldDefinition>();
  164. }
  165. /// <summary>
  166. /// Represents a world in an LDtk project (multi-worlds support).
  167. /// </summary>
  168. public class LDtkWorld
  169. {
  170. [JsonPropertyName("identifier")]
  171. public string Identifier { get; set; }
  172. [JsonPropertyName("iid")]
  173. public string Iid { get; set; }
  174. [JsonPropertyName("levels")]
  175. public List<LDtkLevel> Levels { get; set; } = new List<LDtkLevel>();
  176. [JsonPropertyName("worldGridWidth")]
  177. public int WorldGridWidth { get; set; }
  178. [JsonPropertyName("worldGridHeight")]
  179. public int WorldGridHeight { get; set; }
  180. [JsonPropertyName("worldLayout")]
  181. public string WorldLayout { get; set; }
  182. [JsonPropertyName("defaultLevelWidth")]
  183. public int DefaultLevelWidth { get; set; }
  184. [JsonPropertyName("defaultLevelHeight")]
  185. public int DefaultLevelHeight { get; set; }
  186. }
  187. #endregion
  188. #region Level
  189. /// <summary>
  190. /// Represents a level in an LDtk project.
  191. /// </summary>
  192. public class LDtkLevel
  193. {
  194. /// <summary>
  195. /// Gets or sets the level identifier.
  196. /// </summary>
  197. [JsonPropertyName("identifier")]
  198. public string Identifier { get; set; }
  199. /// <summary>
  200. /// Gets or sets the unique level instance identifier.
  201. /// </summary>
  202. [JsonPropertyName("iid")]
  203. public string Iid { get; set; }
  204. [JsonPropertyName("uid")]
  205. public int Uid { get; set; }
  206. /// <summary>
  207. /// Gets or sets the world X coordinate in pixels.
  208. /// </summary>
  209. [JsonPropertyName("worldX")]
  210. public int WorldX { get; set; }
  211. /// <summary>
  212. /// Gets or sets the world Y coordinate in pixels.
  213. /// </summary>
  214. [JsonPropertyName("worldY")]
  215. public int WorldY { get; set; }
  216. [JsonPropertyName("worldDepth")]
  217. public int WorldDepth { get; set; }
  218. /// <summary>
  219. /// Gets or sets the level width in pixels.
  220. /// </summary>
  221. [JsonPropertyName("pxWid")]
  222. public int PxWid { get; set; }
  223. /// <summary>
  224. /// Gets or sets the level height in pixels.
  225. /// </summary>
  226. [JsonPropertyName("pxHei")]
  227. public int PxHei { get; set; }
  228. /// <summary>
  229. /// Gets or sets the level background color in #RRGGBB format.
  230. /// </summary>
  231. [JsonPropertyName("__bgColor")]
  232. public string BgColor { get; set; }
  233. [JsonPropertyName("bgColor")]
  234. public string BgColorOverride { get; set; }
  235. [JsonPropertyName("bgRelPath")]
  236. public string BgRelPath { get; set; }
  237. [JsonPropertyName("bgPos")]
  238. public string BgPos { get; set; }
  239. [JsonPropertyName("bgPivotX")]
  240. public float BgPivotX { get; set; }
  241. [JsonPropertyName("bgPivotY")]
  242. public float BgPivotY { get; set; }
  243. [JsonPropertyName("externalRelPath")]
  244. public string ExternalRelPath { get; set; }
  245. /// <summary>
  246. /// Gets or sets the custom field instances for this level.
  247. /// </summary>
  248. [JsonPropertyName("fieldInstances")]
  249. public List<LDtkFieldInstance> FieldInstances { get; set; } = new List<LDtkFieldInstance>();
  250. /// <summary>
  251. /// Gets or sets the collection of layer instances in this level.
  252. /// </summary>
  253. [JsonPropertyName("layerInstances")]
  254. public List<LDtkLayerInstance> LayerInstances { get; set; }
  255. /// <summary>
  256. /// Gets or sets the collection of neighbor levels touching this one.
  257. /// </summary>
  258. [JsonPropertyName("__neighbours")]
  259. public List<LDtkNeighbourLevel> Neighbours { get; set; } = new List<LDtkNeighbourLevel>();
  260. }
  261. /// <summary>
  262. /// Represents a neighbor level in LDtk.
  263. /// </summary>
  264. public class LDtkNeighbourLevel
  265. {
  266. /// <summary>
  267. /// Gets or sets the direction to the neighbor (n, s, e, w, ne, nw, se, sw, &lt;, &gt;, o).
  268. /// </summary>
  269. [JsonPropertyName("dir")]
  270. public string Dir { get; set; }
  271. /// <summary>
  272. /// Gets or sets the neighbor level's instance identifier.
  273. /// </summary>
  274. [JsonPropertyName("levelIid")]
  275. public string LevelIid { get; set; }
  276. /// <summary>
  277. /// Gets or sets the neighbor level's UID (deprecated, use levelIid).
  278. /// </summary>
  279. [JsonPropertyName("levelUid")]
  280. public int? LevelUid { get; set; }
  281. }
  282. #endregion
  283. #region Layer
  284. /// <summary>
  285. /// Represents a layer definition in LDtk.
  286. /// </summary>
  287. public class LDtkLayerDefinition
  288. {
  289. /// <summary>
  290. /// Gets or sets the layer type (IntGrid, Entities, Tiles, AutoLayer).
  291. /// </summary>
  292. [JsonPropertyName("__type")]
  293. public string Type { get; set; }
  294. /// <summary>
  295. /// Gets or sets the layer identifier.
  296. /// </summary>
  297. [JsonPropertyName("identifier")]
  298. public string Identifier { get; set; }
  299. [JsonPropertyName("type")]
  300. public string TypeEnum { get; set; }
  301. [JsonPropertyName("uid")]
  302. public int Uid { get; set; }
  303. /// <summary>
  304. /// Gets or sets the grid size for this layer in pixels.
  305. /// </summary>
  306. [JsonPropertyName("gridSize")]
  307. public int GridSize { get; set; }
  308. [JsonPropertyName("displayOpacity")]
  309. public float DisplayOpacity { get; set; }
  310. [JsonPropertyName("pxOffsetX")]
  311. public int PxOffsetX { get; set; }
  312. [JsonPropertyName("pxOffsetY")]
  313. public int PxOffsetY { get; set; }
  314. [JsonPropertyName("parallaxFactorX")]
  315. public float ParallaxFactorX { get; set; }
  316. [JsonPropertyName("parallaxFactorY")]
  317. public float ParallaxFactorY { get; set; }
  318. /// <summary>
  319. /// Gets or sets the tileset definition UID for this layer (null if not a tile layer).
  320. /// </summary>
  321. [JsonPropertyName("tilesetDefUid")]
  322. public int? TilesetDefUid { get; set; }
  323. [JsonPropertyName("autoSourceLayerDefUid")]
  324. public int? AutoSourceLayerDefUid { get; set; }
  325. /// <summary>
  326. /// Gets or sets the IntGrid value definitions for IntGrid layers.
  327. /// </summary>
  328. [JsonPropertyName("intGridValues")]
  329. public List<LDtkIntGridValueDefinition> IntGridValues { get; set; } = new List<LDtkIntGridValueDefinition>();
  330. [JsonPropertyName("autoRuleGroups")]
  331. public List<LDtkAutoLayerRuleGroup> AutoRuleGroups { get; set; } = new List<LDtkAutoLayerRuleGroup>();
  332. }
  333. /// <summary>
  334. /// Represents a layer instance in an LDtk level.
  335. /// </summary>
  336. public class LDtkLayerInstance
  337. {
  338. /// <summary>
  339. /// Gets or sets the layer identifier.
  340. /// </summary>
  341. [JsonPropertyName("__identifier")]
  342. public string Identifier { get; set; }
  343. /// <summary>
  344. /// Gets or sets the layer type (IntGrid, Entities, Tiles, AutoLayer).
  345. /// </summary>
  346. [JsonPropertyName("__type")]
  347. public string Type { get; set; }
  348. /// <summary>
  349. /// Gets or sets the layer width in grid cells.
  350. /// </summary>
  351. [JsonPropertyName("__cWid")]
  352. public int CWid { get; set; }
  353. /// <summary>
  354. /// Gets or sets the layer height in grid cells.
  355. /// </summary>
  356. [JsonPropertyName("__cHei")]
  357. public int CHei { get; set; }
  358. /// <summary>
  359. /// Gets or sets the grid size in pixels.
  360. /// </summary>
  361. [JsonPropertyName("__gridSize")]
  362. public int GridSize { get; set; }
  363. /// <summary>
  364. /// Gets or sets the layer opacity (0.0 to 1.0).
  365. /// </summary>
  366. [JsonPropertyName("__opacity")]
  367. public float Opacity { get; set; }
  368. [JsonPropertyName("__pxTotalOffsetX")]
  369. public int PxTotalOffsetX { get; set; }
  370. [JsonPropertyName("__pxTotalOffsetY")]
  371. public int PxTotalOffsetY { get; set; }
  372. /// <summary>
  373. /// Gets or sets the tileset definition UID for this layer instance.
  374. /// </summary>
  375. [JsonPropertyName("__tilesetDefUid")]
  376. public int? TilesetDefUid { get; set; }
  377. [JsonPropertyName("__tilesetRelPath")]
  378. public string TilesetRelPath { get; set; }
  379. [JsonPropertyName("iid")]
  380. public string Iid { get; set; }
  381. [JsonPropertyName("levelId")]
  382. public int LevelId { get; set; }
  383. [JsonPropertyName("layerDefUid")]
  384. public int LayerDefUid { get; set; }
  385. [JsonPropertyName("pxOffsetX")]
  386. public int PxOffsetX { get; set; }
  387. [JsonPropertyName("pxOffsetY")]
  388. public int PxOffsetY { get; set; }
  389. /// <summary>
  390. /// Gets or sets whether the layer is visible.
  391. /// </summary>
  392. [JsonPropertyName("visible")]
  393. public bool Visible { get; set; }
  394. /// <summary>
  395. /// Gets or sets the parallax horizontal factor (from -1 to 1, defaults to 0).
  396. /// </summary>
  397. [JsonPropertyName("__parallaxFactorX")]
  398. public float ParallaxFactorX { get; set; }
  399. /// <summary>
  400. /// Gets or sets the parallax vertical factor (from -1 to 1, defaults to 0).
  401. /// </summary>
  402. [JsonPropertyName("__parallaxFactorY")]
  403. public float ParallaxFactorY { get; set; }
  404. /// <summary>
  405. /// Gets or sets the tile instances for Tiles layers.
  406. /// </summary>
  407. [JsonPropertyName("gridTiles")]
  408. public List<LDtkTileInstance> GridTiles { get; set; } = new List<LDtkTileInstance>();
  409. /// <summary>
  410. /// Gets or sets the auto-layer tile instances for IntGrid layers.
  411. /// </summary>
  412. [JsonPropertyName("autoLayerTiles")]
  413. public List<LDtkTileInstance> AutoLayerTiles { get; set; } = new List<LDtkTileInstance>();
  414. /// <summary>
  415. /// Gets or sets the entity instances for Entities layers.
  416. /// </summary>
  417. [JsonPropertyName("entityInstances")]
  418. public List<LDtkEntityInstance> EntityInstances { get; set; } = new List<LDtkEntityInstance>();
  419. /// <summary>
  420. /// Gets or sets the IntGrid values in CSV format for IntGrid layers.
  421. /// </summary>
  422. [JsonPropertyName("intGridCsv")]
  423. public List<int> IntGridCsv { get; set; } = new List<int>();
  424. }
  425. #endregion
  426. #region Tileset
  427. /// <summary>
  428. /// Represents a tileset definition in LDtk.
  429. /// </summary>
  430. public class LDtkTilesetDefinition
  431. {
  432. /// <summary>
  433. /// Gets or sets the tileset identifier.
  434. /// </summary>
  435. [JsonPropertyName("identifier")]
  436. public string Identifier { get; set; }
  437. [JsonPropertyName("uid")]
  438. public int Uid { get; set; }
  439. /// <summary>
  440. /// Gets or sets the relative path to the tileset image.
  441. /// </summary>
  442. [JsonPropertyName("relPath")]
  443. public string RelPath { get; set; }
  444. [JsonPropertyName("embedAtlas")]
  445. public string EmbedAtlas { get; set; }
  446. /// <summary>
  447. /// Gets or sets the tileset image width in pixels.
  448. /// </summary>
  449. [JsonPropertyName("pxWid")]
  450. public int PxWid { get; set; }
  451. /// <summary>
  452. /// Gets or sets the tileset image height in pixels.
  453. /// </summary>
  454. [JsonPropertyName("pxHei")]
  455. public int PxHei { get; set; }
  456. /// <summary>
  457. /// Gets or sets the tile grid size in pixels.
  458. /// </summary>
  459. [JsonPropertyName("tileGridSize")]
  460. public int TileGridSize { get; set; }
  461. /// <summary>
  462. /// Gets or sets the spacing in pixels between tiles.
  463. /// </summary>
  464. [JsonPropertyName("spacing")]
  465. public int Spacing { get; set; }
  466. /// <summary>
  467. /// Gets or sets the padding in pixels around tiles.
  468. /// </summary>
  469. [JsonPropertyName("padding")]
  470. public int Padding { get; set; }
  471. /// <summary>
  472. /// Gets or sets the tileset width in grid cells.
  473. /// </summary>
  474. [JsonPropertyName("__cWid")]
  475. public int CWid { get; set; }
  476. /// <summary>
  477. /// Gets or sets the tileset height in grid cells.
  478. /// </summary>
  479. [JsonPropertyName("__cHei")]
  480. public int CHei { get; set; }
  481. }
  482. /// <summary>
  483. /// Represents a tile instance in an LDtk layer.
  484. /// </summary>
  485. public class LDtkTileInstance
  486. {
  487. /// <summary>
  488. /// Gets or sets the pixel coordinates [x, y] of the tile in the layer.
  489. /// </summary>
  490. [JsonPropertyName("px")]
  491. public List<int> Px { get; set; } = new List<int>();
  492. /// <summary>
  493. /// Gets or sets the source pixel coordinates [x, y] in the tileset.
  494. /// </summary>
  495. [JsonPropertyName("src")]
  496. public List<int> Src { get; set; } = new List<int>();
  497. /// <summary>
  498. /// Gets or sets the flip flags (0=none, 1=X, 2=Y, 3=XY).
  499. /// </summary>
  500. [JsonPropertyName("f")]
  501. public int F { get; set; }
  502. /// <summary>
  503. /// Gets or sets the tile ID in the tileset.
  504. /// </summary>
  505. [JsonPropertyName("t")]
  506. public int T { get; set; }
  507. [JsonPropertyName("d")]
  508. public List<int> D { get; set; } = new List<int>();
  509. /// <summary>
  510. /// Gets or sets the tile alpha/opacity (0.0 to 1.0).
  511. /// </summary>
  512. [JsonPropertyName("a")]
  513. public float A { get; set; } = 1.0f;
  514. }
  515. /// <summary>
  516. /// Represents an IntGrid value definition in LDtk.
  517. /// </summary>
  518. public class LDtkIntGridValueDefinition
  519. {
  520. [JsonPropertyName("value")]
  521. public int Value { get; set; }
  522. [JsonPropertyName("identifier")]
  523. public string Identifier { get; set; }
  524. [JsonPropertyName("color")]
  525. public string Color { get; set; }
  526. }
  527. #endregion
  528. #region Entity
  529. /// <summary>
  530. /// Represents an entity definition in LDtk.
  531. /// </summary>
  532. public class LDtkEntityDefinition
  533. {
  534. /// <summary>
  535. /// Gets or sets the entity identifier.
  536. /// </summary>
  537. [JsonPropertyName("identifier")]
  538. public string Identifier { get; set; }
  539. [JsonPropertyName("uid")]
  540. public int Uid { get; set; }
  541. /// <summary>
  542. /// Gets or sets the entity width in pixels.
  543. /// </summary>
  544. [JsonPropertyName("width")]
  545. public int Width { get; set; }
  546. /// <summary>
  547. /// Gets or sets the entity height in pixels.
  548. /// </summary>
  549. [JsonPropertyName("height")]
  550. public int Height { get; set; }
  551. /// <summary>
  552. /// Gets or sets the entity color in #RRGGBB format.
  553. /// </summary>
  554. [JsonPropertyName("color")]
  555. public string Color { get; set; }
  556. [JsonPropertyName("pivotX")]
  557. public float PivotX { get; set; }
  558. [JsonPropertyName("pivotY")]
  559. public float PivotY { get; set; }
  560. /// <summary>
  561. /// Gets or sets the custom field definitions for this entity.
  562. /// </summary>
  563. [JsonPropertyName("fieldDefs")]
  564. public List<LDtkFieldDefinition> FieldDefs { get; set; } = new List<LDtkFieldDefinition>();
  565. [JsonPropertyName("tags")]
  566. public List<string> Tags { get; set; } = new List<string>();
  567. }
  568. /// <summary>
  569. /// Represents an entity instance in an LDtk level.
  570. /// </summary>
  571. public class LDtkEntityInstance
  572. {
  573. /// <summary>
  574. /// Gets or sets the entity identifier.
  575. /// </summary>
  576. [JsonPropertyName("__identifier")]
  577. public string Identifier { get; set; }
  578. /// <summary>
  579. /// Gets or sets the unique entity instance identifier.
  580. /// </summary>
  581. [JsonPropertyName("iid")]
  582. public string Iid { get; set; }
  583. [JsonPropertyName("defUid")]
  584. public int DefUid { get; set; }
  585. /// <summary>
  586. /// Gets or sets the pixel coordinates [x, y] of the entity.
  587. /// </summary>
  588. [JsonPropertyName("px")]
  589. public List<int> Px { get; set; } = new List<int>();
  590. /// <summary>
  591. /// Gets or sets the entity width in pixels.
  592. /// </summary>
  593. [JsonPropertyName("width")]
  594. public int Width { get; set; }
  595. /// <summary>
  596. /// Gets or sets the entity height in pixels.
  597. /// </summary>
  598. [JsonPropertyName("height")]
  599. public int Height { get; set; }
  600. [JsonPropertyName("__pivot")]
  601. public List<float> Pivot { get; set; } = new List<float>();
  602. [JsonPropertyName("__tags")]
  603. public List<string> Tags { get; set; } = new List<string>();
  604. /// <summary>
  605. /// Gets or sets the custom field instances for this entity.
  606. /// </summary>
  607. [JsonPropertyName("fieldInstances")]
  608. public List<LDtkFieldInstance> FieldInstances { get; set; } = new List<LDtkFieldInstance>();
  609. }
  610. #endregion
  611. #region Fields
  612. /// <summary>
  613. /// Represents a field definition in LDtk.
  614. /// </summary>
  615. public class LDtkFieldDefinition
  616. {
  617. [JsonPropertyName("identifier")]
  618. public string Identifier { get; set; }
  619. /// <summary>
  620. /// Gets or sets the field type (Int, Float, String, Bool, Color, Point, FilePath, EntityRef, Enum, etc.).
  621. /// </summary>
  622. [JsonPropertyName("__type")]
  623. public string Type { get; set; }
  624. [JsonPropertyName("uid")]
  625. public int Uid { get; set; }
  626. [JsonPropertyName("type")]
  627. public string TypeEnum { get; set; }
  628. /// <summary>
  629. /// Gets or sets whether this field is an array.
  630. /// </summary>
  631. [JsonPropertyName("isArray")]
  632. public bool IsArray { get; set; }
  633. [JsonPropertyName("canBeNull")]
  634. public bool CanBeNull { get; set; }
  635. }
  636. /// <summary>
  637. /// Represents a field instance (custom property value) in LDtk.
  638. /// </summary>
  639. public class LDtkFieldInstance
  640. {
  641. /// <summary>
  642. /// Gets or sets the field identifier.
  643. /// </summary>
  644. [JsonPropertyName("__identifier")]
  645. public string Identifier { get; set; }
  646. /// <summary>
  647. /// Gets or sets the field type.
  648. /// </summary>
  649. [JsonPropertyName("__type")]
  650. public string Type { get; set; }
  651. /// <summary>
  652. /// Gets or sets the field value (can be various types).
  653. /// </summary>
  654. [JsonPropertyName("__value")]
  655. public JsonElement? Value { get; set; }
  656. [JsonPropertyName("defUid")]
  657. public int DefUid { get; set; }
  658. [JsonPropertyName("realEditorValues")]
  659. public List<object> RealEditorValues { get; set; } = new List<object>();
  660. }
  661. #endregion
  662. #region Auto-Layer
  663. /// <summary>
  664. /// Represents an auto-layer rule group in LDtk.
  665. /// </summary>
  666. public class LDtkAutoLayerRuleGroup
  667. {
  668. [JsonPropertyName("uid")]
  669. public int Uid { get; set; }
  670. [JsonPropertyName("name")]
  671. public string Name { get; set; }
  672. [JsonPropertyName("active")]
  673. public bool Active { get; set; }
  674. [JsonPropertyName("rules")]
  675. public List<LDtkAutoLayerRule> Rules { get; set; } = new List<LDtkAutoLayerRule>();
  676. }
  677. /// <summary>
  678. /// Represents an auto-layer rule in LDtk.
  679. /// </summary>
  680. public class LDtkAutoLayerRule
  681. {
  682. [JsonPropertyName("uid")]
  683. public int Uid { get; set; }
  684. [JsonPropertyName("active")]
  685. public bool Active { get; set; }
  686. [JsonPropertyName("size")]
  687. public int Size { get; set; }
  688. [JsonPropertyName("tileRectsIds")]
  689. public List<List<int>> TileRectsIds { get; set; } = new List<List<int>>();
  690. [JsonPropertyName("pattern")]
  691. public List<int> Pattern { get; set; } = new List<int>();
  692. }
  693. #endregion
  694. #region Enum
  695. /// <summary>
  696. /// Represents an enum definition in LDtk.
  697. /// </summary>
  698. public class LDtkEnumDefinition
  699. {
  700. [JsonPropertyName("identifier")]
  701. public string Identifier { get; set; }
  702. [JsonPropertyName("uid")]
  703. public int Uid { get; set; }
  704. [JsonPropertyName("values")]
  705. public List<LDtkEnumValue> Values { get; set; } = new List<LDtkEnumValue>();
  706. [JsonPropertyName("externalRelPath")]
  707. public string ExternalRelPath { get; set; }
  708. }
  709. /// <summary>
  710. /// Represents an enum value in LDtk.
  711. /// </summary>
  712. public class LDtkEnumValue
  713. {
  714. [JsonPropertyName("id")]
  715. public string Id { get; set; }
  716. [JsonPropertyName("color")]
  717. public int Color { get; set; }
  718. }
  719. #endregion
  720. #region Supporting Types
  721. /// <summary>
  722. /// Represents a grid point coordinate in LDtk.
  723. /// </summary>
  724. public class LDtkGridPoint
  725. {
  726. [JsonPropertyName("cx")]
  727. public int Cx { get; set; }
  728. [JsonPropertyName("cy")]
  729. public int Cy { get; set; }
  730. }
  731. /// <summary>
  732. /// Represents entity reference information in LDtk.
  733. /// </summary>
  734. public class LDtkEntityReferenceInfos
  735. {
  736. [JsonPropertyName("entityIid")]
  737. public string EntityIid { get; set; }
  738. [JsonPropertyName("layerIid")]
  739. public string LayerIid { get; set; }
  740. [JsonPropertyName("levelIid")]
  741. public string LevelIid { get; set; }
  742. [JsonPropertyName("worldIid")]
  743. public string WorldIid { get; set; }
  744. }
  745. #endregion