AnimationSystem.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System.Collections.Concurrent;
  2. namespace OpenVIII.Battle
  3. {
  4. /// <summary>
  5. /// Animation system. Decided to go for struct, so I can attach it to instance and manipulate
  6. /// easily grouped. It's also open for modifications
  7. /// </summary>
  8. public struct AnimationSystem
  9. {
  10. #region Fields
  11. public ConcurrentQueue<int> AnimationQueue;
  12. private int _animationFrame;
  13. private int _animationId;
  14. private int _lastAnimationFrame;
  15. private int _lastAnimationId;
  16. private bool bAnimationStopped;
  17. #endregion Fields
  18. #region Properties
  19. public int AnimationFrame
  20. {
  21. get => _animationFrame; set
  22. {
  23. _lastAnimationFrame = _animationFrame;
  24. _animationFrame = value;
  25. if (_animationFrame > 0 && _lastAnimationId != _animationId)
  26. _lastAnimationId = _animationId;
  27. }
  28. }
  29. public int AnimationId
  30. {
  31. get => _animationId; set
  32. {
  33. _lastAnimationId = _animationId;
  34. _animationId = value;
  35. AnimationFrame = 0;
  36. }
  37. }
  38. public bool AnimationStopped => bAnimationStopped;
  39. public int LastAnimationFrame { get => _lastAnimationFrame; private set => _lastAnimationFrame = value; }
  40. public int LastAnimationId { get => _lastAnimationId; private set => _lastAnimationId = value; }
  41. #endregion Properties
  42. #region Methods
  43. public int NextFrame() => ++AnimationFrame;
  44. public bool StartAnimation() => bAnimationStopped = false;
  45. public bool StopAnimation()
  46. {
  47. LastAnimationFrame = AnimationFrame;
  48. AnimationId = AnimationId;
  49. return bAnimationStopped = true;
  50. }
  51. #endregion Methods
  52. }
  53. }