using Godot;
using System;
using Cirno.Scripts;
using System.Threading.Tasks;

public partial class ForceField : Door
{
    [Export]
    public Material TurnOffMaterial { get; private set; }

    [Export]
    public Material ActiveMaterial { get; private set; }

    // Disable
    public override void Open()
    {
        base.Open();
        if (TurnOffMaterial is null) return;

        //_animatedSprite.Material = TurnOffMaterial;
        //((ShaderMaterial)_animatedSprite.Material).Shader = TurnOffShader;
        _ = AnimateShutdownAsync();
    }

    protected async Task AnimateShutdownAsync()
    {
        Tween tween = GetTree().CreateTween();
        tween.TweenMethod(Callable.From((float value) => SetShaderScanlineDensity(value)), 0f, 50f, 0.5);
        tween.Parallel().TweenMethod(Callable.From((float value) => SetShaderTeleportProgress(value)), 0f, 1f, 0.5);

        await ToSignal(tween, "finished");
    }

    // Enable
    public override void Close()
    {
        base.Close();

        if (ActiveMaterial is null) return;
        //_animatedSprite.Material = ActiveMaterial;
        //((ShaderMaterial)_animatedSprite.Material).Shader = ActiveShader;
    }

    private void SetShaderTeleportProgress(float value)
    {
        //((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("teleport_progress", value);
    }

    private void SetShaderScanlineDensity(float value)
    {
        //((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("scanline_density", value);
    }
}