88 lines
2.9 KiB
C#
88 lines
2.9 KiB
C#
using Godot;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
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> frameRotations = 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.frameRotations[frame] = this.AssignedRigidBody3D.Rotation;
|
|
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.Rotation = this.frameRotations[frame];
|
|
this.AssignedRigidBody3D.LinearVelocity = this.frameLinearVelocities[frame];
|
|
this.AssignedRigidBody3D.AngularVelocity = this.frameAngularVelocities[frame];
|
|
}
|
|
|
|
|
|
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);
|
|
}
|
|
|
|
public virtual void OnFrameIncremented(int newFrame)
|
|
{
|
|
this.SaveState(newFrame);
|
|
// GD.Print($"Frame advanced to {newFrame}, called from node {this.AssignedRigidBody3D.Name}");
|
|
}
|
|
|
|
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}");
|
|
}
|
|
|
|
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;
|
|
this.AssignedRigidBody3D.LockRotation = false;
|
|
}
|
|
|
|
public virtual void OnStoppedIncrementing()
|
|
{
|
|
this.AssignedRigidBody3D.Freeze = true;
|
|
this.AssignedRigidBody3D.LockRotation = true;
|
|
}
|
|
|
|
public virtual void OnFramesReset()
|
|
{
|
|
this.SaveState(0);
|
|
}
|
|
}
|