1using System.Runtime.Serialization;
12[JsonObject(IsReference =
true)]
13public class Cycle : ICloneable, IDisposable
15 [Newtonsoft.Json.JsonIgnore]
16 internal DefinitionProvenance? DefinitionProvenance {
get;
set; }
38 internal long _throttle = 0;
42 #region constructors / destructor
51 public Cycle(
FrameSequence sequence,
double throttleTime,
string cycleKey,
bool hideTileOnCycleEnd =
false)
59 if (
Cycle._cycles.ContainsKey(cycleKey))
60 Cycle._cycles[cycleKey] =
this;
62 Cycle._cycles.Add(cycleKey,
this);
68 _throttle = fromCycle._throttle;
69 _throttleTime = fromCycle._throttleTime;
75 private void OnDeserialized(StreamingContext context)
83 #endregion constructors / destructor
85 #region public properties
87 private double _throttleTime;
94 internal long CurrentFrameThrottle
99 return !
double.IsFinite(ticks) || ticks < 1 || ticks >= long.MaxValue ? 0 : (long)ticks;
109 get {
return _throttleTime; }
112 _throttle = (long)(value * (
double)HighResTimer.TicksPerSecond);
113 _throttleTime = value;
125 if (Enumerable.Range(0,
Sequence.FrameCount).Any(i =>
Sequence.GetDurationSeconds(i).HasValue))
128 for (
int i = 0; i <
Sequence.FrameCount; i++)
164 #endregion public properties
166 #region ICloneable Members
174 return new Cycle(
this);
177 #endregion ICloneable Members
179 #region IDisposable Members
186 GC.SuppressFinalize(
this);
191 sprite.TileAnimator.CurrentCycle =
null;
197 #endregion IDisposable Members
199 #region static members
201 internal static readonly Dictionary<string, Cycle> _cycles =
new();
206 public static int Count => _cycles.Count;
227 if (_cycles.ContainsKey(cycleKey))
239 if (_cycles.ContainsKey(cycleKey))
240 _cycles[cycleKey].Dispose();
248 var tempCycles =
new List<Cycle>(_cycles.Values);
249 foreach (
Cycle cyc
in tempCycles)
253 #endregion static members
References a FrameSequence object, along with a particular Throttle value for animating through Frame...
static void ClearAllAnimationCycles()
Removes and disposes all registered animation cycles.
double TotalCycleTime
Returns the total time in seconds for the Cycle.
static int Count
Gets the total number of animation cycles currently registered.
double ThrottleTime
Gets or sets the time in seconds between frame transitions in the animation cycle.
object Clone()
Creates a shallow copy of the current Cycle instance.
double CurrentFrameDurationSeconds
Effective duration of the currently displayed frame.
Cycle NextCycle
Gets or sets the next cycle to transition to when this cycle completes.
static void ClearAnimationCycle(string cycleKey)
Removes and disposes the animation cycle with the specified key.
Cycle(FrameSequence sequence, double throttleTime, string cycleKey, bool hideTileOnCycleEnd=false)
Initializes a new instance of the Cycle class.
static Cycle GetAnimationCycle(string cycleKey)
Retrieves a clone of the animation cycle with the specified key.
void Dispose()
Releases all resources used by the Cycle and removes it from the static cycle collection.
readonly bool HideTileOnCycleEnd
Indicates whether the tile should be hidden when the cycle completes.
FrameSequence Sequence
The frame sequence used by this animation cycle.
static List< string > GetAnimationCycleKeys()
Retrieves a list of all registered animation cycle keys.
static List< Cycle > GetAnimationCycles()
Retrieves a list of all registered animation cycles.
readonly string CycleKey
The unique identifier key for this cycle.
Manages the lifecycle, lookup, and per-frame updates of all active Sprite instances.
static SpriteManager Instance
Gets the singleton instance of the sprite manager.
Represents a movable visual element on a scene layer.
virtual Animator TileAnimator
Gets the animator associated with this tile.
CycleType
Simple is self-terminating; the other two are repeating.
Represents a sequence of animation frames that can be cycled through using different animation patter...