hurrmmm/godot/TAS_system/TAS_System.cs

111 lines
2.7 KiB
C#
Raw Normal View History

2023-11-11 11:31:48 -07:00
using Godot;
using System;
public partial class TAS_System : Node
{
2023-11-11 13:11:27 -07:00
private double _frameLength = 0.1;
private bool _isCountingFrames = false;
private Timer _frameTimer;
private int _currentFrame = 0;
private int _lastAdvancedFrame = 0;
public double FrameLength
{
get { return this._frameLength; }
private set { this._frameLength = value; }
}
public bool IsCountingFrames
{
get { return this._isCountingFrames; }
private set { this._isCountingFrames = value; }
}
private Timer FrameTimer
{
get { return this._frameTimer; }
set { this._frameTimer = value; }
}
public int CurrentFrame
{
get { return this._currentFrame; }
private set { this._currentFrame = value; }
}
/// <summary>
/// The last frame that can be advanced to. This will
/// only be greater than CurrentFrame after the player
/// regresses frames, and will be equal to CurrentFrame
/// when the player has just done an action.
/// </summary>
/// <value></value>
public int LastAdvancedFrame
{
get { return this._lastAdvancedFrame; }
private set { this._lastAdvancedFrame = value; }
}
[Signal]
public delegate void FrameAdvancedEventHandler(int currentFrame);
[Signal]
public delegate void FramesAdvancedEventHandler(int numFrames);
[Signal]
public delegate void FramesRegressedEventHandler(int numFrames);
public void StartCountingFrames()
{
}
public void StopCountingFrames()
{
}
public void ResetFrameCount()
{
this.CurrentFrame = 0;
this.LastAdvancedFrame = 0;
}
// Returns how many frames it could successfully advance
public int Advance(int numFrames)
{
int newFrame = Math.Min(this.CurrentFrame + numFrames, this.LastAdvancedFrame);
int framesAdvanced = newFrame - this.CurrentFrame;
EmitSignal(SignalName.FramesAdvanced, framesAdvanced);
return framesAdvanced;
}
// Returns how many frames it could successfully regress
public int Regress(int numFrames)
{
int newFrame = Math.Max(this.CurrentFrame - numFrames, 0);
int framesRegressed = newFrame - this.CurrentFrame;
EmitSignal(SignalName.FramesRegressed, framesRegressed);
return framesRegressed;
}
/// <summary>
/// Gets rid of advanced frames.
/// </summary>
public void DiscardAdvancedFrames()
{
this.LastAdvancedFrame = this.CurrentFrame;
}
// public void Test()
// {
// GD.Print("test123");
// // EmitSignal(SignalName.TestSignal, "test456");
// }
2023-11-11 11:31:48 -07:00
}