No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TilesetChunk.cs 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.IO;
  4. namespace UnityEditor.U2D.Aseprite
  5. {
  6. /// <summary>
  7. /// Flags to define where data for a tileset is stored.
  8. /// </summary>
  9. [Flags]
  10. public enum TileSetFlags
  11. {
  12. IncludesLinkToExternal = 1,
  13. IncludesTilesInFile = 2,
  14. Misc = 4,
  15. }
  16. /// <summary>
  17. /// Parsed representation of an Aseprite Tileset chunk.
  18. /// </summary>
  19. /// <note>Not supported yet.</note>
  20. public class TilesetChunk : BaseChunk
  21. {
  22. public override ChunkTypes chunkType => ChunkTypes.Tileset;
  23. /// <summary>
  24. /// The ID of the tileset.
  25. /// </summary>
  26. public uint tileSetId { get; private set; }
  27. /// <summary>
  28. /// Flags to define where data for a tileset is stored.
  29. /// </summary>
  30. public TileSetFlags tileSetFlags { get; private set; }
  31. /// <summary>
  32. /// The number of tiles in the tileset.
  33. /// </summary>
  34. public uint noOfTiles { get; private set; }
  35. /// <summary>
  36. /// Tile width in pixels.
  37. /// </summary>
  38. public ushort width { get; private set; }
  39. /// <summary>
  40. /// Tile height in pixels.
  41. /// </summary>
  42. public ushort height { get; private set; }
  43. /// <summary>
  44. /// The name of the tileset.
  45. /// </summary>
  46. public string tileSetName { get; private set; }
  47. readonly ushort m_ColorDepth;
  48. readonly ReadOnlyCollection<PaletteEntry> m_PaletteEntries;
  49. readonly byte m_AlphaPaletteEntry;
  50. internal TilesetChunk(uint chunkSize, ushort colorDepth, ReadOnlyCollection<PaletteEntry> paletteEntries, byte alphaPaletteEntry) : base(chunkSize)
  51. {
  52. m_ColorDepth = colorDepth;
  53. m_PaletteEntries = paletteEntries;
  54. m_AlphaPaletteEntry = alphaPaletteEntry;
  55. }
  56. protected override void InternalRead(BinaryReader reader)
  57. {
  58. tileSetId = reader.ReadUInt32();
  59. tileSetFlags = (TileSetFlags)reader.ReadUInt32();
  60. noOfTiles = reader.ReadUInt32();
  61. width = reader.ReadUInt16();
  62. height = reader.ReadUInt16();
  63. var baseIndex = reader.ReadInt16();
  64. var reservedBytes = reader.ReadBytes(14);
  65. tileSetName = AsepriteUtilities.ReadString(reader);
  66. // Not supported yet.
  67. if ((tileSetFlags & TileSetFlags.IncludesLinkToExternal) != 0)
  68. {
  69. var idOfExternalFile = reader.ReadUInt32();
  70. var tileSetIdInExternal = reader.ReadUInt32();
  71. }
  72. if ((tileSetFlags & TileSetFlags.IncludesTilesInFile) != 0)
  73. {
  74. var compressedDataLength = (int)reader.ReadUInt32();
  75. var decompressedData = AsepriteUtilities.ReadAndDecompressedData(reader, compressedDataLength);
  76. var image = AsepriteUtilities.GenerateImageData(m_ColorDepth, decompressedData, m_PaletteEntries, m_AlphaPaletteEntry);
  77. // Disposing for now.
  78. image.Dispose();
  79. }
  80. }
  81. }
  82. }