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

namespace Rokojori
{ 
  [Tool]
  [GlobalClass]
  public partial class CSShaderVariant:Resource
  { 
    [ExportGroup("Name")]
    [Export]
    public string nameChangeMatcher = "Add.gdshader$";
    [Export]
    public string nameChangeReplacement = "Mix.gdshader";

    [ExportGroup("Changes")]
    [Export]
    public CSShaderVariantChange[] changes = [];

    public string GetVariant( string shaderCode )
    {
      changes.ForEach(
        c =>
        {
          if ( c == null )
          {
            return;
          }

          shaderCode = c.ChangeShaderCode( shaderCode );

        }
      );

      return shaderCode;
    }

    public string GetSavingPath( string resourcePath )
    {
      var savePath = resourcePath.Replace( new Regex( nameChangeMatcher ), nameChangeReplacement );
      return savePath;
    }

  }
}