
using Godot;
using System;
using System.Collections.Generic;

namespace Rokojori
{  
  [Tool]
  [GlobalClass]
  public partial class CompositorEffectMemberCurveTarget:CompositorEffectDriverTarget
  {
    [Export]
    public string member;

    [Export]
    public Curve curve;

    public enum TargetType
    {
      Float, 
      Int, 
      Bool
    }
    
    [Export]
    public TargetType targetType = TargetType.Float;

    public override void OnDriverChange( RokojoriCompositorEffect re, float value )
    {
      var curveValue = curve == null ? value : curve.Sample( value );

      if ( TargetType.Float == targetType )
      {
        ReflectionHelper.SetValue( re, member, curveValue );
      }
      else if ( TargetType.Int == targetType )
      {
        ReflectionHelper.SetValue( re, member, (int)curveValue );
      }
      else if ( TargetType.Bool == targetType )
      {
        ReflectionHelper.SetValue( re, member, curveValue > 0  );
      }

    }
  }
}