- add: script abilities
This commit is contained in:
@@ -1,33 +1,29 @@
|
||||
using System.Reflection;
|
||||
using Nebula.Shared;
|
||||
using Nebula.Shared.FileApis;
|
||||
using Nebula.Shared.Services;
|
||||
|
||||
namespace Nebula.Runner.Services;
|
||||
|
||||
[ServiceRegister]
|
||||
public class ReflectionService(AssemblyService assemblyService)
|
||||
public class ReflectionService
|
||||
{
|
||||
private Dictionary<string, Assembly> _typeCache = new();
|
||||
private readonly Dictionary<string, Assembly> _typeCache = new();
|
||||
|
||||
public ReflectionService(AssemblyService assemblyService)
|
||||
{
|
||||
assemblyService.OnAssemblyLoaded += OnAssemblyLoaded;
|
||||
}
|
||||
|
||||
private void OnAssemblyLoaded(Assembly obj)
|
||||
{
|
||||
RegisterAssembly(obj);
|
||||
}
|
||||
|
||||
public void RegisterAssembly(Assembly robustAssembly)
|
||||
{
|
||||
_typeCache.Add(robustAssembly.GetName().Name!, robustAssembly);
|
||||
}
|
||||
|
||||
public void RegisterRobustAssemblies(AssemblyApi engine)
|
||||
{
|
||||
RegisterAssembly(GetRobustAssembly("Robust.Shared", engine));
|
||||
RegisterAssembly(GetRobustAssembly("Robust.Client", engine));
|
||||
}
|
||||
|
||||
private Assembly GetRobustAssembly(string assemblyName, AssemblyApi engine)
|
||||
{
|
||||
if(!assemblyService.TryOpenAssembly(assemblyName, engine, out var assembly))
|
||||
throw new Exception($"Unable to locate {assemblyName}.dll in engine build!");
|
||||
return assembly;
|
||||
}
|
||||
|
||||
|
||||
public Type? GetTypeImp(string name)
|
||||
{
|
||||
foreach (var (prefix,assembly) in _typeCache)
|
||||
@@ -51,7 +47,7 @@ public class ReflectionService(AssemblyService assemblyService)
|
||||
: assembly.GetType(name)!;
|
||||
}
|
||||
|
||||
private string ExtrackPrefix(string path)
|
||||
public string ExtrackPrefix(string path)
|
||||
{
|
||||
var sp = path.Split(".");
|
||||
return sp[0] + "." + sp[1];
|
||||
|
||||
Reference in New Issue
Block a user