using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Netcode;
namespace StardustCore.Animations
{
/// A custom class used to deal with custom animations/
public class Animation
{
/// The source rectangle on the texture to display.
public Rectangle sourceRectangle;
/// The duration of the frame in length.
public int frameDuration;
/// The duration until the next frame.
public int frameCountUntilNextAnimation;
[XmlIgnore]
public NetFields NetFields { get; } = new NetFields();
public Animation()
{
this.sourceRectangle = new Rectangle(0, 0, 16, 16);
this.frameCountUntilNextAnimation = -1;
this.frameDuration = -1;
}
/// Constructor that causes the animation frame count to be set to -1; This forces it to never change.
/// The draw source for this animation.
public Animation(Rectangle SourceRectangle)
{
this.sourceRectangle = SourceRectangle;
this.frameCountUntilNextAnimation = -1;
this.frameDuration = -1;
}
/// Construct an instance.
/// The draw source for this animation.
/// How many on screen frames this animation stays for. Every draw frame decrements an active animation by 1 frame. Set this to -1 to have it be on the screen infinitely.
public Animation(Rectangle SourceRectangle, int existForXFrames)
{
this.sourceRectangle = SourceRectangle;
this.frameDuration = existForXFrames;
}
/// Decrements the amount of frames this animation is on the screen for by 1.
public void tickAnimationFrame()
{
this.frameCountUntilNextAnimation--;
}
/// This sets the animation frame count to be the max duration. I.E restart the timer.
public void startAnimation()
{
this.frameCountUntilNextAnimation = this.frameDuration;
}
}
}