Animation.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. namespace OpenVIII.Battle.Dat
  6. {
  7. /// <summary>
  8. /// Section 3c: Model animation frames container
  9. /// </summary>
  10. /// <see cref="http://wiki.ffrtt.ru/index.php/FF8/FileFormat_DAT#Animation"/>
  11. public struct Animation : IReadOnlyList<AnimationFrame>
  12. {
  13. #region Fields
  14. private readonly IReadOnlyList<AnimationFrame> _animationFrames;
  15. #endregion Fields
  16. #region Constructors
  17. public Animation(BinaryReader br, Skeleton skeleton) : this()
  18. {
  19. var cFrames = br.ReadByte();
  20. _animationFrames = AnimationFrame.CreateInstances(br, cFrames, skeleton);
  21. }
  22. #endregion Constructors
  23. #region Properties
  24. public int Count => _animationFrames.Count;
  25. #endregion Properties
  26. #region Indexers
  27. public AnimationFrame this[int index] => _animationFrames[index];
  28. #endregion Indexers
  29. #region Methods
  30. public static Animation CreateInstance(BinaryReader br, long byteOffset, Skeleton skeleton)
  31. {
  32. br.BaseStream.Seek(byteOffset, SeekOrigin.Begin);
  33. return new Animation(br, skeleton);
  34. }
  35. public static IReadOnlyList<Animation> CreateInstances(BinaryReader br, IEnumerable<uint> pAnimations, Skeleton skeleton) => pAnimations.Select(x => CreateInstance(br, x, skeleton)).ToList().AsReadOnly();
  36. public IEnumerator<AnimationFrame> GetEnumerator() => _animationFrames.GetEnumerator();
  37. IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_animationFrames).GetEnumerator();
  38. #endregion Methods
  39. }
  40. }