2023-11-11 14:47:07 -07:00
|
|
|
using Godot;
|
|
|
|
using System;
|
2023-11-11 17:23:00 -07:00
|
|
|
using System.Collections.Generic;
|
2023-11-11 14:47:07 -07:00
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
public partial class TASable : Node
|
|
|
|
{
|
2023-11-11 17:23:00 -07:00
|
|
|
[Export] RigidBody3D _assignedRigidBody3D;
|
|
|
|
|
|
|
|
public RigidBody3D AssignedRigidBody3D
|
|
|
|
{
|
|
|
|
get { return this._assignedRigidBody3D; }
|
|
|
|
}
|
|
|
|
|
2023-11-11 18:50:16 -07:00
|
|
|
// Frame data
|
2023-11-11 17:23:00 -07:00
|
|
|
public Dictionary<int, Vector3> framePositions = new Dictionary<int, Vector3>();
|
2023-11-11 20:46:11 -07:00
|
|
|
public Dictionary<int, Vector3> frameRotations = new Dictionary<int, Vector3>();
|
2023-11-11 18:50:16 -07:00
|
|
|
public Dictionary<int, Vector3> frameLinearVelocities = new Dictionary<int, Vector3>();
|
|
|
|
public Dictionary<int, Vector3> frameAngularVelocities = new Dictionary<int, Vector3>();
|
2023-11-11 17:23:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
public virtual void SaveState(int frame)
|
|
|
|
{
|
|
|
|
this.framePositions[frame] = this.AssignedRigidBody3D.Position;
|
2023-11-11 20:46:11 -07:00
|
|
|
this.frameRotations[frame] = this.AssignedRigidBody3D.Rotation;
|
2023-11-11 18:50:16 -07:00
|
|
|
this.frameLinearVelocities[frame] = this.AssignedRigidBody3D.LinearVelocity;
|
|
|
|
this.frameAngularVelocities[frame] = this.AssignedRigidBody3D.AngularVelocity;
|
2023-11-11 17:23:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void LoadState(int frame)
|
|
|
|
{
|
|
|
|
this.AssignedRigidBody3D.Position = this.framePositions[frame];
|
2023-11-11 20:46:11 -07:00
|
|
|
this.AssignedRigidBody3D.Rotation = this.frameRotations[frame];
|
2023-11-11 18:50:16 -07:00
|
|
|
this.AssignedRigidBody3D.LinearVelocity = this.frameLinearVelocities[frame];
|
|
|
|
this.AssignedRigidBody3D.AngularVelocity = this.frameAngularVelocities[frame];
|
2023-11-11 17:23:00 -07:00
|
|
|
}
|
|
|
|
|
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;
|
2023-11-11 17:23:00 -07:00
|
|
|
TAS.StartedIncrementing += this.OnStartedIncrementing;
|
|
|
|
TAS.StoppedIncrementing += this.OnStoppedIncrementing;
|
2023-11-11 18:50:16 -07:00
|
|
|
TAS.FramesReset += this.OnFramesReset;
|
2023-11-11 17:23:00 -07:00
|
|
|
|
|
|
|
this.SaveState(0);
|
2023-11-11 14:47:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnFrameIncremented(int newFrame)
|
|
|
|
{
|
2023-11-11 17:23:00 -07:00
|
|
|
this.SaveState(newFrame);
|
2023-11-11 19:58:56 -07:00
|
|
|
// 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)
|
|
|
|
{
|
2023-11-11 17:23:00 -07:00
|
|
|
this.LoadState(endFrame);
|
2023-11-11 19:58:56 -07:00
|
|
|
// 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)
|
|
|
|
{
|
2023-11-11 17:23:00 -07:00
|
|
|
this.LoadState(endFrame);
|
2023-11-11 19:58:56 -07:00
|
|
|
// GD.Print($"Frames regressed from {startFrame} to {endFrame}, called from node {this.AssignedRigidBody3D.Name}");
|
2023-11-11 17:23:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnStartedIncrementing()
|
|
|
|
{
|
|
|
|
this.AssignedRigidBody3D.Freeze = false;
|
2023-11-11 19:58:56 -07:00
|
|
|
this.AssignedRigidBody3D.LockRotation = false;
|
2023-11-11 17:23:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void OnStoppedIncrementing()
|
|
|
|
{
|
|
|
|
this.AssignedRigidBody3D.Freeze = true;
|
2023-11-11 19:58:56 -07:00
|
|
|
this.AssignedRigidBody3D.LockRotation = true;
|
2023-11-11 14:47:07 -07:00
|
|
|
}
|
2023-11-11 18:50:16 -07:00
|
|
|
|
|
|
|
public virtual void OnFramesReset()
|
|
|
|
{
|
|
|
|
this.SaveState(0);
|
|
|
|
}
|
2023-11-11 14:47:07 -07:00
|
|
|
}
|