
using Godot;


namespace Rokojori
{  
  [GlobalClass, Icon("res://addons/rokojori_action_library/Icons/OnEvent.svg") ]
  public partial class OnSensor: Node
  {
    [Export]
    public Sensor sensor;

    [Export]
    public Action onStart;    

    [Export]
    public Action onActive;    

    [Export]
    public Action onEnd;    

    public override void _Process( double delta)
    {     
      var active    = sensor.isActive;
      var wasActive = sensor.wasActive;

      if ( ! active && ! wasActive )
      {
        return;
      }

      var started = ! wasActive && active;
      var ended   = wasActive && ! active;

      if ( started )
      { 
        Action.Trigger( onStart );
      }

      if ( active )  
      {
        Action.Trigger( onActive );
      }

      if ( ended )  
      {
        Action.Trigger( onActive );
      }

    }
  }
}