diff --git a/Engine.Systems/Tween/EngineExtensions/TweenAABBExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenAABBExtensions.cs new file mode 100644 index 0000000..b3baace --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenAABBExtensions.cs @@ -0,0 +1,10 @@ +using System; +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenAABBExtensions +{ + public static ITween TweenAABB(this AABB initialAABB, ITweenManager tweenManager, float duration, AABB targetAABB, Action setMethod) + => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(new AABB(initialAABB.LowerBoundary.Lerp(targetAABB.LowerBoundary, t), initialAABB.UpperBoundary.Lerp(targetAABB.UpperBoundary, t)))); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenCamera2DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenCamera2DExtensions.cs new file mode 100644 index 0000000..1644789 --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenCamera2DExtensions.cs @@ -0,0 +1,12 @@ +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenCamera2DExtensions +{ + public static ITween TweenZoom(this ICamera2D camera2D, ITweenManager tweenManager, float duration, float targetZoom) + { + float initialZoom = camera2D.Zoom; + return tweenManager.StartTween(duration, t => camera2D.Zoom = initialZoom.Lerp(targetZoom, t)); + } +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenCircleExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenCircleExtensions.cs new file mode 100644 index 0000000..82a662a --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenCircleExtensions.cs @@ -0,0 +1,16 @@ +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenCircleExtensions +{ + public static ITween TweenCircle(this Circle initialCircle, ITweenManager tweenManager, float duration, Circle targetCircle, System.Action setMethod) + => tweenManager.StartTween(duration, + t => setMethod?.InvokeSafe( + new Circle( + initialCircle.Center.Lerp(targetCircle.Center, t), + initialCircle.Diameter.Lerp(targetCircle.Diameter, t) + ) + ) + ); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenColorExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenColorExtensions.cs new file mode 100644 index 0000000..523c829 --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenColorExtensions.cs @@ -0,0 +1,15 @@ +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenColorExtensions +{ + public static ITween TweenColor(this ColorRGB initialColorRGB, ITweenManager tweenManager, float duration, ColorRGB targetColorRGB, System.Action setMethod) + => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorRGB.Lerp(targetColorRGB, t))); + + public static ITween TweenColor(this ColorRGBA initialColorRGBA, ITweenManager tweenManager, float duration, ColorRGBA targetColorRGBA, System.Action setMethod) + => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorRGBA.Lerp(targetColorRGBA, t))); + + public static ITween TweenColor(this ColorHSV initialColorHSV, ITweenManager tweenManager, float duration, ColorHSV targetColorHSV, System.Action setMethod) + => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialColorHSV.Lerp(targetColorHSV, t))); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenLine2DEquationExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenLine2DEquationExtensions.cs new file mode 100644 index 0000000..0e6e39c --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenLine2DEquationExtensions.cs @@ -0,0 +1,16 @@ +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenLine2DEquationExtensions +{ + public static ITween TweenLine2DEquation(this Line2DEquation initialLine2DEquation, ITweenManager tweenManager, float duration, Line2DEquation targetLine2DEquation, System.Action setMethod) + => tweenManager.StartTween(duration, + t => setMethod?.InvokeSafe( + new Line2DEquation( + initialLine2DEquation.Slope.Lerp(targetLine2DEquation.Slope, t), + initialLine2DEquation.OffsetY.Lerp(targetLine2DEquation.OffsetY, t) + ) + ) + ); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenLine2DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenLine2DExtensions.cs new file mode 100644 index 0000000..c2d58f9 --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenLine2DExtensions.cs @@ -0,0 +1,16 @@ +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenLine2DExtensions +{ + public static ITween TweenLine2D(this Line2D initialLine2D, ITweenManager tweenManager, float duration, Line2D targetLine2D, System.Action setMethod) + => tweenManager.StartTween(duration, + t => setMethod?.InvokeSafe( + new Line2D( + initialLine2D.From.Lerp(targetLine2D.From, t), + initialLine2D.To.Lerp(targetLine2D.To, t) + ) + ) + ); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenProjection1DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenProjection1DExtensions.cs new file mode 100644 index 0000000..2b1ff96 --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenProjection1DExtensions.cs @@ -0,0 +1,17 @@ +using System; +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenProjection1DExtensions +{ + public static ITween TweenProjection1D(this Projection1D initialProjection1D, ITweenManager tweenManager, float duration, Projection1D targetProjection1D, Action setMethod) + => tweenManager.StartTween(duration, + t => setMethod?.InvokeSafe( + new Projection1D( + initialProjection1D.Min.Lerp(targetProjection1D.Min, t), + initialProjection1D.Max.Lerp(targetProjection1D.Max, t) + ) + ) + ); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenQuaternionExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenQuaternionExtensions.cs new file mode 100644 index 0000000..c3cc759 --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenQuaternionExtensions.cs @@ -0,0 +1,10 @@ +using System; +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenQuaternionExtensions +{ + public static ITween TweenQuaternion(this Quaternion initialQuaternion, ITweenManager tweenManager, float duration, Quaternion targetQuaternion, Action setMethod) + => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialQuaternion.SLerp(targetQuaternion, t))); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenShape2DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenShape2DExtensions.cs new file mode 100644 index 0000000..e5d358b --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenShape2DExtensions.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenShape2DExtensions +{ + public static ITween TweenShape2D(this Shape2D shape, ITweenManager tweenManager, float duration, Shape2D targetShape2D) + { + List initialVertices = new(shape.Vertices); + List shapeVertices = new(shape.Vertices); + + return tweenManager.StartTween(duration, + t => + { + shapeVertices.Clear(); + int count = Math.Lerp(initialVertices.Count, targetShape2D.Vertices.Count, t).RoundToInt(); + for (int i = 0; i < count; i++) + { + int initialIndex = i.Min(initialVertices.Count); + int targetIndex = i.Min(targetShape2D.Vertices.Count); + shapeVertices.Add(targetShape2D.Vertices[targetIndex].Lerp(initialVertices[initialIndex], 1f - t)); + } + shape.Vertices = shapeVertices; + } + ); + } +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenTransform2DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenTransform2DExtensions.cs new file mode 100644 index 0000000..513b608 --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenTransform2DExtensions.cs @@ -0,0 +1,42 @@ +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenTransform2DExtensions +{ + public static ITween TweenPosition(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetPosition) + { + Vector2D initialPosition = transform2D.Position; + return tweenManager.StartTween(duration, t => transform2D.Position = initialPosition.Lerp(targetPosition, t)); + } + + public static ITween TweenScale(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetScale) + { + Vector2D initialScale = transform2D.Scale; + return tweenManager.StartTween(duration, t => transform2D.Scale = initialScale.Lerp(targetScale, t)); + } + + public static ITween TweenRotation(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float targetRotation) + { + float initialRotation = transform2D.Rotation; + return tweenManager.StartTween(duration, t => transform2D.Rotation = initialRotation.Lerp(targetRotation, t)); + } + + public static ITween TweenLocalPosition(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetLocalPosition) + { + Vector2D initialLocalPosition = transform2D.LocalPosition; + return tweenManager.StartTween(duration, t => transform2D.LocalPosition = initialLocalPosition.Lerp(targetLocalPosition, t)); + } + + public static ITween TweenLocalScale(this ITransform2D transform2D, ITweenManager tweenManager, float duration, Vector2D targetLocalScale) + { + Vector2D initialLocalScale = transform2D.LocalScale; + return tweenManager.StartTween(duration, t => transform2D.LocalScale = initialLocalScale.Lerp(targetLocalScale, t)); + } + + public static ITween TweenLocalRotation(this ITransform2D transform2D, ITweenManager tweenManager, float duration, float targetLocalRotation) + { + float initialLocalRotation = transform2D.LocalRotation; + return tweenManager.StartTween(duration, t => transform2D.LocalRotation = initialLocalRotation.Lerp(targetLocalRotation, t)); + } +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenTriangleExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenTriangleExtensions.cs new file mode 100644 index 0000000..9c85d31 --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenTriangleExtensions.cs @@ -0,0 +1,18 @@ +using System; +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenTriangleExtensions +{ + public static ITween TweenTriangle(this Triangle initialTriangle, ITweenManager tweenManager, float duration, Triangle targetTriangle, Action setMethod) + => tweenManager.StartTween(duration, + t => setMethod?.InvokeSafe( + new Triangle( + initialTriangle.A.Lerp(targetTriangle.A, t), + initialTriangle.B.Lerp(targetTriangle.B, t), + initialTriangle.C.Lerp(targetTriangle.C, t) + ) + ) + ); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenVector2DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenVector2DExtensions.cs new file mode 100644 index 0000000..6776575 --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenVector2DExtensions.cs @@ -0,0 +1,9 @@ +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenVector2DExtensions +{ + public static ITween TweenVector2D(this Vector2D initialVector2D, ITweenManager tweenManager, float duration, Vector2D targetVector2D, System.Action setMethod) + => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialVector2D.Lerp(targetVector2D, t))); +} diff --git a/Engine.Systems/Tween/EngineExtensions/TweenVector3DExtensions.cs b/Engine.Systems/Tween/EngineExtensions/TweenVector3DExtensions.cs new file mode 100644 index 0000000..92983dd --- /dev/null +++ b/Engine.Systems/Tween/EngineExtensions/TweenVector3DExtensions.cs @@ -0,0 +1,9 @@ +using Syntriax.Engine.Core; + +namespace Syntriax.Engine.Systems.Tween; + +public static class TweenVector3DExtensions +{ + public static ITween TweenVector3D(this Vector3D initialVector3D, ITweenManager tweenManager, float duration, Vector3D targetVector3D, System.Action setMethod) + => tweenManager.StartTween(duration, t => setMethod?.InvokeSafe(initialVector3D.Lerp(targetVector3D, t))); +}