using System;
using System.Collections.ObjectModel;
using System.IO;
using UnityEngine.Assertions;
namespace UnityEditor.U2D.Aseprite
{
///
/// Parsed representation of an Aseprite frame.
///
public class FrameData : IDisposable
{
///
/// Bytes in this frame.
///
public uint noOfBytes { get; private set; }
///
/// Frame duration in milliseconds.
///
public ushort frameDuration { get; private set; }
///
/// Number of chunks.
///
public uint chunkCount { get; private set; }
///
/// Chunk data for this frame.
///
public ReadOnlyCollection chunks => Array.AsReadOnly(m_Chunks);
BaseChunk[] m_Chunks;
internal void Read(BinaryReader reader)
{
noOfBytes = reader.ReadUInt32();
var misc0 = reader.ReadUInt16();
var legacyChunkCount = reader.ReadUInt16();
frameDuration = reader.ReadUInt16();
var misc1 = reader.ReadByte();
var misc2 = reader.ReadByte();
var chunkCount = reader.ReadUInt32();
Assert.IsTrue(misc0 == 0xF1FA, "Reading mismatch.");
this.chunkCount = chunkCount != 0 ? chunkCount : legacyChunkCount;
m_Chunks = new BaseChunk[this.chunkCount];
}
internal void SetChunkData(int index, BaseChunk data)
{
if (index < 0 || index >= m_Chunks.Length)
return;
m_Chunks[index] = data;
}
public void Dispose()
{
for (var i = 0; i < m_Chunks.Length; ++i)
m_Chunks[i].Dispose();
}
}
}