using Godot;

namespace Cirno.Scripts.Components.Actors;

public partial class ForceFieldCollisionDisabler : CollisionShape2D
{
    [Export]
    protected Door _door;

    [Export]
    public bool Invert { get; private set; } = false;
    public override void _Ready()
    {
        //_door = GetParent<Door>();
        
        _door.DoorOpened += DoorOpened;
        _door.DoorClosed += DoorClosed;
    }

    protected virtual void DoorClosed()
    {
        CallDeferred(MethodName.Enable);
    }

    private void Disable()
    {
        this.Disabled = !Invert;
    }

    protected virtual void DoorOpened()
    {
        CallDeferred(MethodName.Disable);
    }

    private void Enable()
    {
        this.Disabled = Invert;
    }
}