using Godot;

public partial class TweenPresets : Node
{
        public static void ResetTween(Node node, ref Tween tween)
        {
                if (tween != null)
                {
                        tween.Kill();
                }

                tween = node.CreateTween();
        }

        //Generic blink function
        public static void BlinkProperty(ref Tween tween, Control obj, Color col, Color original, double duration, int loops)
        {
                double time = duration / loops / 2;
                tween.TweenProperty(obj, "modulate", col, time)
                        .SetTrans(Tween.TransitionType.Sine)
                        .SetEase(Tween.EaseType.InOut);
                tween.TweenProperty(obj, "modulate", original, time)
                        .SetTrans(Tween.TransitionType.Sine)
                        .SetEase(Tween.EaseType.InOut);
                tween.SetLoops(loops);
                tween.TweenCallback(Callable.From(() => obj.Modulate = original));
        }

        //Blink function that takes properties specific to Label's
        public static void BlinkProperty(ref Tween tween, Label label, Color col, double duration, int loops)
        {
                Color original = label.GetThemeColor("font_color");
                label.Modulate = original;
                BlinkProperty(ref tween, label, col, original, duration, loops);
        }

        /*
        //For other Control (ControlType here...) nodes it would go like this:
        //Function should have the same name
        public static void BlinkProperty(ref Tween tween, ControlType node, Color col, double duration, int loops, <Add here more if necessary>)
        {
                //Get the original value of the property you are looking to animate from the theme
                        //If you get it directly from the property it's gonna be incorrect
                        //because tweens modify the property directly, if it was interrupted you are gonna have 
                        //an interpolated value
                //Set the property to the original value (just to have the animation always play the same)
                
                BlinkProperty(ref tween, label, col, original, duration, loops);
        }
        */
}
