Move OnInitialize to interface

This commit is contained in:
2025-06-28 10:31:23 +02:00
parent d719ce03ea
commit 04cf585f5a
19 changed files with 49 additions and 44 deletions

View File

@@ -54,13 +54,6 @@ public abstract class Script : IDeepCloneable
{
}
/// <summary>
/// This function is ran when this script starts being in effect.
/// </summary>
public virtual void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters)
{
}
/// <summary>
/// This function is ran when this script is added to a parent.
/// </summary>
@@ -848,4 +841,17 @@ public interface IScriptOnBeforeAnyHookInvoked
/// of scripts. This is useful for example to prevent certain effects from running.
/// </summary>
void OnBeforeAnyHookInvoked(ref List<ScriptCategory>? suppressedCategories);
}
/// <summary>
/// This interface is used to allow scripts to run when they are initialized. This allows for
/// setting up the script with parameters that are passed to it.
/// </summary>
public interface IScriptOnInitialize
{
/// <summary>
/// This function is ran when the script is initialized. This allows for setting up the script
/// with parameters that are passed to it.
/// </summary>
void OnInitialize(IReadOnlyDictionary<StringKey, object?>? parameters);
}

View File

@@ -34,7 +34,8 @@ public class ScriptResolver
}
script = scriptCtor();
script.OnInitialize(parameters);
if (script is IScriptOnInitialize scriptOnInitialize)
scriptOnInitialize.OnInitialize(parameters);
return true;
}