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

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

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

    [Export]
    public Color searchColor;

    [Export]
    public Color replacementColor;

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

    [Export( PropertyHint.Range, "0,3") ]
    public float colorDistanceMin = 0.1f;


    RG_ScreenColorTexure screenColorTexture;
    RG_ReplaceColor replaceColor;    

    void Initialize()
    { 
      screenColorTexture = new RG_ScreenColorTexure( graph );
      replaceColor = new RG_ReplaceColor( graph );


      graph.InitializeNodes();      

      
      replaceColor.SetTextureSlotInputs( screenColorTexture, screenColorTexture ); 


      graph.SetProcessOrder( 
        screenColorTexture, 
        replaceColor 
      );
    }
   

    protected override void ForAllViews()
    {
      replaceColor.constants.Set(
        searchColor,
        replacementColor,
        amount,
        colorDistanceMax,
        colorDistanceMin,
        0f
      );
    }

   
  }
}