// Copyright © Gamesmiths Guild.
#if TOOLS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Gamesmiths.Forge.Godot.Editor.Statescript;
///
/// Registry of available implementations. Resolver editors are discovered
/// automatically via reflection. Any concrete subclass of in the executing assembly is
/// registered and becomes available in node input property dropdowns.
///
internal static class StatescriptResolverRegistry
{
private static readonly List> _factories = [];
static StatescriptResolverRegistry()
{
Type[] allTypes = Assembly.GetExecutingAssembly().GetTypes();
foreach (Type type in allTypes.Where(
x => x.IsSubclassOf(typeof(NodeEditorProperty)) && !x.IsAbstract))
{
Type captured = type;
_factories.Add(() => (NodeEditorProperty)Activator.CreateInstance(captured)!);
}
}
///
/// Gets factory functions for all resolver editors compatible with the given expected type.
///
/// The type expected by the node input property.
/// A list of compatible resolver editor factories.
public static List> GetCompatibleFactories(Type expectedType)
{
var result = new List>();
foreach (Func factory in _factories)
{
using NodeEditorProperty temp = factory();
if (temp.IsCompatibleWith(expectedType))
{
result.Add(factory);
}
}
return result;
}
}
#endif