mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-19 13:43:47 +00:00
Added GTWeen
This commit is contained in:
parent
457998788e
commit
2036e4e748
152 changed files with 5889 additions and 7 deletions
87
GTweensGodot/GTweens/Source/Extensions/AngleExtensions.cs
Normal file
87
GTweensGodot/GTweens/Source/Extensions/AngleExtensions.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
using GTweens.Enums;
|
||||
|
||||
namespace GTweens.Extensions
|
||||
{
|
||||
internal static class AngleExtensions
|
||||
{
|
||||
public static float Clamp360(float eulerAngles)
|
||||
{
|
||||
float result = eulerAngles - (float)Math.Ceiling(eulerAngles / 360f) * 360f;
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
result += 360f;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Vector3 Clamp360(Vector3 eulerAngles)
|
||||
{
|
||||
return new Vector3(
|
||||
Clamp360(eulerAngles.X),
|
||||
Clamp360(eulerAngles.Y),
|
||||
Clamp360(eulerAngles.Z)
|
||||
);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates the shortest difference between two given angles.
|
||||
/// </summary>
|
||||
public static float DeltaAngle(float current, float target)
|
||||
{
|
||||
float difference = target - current;
|
||||
|
||||
float delta = MathExtensions.Repeat(difference, 360f);
|
||||
|
||||
if (delta > 180.0F)
|
||||
{
|
||||
delta -= 360.0F;
|
||||
}
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
public static Vector3 DeltaAngle(Vector3 current, Vector3 target)
|
||||
{
|
||||
return new Vector3(
|
||||
DeltaAngle(current.X, target.X),
|
||||
DeltaAngle(current.Y, target.Y),
|
||||
DeltaAngle(current.Z, target.Z)
|
||||
);
|
||||
}
|
||||
|
||||
public static float GetDestinationAngleDegrees(float origin, float destination, RotationMode mode)
|
||||
{
|
||||
switch(mode)
|
||||
{
|
||||
case RotationMode.ShortestDistance:
|
||||
{
|
||||
float clampedOrigin = Clamp360(origin);
|
||||
float clampedDestination = Clamp360(destination);
|
||||
|
||||
float deltaAngle = DeltaAngle(clampedOrigin, clampedDestination);
|
||||
|
||||
return origin + deltaAngle;
|
||||
}
|
||||
|
||||
default:
|
||||
case RotationMode.TotalDistance:
|
||||
{
|
||||
return destination;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static float GetDestinationAngleRadiants(float origin, float destination, RotationMode mode)
|
||||
{
|
||||
return GetDestinationAngleDegrees(
|
||||
origin * MathExtensions.Rad2Deg,
|
||||
destination * MathExtensions.Rad2Deg,
|
||||
mode
|
||||
) * MathExtensions.Deg2Rad;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://boj44m1nwtj83
|
||||
298
GTweensGodot/GTweens/Source/Extensions/GTweenExtensions.cs
Normal file
298
GTweensGodot/GTweens/Source/Extensions/GTweenExtensions.cs
Normal file
|
|
@ -0,0 +1,298 @@
|
|||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GTweens.Delegates;
|
||||
using GTweens.TweenBehaviours;
|
||||
using GTweens.Tweeners;
|
||||
using GTweens.Tweens;
|
||||
|
||||
namespace GTweens.Extensions
|
||||
{
|
||||
public static class GTweenExtensions
|
||||
{
|
||||
public static GTween Tween(
|
||||
Tweener<int>.Getter getter,
|
||||
Tweener<int>.Setter setter,
|
||||
Tweener<int>.Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
{
|
||||
InterpolationTweenBehaviour tweenBehaviour = new InterpolationTweenBehaviour();
|
||||
tweenBehaviour.Add(new IntTweener(getter, setter, to, duration, validation));
|
||||
return new GTween(tweenBehaviour);
|
||||
}
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<int>.Getter getter,
|
||||
Tweener<int>.Setter setter,
|
||||
int to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
) => Tween(getter, setter, () => to, duration, validation);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<int>.Getter getter,
|
||||
Tweener<int>.Setter setter,
|
||||
int to,
|
||||
float duration
|
||||
) => Tween(getter, setter, () => to, duration, ValidationExtensions.AlwaysValid);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<float>.Getter getter,
|
||||
Tweener<float>.Setter setter,
|
||||
Tweener<float>.Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
{
|
||||
InterpolationTweenBehaviour tweenBehaviour = new InterpolationTweenBehaviour();
|
||||
tweenBehaviour.Add(new FloatTweener(getter, setter, to, duration, validation));
|
||||
return new GTween(tweenBehaviour);
|
||||
}
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<float>.Getter getter,
|
||||
Tweener<float>.Setter setter,
|
||||
float to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
) => Tween(getter, setter, () => to, duration, validation);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<float>.Getter getter,
|
||||
Tweener<float>.Setter setter,
|
||||
float to,
|
||||
float duration
|
||||
) => Tween(getter, setter, to, duration, ValidationExtensions.AlwaysValid);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector2>.Getter getter,
|
||||
Tweener<Vector2>.Setter setter,
|
||||
Tweener<Vector2>.Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
{
|
||||
InterpolationTweenBehaviour tweenBehaviour = new InterpolationTweenBehaviour();
|
||||
tweenBehaviour.Add(new SystemVector2Tweener(getter, setter, to, duration, validation));
|
||||
return new GTween(tweenBehaviour);
|
||||
}
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector2>.Getter getter,
|
||||
Tweener<Vector2>.Setter setter,
|
||||
Vector2 to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
) => Tween(getter, setter, () => to, duration, validation);
|
||||
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector2>.Getter getter,
|
||||
Tweener<Vector2>.Setter setter,
|
||||
Vector2 to,
|
||||
float duration
|
||||
) => Tween(getter, setter, to, duration, ValidationExtensions.AlwaysValid);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector3>.Getter getter,
|
||||
Tweener<Vector3>.Setter setter,
|
||||
Tweener<Vector3>.Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
{
|
||||
InterpolationTweenBehaviour tweenBehaviour = new InterpolationTweenBehaviour();
|
||||
tweenBehaviour.Add(new SystemVector3Tweener(getter, setter, to, duration, validation));
|
||||
return new GTween(tweenBehaviour);
|
||||
}
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector3>.Getter getter,
|
||||
Tweener<Vector3>.Setter setter,
|
||||
Vector3 to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
) => Tween(getter, setter, () => to, duration, validation);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector3>.Getter getter,
|
||||
Tweener<Vector3>.Setter setter,
|
||||
Vector3 to,
|
||||
float duration
|
||||
) => Tween(getter, setter, to, duration, ValidationExtensions.AlwaysValid);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector4>.Getter getter,
|
||||
Tweener<Vector4>.Setter setter,
|
||||
Tweener<Vector4>.Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
{
|
||||
InterpolationTweenBehaviour tweenBehaviour = new InterpolationTweenBehaviour();
|
||||
tweenBehaviour.Add(new SystemVector4Tweener(getter, setter, to, duration, validation));
|
||||
return new GTween(tweenBehaviour);
|
||||
}
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector4>.Getter getter,
|
||||
Tweener<Vector4>.Setter setter,
|
||||
Vector4 to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
) => Tween(getter, setter, () => to, duration, validation);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Vector4>.Getter getter,
|
||||
Tweener<Vector4>.Setter setter,
|
||||
Vector4 to,
|
||||
float duration
|
||||
) => Tween(getter, setter, to, duration, ValidationExtensions.AlwaysValid);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Color>.Getter getter,
|
||||
Tweener<Color>.Setter setter,
|
||||
Tweener<Color>.Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
{
|
||||
InterpolationTweenBehaviour tweenBehaviour = new InterpolationTweenBehaviour();
|
||||
tweenBehaviour.Add(new SystemColorTweener(getter, setter, to, duration, validation));
|
||||
return new GTween(tweenBehaviour);
|
||||
}
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Color>.Getter getter,
|
||||
Tweener<Color>.Setter setter,
|
||||
Color to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
) => Tween(getter, setter, () => to, duration, validation);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Color>.Getter getter,
|
||||
Tweener<Color>.Setter setter,
|
||||
Color to,
|
||||
float duration
|
||||
) => Tween(getter, setter, to, duration, ValidationExtensions.AlwaysValid);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Quaternion>.Getter getter,
|
||||
Tweener<Quaternion>.Setter setter,
|
||||
Tweener<Quaternion>.Getter to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
)
|
||||
{
|
||||
InterpolationTweenBehaviour tweenBehaviour = new InterpolationTweenBehaviour();
|
||||
tweenBehaviour.Add(new SystemQuaternionTweener(getter, setter, to, duration, validation));
|
||||
return new GTween(tweenBehaviour);
|
||||
}
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Quaternion>.Getter getter,
|
||||
Tweener<Quaternion>.Setter setter,
|
||||
Quaternion to,
|
||||
float duration,
|
||||
ValidationDelegates.Validation validation
|
||||
) => Tween(getter, setter, () => to, duration, validation);
|
||||
|
||||
public static GTween Tween(
|
||||
Tweener<Quaternion>.Getter getter,
|
||||
Tweener<Quaternion>.Setter setter,
|
||||
Quaternion to,
|
||||
float duration
|
||||
) => Tween(getter, setter, to, duration, ValidationExtensions.AlwaysValid);
|
||||
|
||||
public static GTween Tween(
|
||||
int from,
|
||||
int to,
|
||||
Tweener<int>.Setter setter,
|
||||
float duration
|
||||
)
|
||||
{
|
||||
return Tween(
|
||||
() => from,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
ValidationExtensions.AlwaysValid
|
||||
);
|
||||
}
|
||||
|
||||
public static GTween Tween(
|
||||
float from,
|
||||
float to,
|
||||
Tweener<float>.Setter setter,
|
||||
float duration
|
||||
)
|
||||
{
|
||||
return Tween(
|
||||
() => from,
|
||||
setter,
|
||||
to,
|
||||
duration,
|
||||
ValidationExtensions.AlwaysValid
|
||||
);
|
||||
}
|
||||
|
||||
public static GTween TweenTimeScale(this GTween target, float to, float duration)
|
||||
{
|
||||
return Tween(
|
||||
() => target.TimeScale,
|
||||
current => target.SetTimeScale(current),
|
||||
to,
|
||||
duration
|
||||
);
|
||||
}
|
||||
|
||||
public static bool IsPlayingOrCompleted(this GTween gTween)
|
||||
{
|
||||
return gTween.IsPlaying || gTween.IsCompleted;
|
||||
}
|
||||
|
||||
public static bool IsPlayingOrCompletedOrNested(this GTween gTween)
|
||||
{
|
||||
return gTween.IsPlaying || gTween.IsCompleted || gTween.IsNested;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously waits for the completion of a GTween animation or cancellation through a CancellationToken.
|
||||
/// </summary>
|
||||
/// <param name="gTween">The GTween instance to monitor for completion.</param>
|
||||
/// <param name="cancellationToken">The CancellationToken that can be used to cancel the operation.</param>
|
||||
/// <returns>
|
||||
/// A Task that represents the asynchronous operation. The Task completes when the GTween animation is complete,
|
||||
/// or when the CancellationToken is signaled for cancellation.
|
||||
/// </returns>
|
||||
public static Task AwaitCompleteOrKill(this GTween gTween, CancellationToken cancellationToken)
|
||||
{
|
||||
TaskCompletionSource taskCompletionSource = new();
|
||||
|
||||
if (!gTween.IsPlaying)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
void OnCompleteOrKill()
|
||||
{
|
||||
gTween.OnCompleteOrKillAction -= OnCompleteOrKill;
|
||||
taskCompletionSource.TrySetResult();
|
||||
}
|
||||
|
||||
cancellationToken.Register(OnCompleteOrKill);
|
||||
gTween.OnCompleteOrKill(OnCompleteOrKill);
|
||||
|
||||
return taskCompletionSource.Task;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://dei0hda724u2a
|
||||
27
GTweensGodot/GTweens/Source/Extensions/MathExtensions.cs
Normal file
27
GTweensGodot/GTweens/Source/Extensions/MathExtensions.cs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
|
||||
namespace GTweens.Extensions;
|
||||
|
||||
public static class MathExtensions
|
||||
{
|
||||
public const float Deg2Rad = 0.01745329f;
|
||||
public const float Rad2Deg = 57.29578f;
|
||||
|
||||
public static float SafeDivide(float v1, float v2)
|
||||
{
|
||||
if (v2 == 0f)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
return v1 / v2;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loops the value t, so that it is never larger than length and never smaller than 0.
|
||||
/// </summary>
|
||||
public static float Repeat(float t, float length)
|
||||
{
|
||||
return Math.Clamp(t - (float)Math.Floor(t / length) * length, 0.0f, length);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://bouwnkbl68u6a
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using System.Drawing;
|
||||
|
||||
namespace GTweens.Extensions
|
||||
{
|
||||
public static class SystemColorExtensions
|
||||
{
|
||||
public static Color FromRgba(float r, float g, float b, float a)
|
||||
{
|
||||
return Color.FromArgb(
|
||||
(int)(a * 255f),
|
||||
(int)(r * 255f),
|
||||
(int)(g * 255f),
|
||||
(int)(b * 255f)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://cftquavd2ss24
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
using GTweens.Delegates;
|
||||
|
||||
namespace GTweens.Extensions;
|
||||
|
||||
public static class ValidationExtensions
|
||||
{
|
||||
public static readonly ValidationDelegates.Validation AlwaysValid = () => true;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
uid://yer2h7qavcpt
|
||||
Loading…
Add table
Add a link
Reference in a new issue