Refactor move selection prevention to use interface
This commit is contained in:
@@ -13,7 +13,6 @@ public static class ScriptExecution
|
||||
/// <summary>
|
||||
/// Executes a hook on all scripts in a source.
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void RunScriptHook(this IScriptSource source, Action<Script> hook)
|
||||
{
|
||||
var iterator = source.GetScripts();
|
||||
@@ -37,6 +36,34 @@ public static class ScriptExecution
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes a hook on all scripts in a source.
|
||||
/// </summary>
|
||||
public static void RunScriptHookInterface<TScriptHook>(this IScriptSource source, Action<TScriptHook> hook)
|
||||
{
|
||||
var iterator = source.GetScripts();
|
||||
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 source.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user