2017-09-12 09:35:31 +08:00
using Microsoft.Xna.Framework ;
2018-08-07 11:01:59 +08:00
using Netcode ;
2017-09-12 09:35:31 +08:00
using System ;
using System.Collections.Generic ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
2018-08-07 11:01:59 +08:00
using System.Xml.Serialization ;
2017-09-12 09:35:31 +08:00
namespace StardustCore.Animations
{
2018-05-01 09:21:31 +08:00
/// <summary>
/// A custom class used to deal with custom animations/
/// </summary>
2017-09-12 09:35:31 +08:00
public class Animation
{
2018-08-07 11:01:59 +08:00
/// <summary>
/// The source rectangle on the texture to display.
/// </summary>
2017-09-12 09:35:31 +08:00
public Rectangle sourceRectangle ;
2018-08-07 11:01:59 +08:00
/// <summary>
/// The duration of the frame in length.
/// </summary>
public int frameDuration ;
/// <summary>
/// The duration until the next frame.
/// </summary>
public int frameCountUntilNextAnimation ;
[XmlIgnore]
public NetFields NetFields { get ; } = new NetFields ( ) ;
2017-09-12 09:35:31 +08:00
2018-12-10 17:33:10 +08:00
public Animation ( )
{
2018-12-16 03:49:56 +08:00
this . sourceRectangle = new Rectangle ( 0 , 0 , 16 , 16 ) ;
this . frameCountUntilNextAnimation = - 1 ;
2018-12-15 19:00:32 +08:00
this . frameDuration = - 1 ;
2018-12-10 17:33:10 +08:00
}
2018-03-06 12:46:45 +08:00
/// <summary>
/// Constructor that causes the animation frame count to be set to -1; This forces it to never change.
/// </summary>
/// <param name="SourceRectangle">The draw source for this animation.</param>
public Animation ( Rectangle SourceRectangle )
{
sourceRectangle = SourceRectangle ;
2018-12-16 03:49:56 +08:00
this . frameCountUntilNextAnimation = - 1 ;
2018-03-06 12:46:45 +08:00
frameDuration = - 1 ;
}
/// <summary>
/// Constructor.
/// </summary>
/// <param name="SourceRectangle">The draw source for this animation.</param>
/// <param name="existForXFrames">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.</param>
public Animation ( Rectangle SourceRectangle , int existForXFrames )
2017-09-12 09:35:31 +08:00
{
2018-03-06 12:46:45 +08:00
sourceRectangle = SourceRectangle ;
2017-09-12 09:35:31 +08:00
frameDuration = existForXFrames ;
}
2018-03-06 12:46:45 +08:00
/// <summary>
/// Decrements the amount of frames this animation is on the screen for by 1.
/// </summary>
2017-09-12 09:35:31 +08:00
public void tickAnimationFrame ( )
{
frameCountUntilNextAnimation - - ;
}
2018-03-06 12:46:45 +08:00
/// <summary>
/// This sets the animation frame count to be the max duration. I.E restart the timer.
/// </summary>
2017-09-12 09:35:31 +08:00
public void startAnimation ( )
{
frameCountUntilNextAnimation = frameDuration ;
}
}
}