using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Text;
using Godot;

namespace Rokojori
{  
  public interface IFloatDriver
  {
    public float GetDriverFloatValue();
  }

  [Tool]
  [GlobalClass]
  public partial class FloatDriver:Node, IFloatDriver
  { 
    float _driverValue = 0f;

    [Export( PropertyHint.Range, "0,1" )]
    public float value
    {
      get => _driverValue;
      set 
      {
        _driverValue = value;
        UpdateValue();
      }
    }

    public float GetDriverFloatValue()
    { return _driverValue; }

    [ExportToolButton( "Update Value")]
    public Callable updateValueButton => Callable.From( ()=> UpdateValue() ) ;
    
    void UpdateValue() 
    {      
      for ( int i = 0; targets != null && i < targets.Length; i++ )
      {
        if ( targets[ i ] == null || targets[ i ].GetGodotObject( this ) == null )
        {
          continue;
        }

        targets[ i ].Update( this );
      }

      onChange?.Trigger();

      if ( value == 0 )
      {
        onZero?.Trigger();
      }
      else if ( value == 1 )
      {
        onOne?.Trigger();
      }
      else 
      {
        onIntermediate?.Trigger();
      }
    }    
    
    [Export]
    public FloatDriverTarget[] targets = [];

    [Export]
    public Action onChange;

    [Export]
    public Action onZero;

    [Export]
    public Action onOne;

    [Export]
    public Action onIntermediate;





  }
}