More work on refactor to interfaces
All checks were successful
Build / Build (push) Successful in 50s

This commit is contained in:
2025-06-29 12:03:51 +02:00
parent 436d1899e0
commit 1feb27e826
173 changed files with 713 additions and 562 deletions

View File

@@ -91,6 +91,36 @@ public static class ScriptExecution
}
}
/// <summary>
/// Executes a hook on all scripts in a source.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RunScriptHookInterface<TScriptHook>(this IEnumerable<IScriptSource> sources,
Action<TScriptHook> hook)
{
var iterator = sources.Distinct().SelectMany(x => x.GetScripts()).ToArray();
List<ScriptCategory>? suppressedCategories = null;
foreach (var container in iterator)
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (script is IScriptOnBeforeAnyHookInvoked onBeforeAnyHookInvoked)
onBeforeAnyHookInvoked.OnBeforeAnyHookInvoked(ref suppressedCategories);
}
foreach (var container in iterator)
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (script is not TScriptHook scriptHook)
continue;
if (suppressedCategories != null && suppressedCategories.Contains(script.Category))
continue;
hook(scriptHook);
}
}
/// <summary>
/// Executes a hook on all scripts in a list of sources. Note that this does not walk through the parents of the
/// sources, but only the sources themselves.
@@ -117,6 +147,35 @@ public static class ScriptExecution
}
}
/// <summary>
/// Executes a hook on all scripts in a list of sources. Note that this does not walk through the parents of the
/// sources, but only the sources themselves.
/// </summary>
public static void RunScriptHookInterface<TScriptHook>(this IReadOnlyList<IEnumerable<ScriptContainer>> source,
Action<TScriptHook> hook)
{
List<ScriptCategory>? suppressedCategories = null;
foreach (var container in source.SelectMany(x => x))
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (script is IScriptOnBeforeAnyHookInvoked onBeforeAnyHookInvoked)
onBeforeAnyHookInvoked.OnBeforeAnyHookInvoked(ref suppressedCategories);
}
foreach (var container in source.SelectMany(x => x))
{
if (container.IsEmpty)
continue;
var script = container.Script;
if (script is not TScriptHook scriptHook)
continue;
if (suppressedCategories != null && suppressedCategories.Contains(script.Category))
continue;
hook(scriptHook);
}
}
/// <summary>
/// Executes a script on an item.
/// </summary>