hurrmmm/godot/TAS_system/TASable.cs

83 lines
2.6 KiB
C#
Raw Normal View History

2023-11-11 14:47:07 -07:00
using Godot;
using System;
using System.Collections.Generic;
2023-11-11 14:47:07 -07:00
using System.Globalization;
public partial class TASable : Node
{
[Export] RigidBody3D _assignedRigidBody3D;
public RigidBody3D AssignedRigidBody3D
{
get { return this._assignedRigidBody3D; }
}
// Frame data
public Dictionary<int, Vector3> framePositions = new Dictionary<int, Vector3>();
public Dictionary<int, Vector3> frameLinearVelocities = new Dictionary<int, Vector3>();
public Dictionary<int, Vector3> frameAngularVelocities = new Dictionary<int, Vector3>();
public virtual void SaveState(int frame)
{
this.framePositions[frame] = this.AssignedRigidBody3D.Position;
this.frameLinearVelocities[frame] = this.AssignedRigidBody3D.LinearVelocity;
this.frameAngularVelocities[frame] = this.AssignedRigidBody3D.AngularVelocity;
}
public virtual void LoadState(int frame)
{
this.AssignedRigidBody3D.Position = this.framePositions[frame];
this.AssignedRigidBody3D.LinearVelocity = this.frameLinearVelocities[frame];
this.AssignedRigidBody3D.AngularVelocity = this.frameAngularVelocities[frame];
}
2023-11-11 14:47:07 -07:00
public override void _Ready()
{
TAS_System TAS = GetNode<TAS_System>("/root/TAS_System");
TAS.FrameIncremented += this.OnFrameIncremented;
TAS.FramesAdvanced += this.OnFramesAdvanced;
TAS.FramesRegressed += this.OnFramesRegressed;
TAS.StartedIncrementing += this.OnStartedIncrementing;
TAS.StoppedIncrementing += this.OnStoppedIncrementing;
TAS.FramesReset += this.OnFramesReset;
this.SaveState(0);
2023-11-11 14:47:07 -07:00
}
public virtual void OnFrameIncremented(int newFrame)
{
this.SaveState(newFrame);
GD.Print($"Frame advanced to {newFrame}, called from node {this.AssignedRigidBody3D.Name}");
2023-11-11 14:47:07 -07:00
}
public virtual void OnFramesAdvanced(int startFrame, int endFrame)
{
this.LoadState(endFrame);
GD.Print($"Frames advanced from {startFrame} to {endFrame}, called from node {this.AssignedRigidBody3D.Name}");
2023-11-11 14:47:07 -07:00
}
public virtual void OnFramesRegressed(int startFrame, int endFrame)
{
this.LoadState(endFrame);
GD.Print($"Frames regressed from {startFrame} to {endFrame}, called from node {this.AssignedRigidBody3D.Name}");
}
public virtual void OnStartedIncrementing()
{
this.AssignedRigidBody3D.Freeze = false;
}
public virtual void OnStoppedIncrementing()
{
this.AssignedRigidBody3D.Freeze = true;
2023-11-11 14:47:07 -07:00
}
public virtual void OnFramesReset()
{
this.SaveState(0);
}
2023-11-11 14:47:07 -07:00
}