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

namespace Rokojori
{  
  [Tool]
  [GlobalClass]
  public partial class LightnessBasedAdjustmentEffect:ColorEffect
  {
    public LightnessBasedAdjustmentEffect():base()
    {
      Initialize();
    } 

    [Export( PropertyHint.Range, "0,1") ]
    public float amount = 0.5f;

    [Export]
    public Vector3 hueShift = Vector3.Zero;

    [Export( PropertyHint.Range, "0,1") ]
    public float hueAmount = 1.0f;

    [Export]
    public Vector3 saturationShift = Vector3.Zero;

    [Export( PropertyHint.Range, "0,1") ]
    public float saturationAmount = 1.0f;

    [Export ]
    public Vector3 lightnessShift = Vector3.Zero;

    [Export( PropertyHint.Range, "0,1") ]
    public float lightnessAmount = 1.0f;

    public enum HSLConversionMode
    {
      Raw,
      Scaled,
      Clamped
    }

    [Export]
    public HSLConversionMode hslConversionMode = HSLConversionMode.Scaled;



    RG_ScreenColorTexure screenColorTexture;
    RG_LightnessBasedAdjustment adjustment;    

    void Initialize()
    { 
      screenColorTexture = new RG_ScreenColorTexure( graph );
      adjustment = new RG_LightnessBasedAdjustment( graph );


      graph.InitializeNodes();      

      
      adjustment.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); 


      graph.SetProcessOrder( 
        screenColorTexture, 
        adjustment 
      );
    }

    Vector4 ToVector4( Vector3 v, float w )
    {
      return new Vector4( v.X, v.Y, v.Z, w );
    }

    protected override void ForAllViews()
    {
      adjustment.constants.Set(        
        ToVector4( hueShift, hueAmount ),
        ToVector4( saturationShift, saturationAmount ),
        ToVector4( lightnessShift, lightnessAmount ),
        Vector4.Zero,
        amount, 
        0f,
        0f,
        0f

      );
    }

   
  }
}