
using Godot;
using System.Collections.Generic;

namespace Rokojori
{  
  [Tool]
  [GlobalClass]
  public partial class CompFXMemberCurveTarget:RokojoriCompositorEffectAnimationTarget
  {
    [Export]
    public string member;

    [Export]
    public Curve curve;

    [Export]
    public float curveScale = 1f;

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

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

      curveValue *= curveScale;

      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  );
      }

    }
  }
}