Files
2024-07-12 14:32:16 +01:00

34 lines
1.2 KiB
C#

using Godot;
using Skeleton.Utils.Helpers;
using R2 = Skeleton.Algebra.CategoryOf<Skeleton.Algebra.DimensionProviders.IDim2>.OnField<double>.FVector;
namespace Enigmos.Modules.TerminalModules.TestingModules;
public partial class R2Reader : Control
{
private AnimatedSprite2D Direction { get; set; }
private AnimatedSprite2D Magnitude { get; set; }
public R2 UnderlyingVector { get; set; }
private double TargetPhase() => UnderlyingVector == null ? 0: Math.Atan2(UnderlyingVector![2], UnderlyingVector![1]);
private double TargetLength() => UnderlyingVector?.Magnitude ?? 0;
private int TargetPhaseFrame =>
Mathf.FloorToInt((TargetPhase() % (2d * Math.PI) + 2d * Math.PI) % (2d * Math.PI) * 44d / (2d * Math.PI));
private int TargetLengthFrame =>
Mathf.FloorToInt(TargetLength().DoubleCut() * 9d);
public override void _Process(double delta)
{
Magnitude!.SpeedScale = (TargetLengthFrame - Magnitude.Frame) / 7f;
var debug = new[] { TargetPhaseFrame - Direction!.Frame, TargetPhaseFrame + 44 - Direction.Frame };
Direction.SpeedScale = debug.MinBy(Math.Abs) / 25f;
}
public void Init()
{
Direction = GetNode<AnimatedSprite2D>("Direction");
Magnitude = GetNode<AnimatedSprite2D>("Magnitude");
Direction.Play();
Magnitude.Play();
}
}