using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace OpenVIII.Battle.Dat
{
///
/// Section 3c: Model animation frames container
///
///
public struct Animation : IReadOnlyList
{
#region Fields
private readonly IReadOnlyList _animationFrames;
#endregion Fields
#region Constructors
public Animation(BinaryReader br, Skeleton skeleton) : this()
{
var cFrames = br.ReadByte();
_animationFrames = AnimationFrame.CreateInstances(br, cFrames, skeleton);
}
#endregion Constructors
#region Properties
public int Count => _animationFrames.Count;
#endregion Properties
#region Indexers
public AnimationFrame this[int index] => _animationFrames[index];
#endregion Indexers
#region Methods
public static Animation CreateInstance(BinaryReader br, long byteOffset, Skeleton skeleton)
{
br.BaseStream.Seek(byteOffset, SeekOrigin.Begin);
return new Animation(br, skeleton);
}
public static IReadOnlyList CreateInstances(BinaryReader br, IEnumerable pAnimations, Skeleton skeleton) => pAnimations.Select(x => CreateInstance(br, x, skeleton)).ToList().AsReadOnly();
public IEnumerator GetEnumerator() => _animationFrames.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_animationFrames).GetEnumerator();
#endregion Methods
}
}