Adds a bunch more move scripts

This commit is contained in:
Deukhoofd committed 2024-11-02 12:59:55 +01:00
1 parent 6f2bd678a5
commit 44cd2ee03e
17 files changed
+492 -1

No files matched your search

@@ -15,6 +15,8 @@ public static class ScriptUtils
/// </summary>
public static StringKey ResolveName(this Script script) => ResolveName(script.GetType());
public static StringKey ResolveName<T>() where T : Script => ResolveName(typeof(T));
/// <summary>
/// Resolve name from the <see cref="ScriptAttribute"/> of the given type.
/// </summary>
+7
View File
@@ -14,8 +14,15 @@ namespace PkmnLib.Dynamic.ScriptHandling;
/// </summary>
public abstract class Script
{
internal event Action<Script>? OnRemoveEvent;
private int _suppressCount;
public void RemoveSelf()
{
OnRemoveEvent?.Invoke(this);
}
/// <summary>
/// The name of a script is its unique identifier.
/// If not overridden, this will resolve the name from the <see cref="ScriptAttribute"/> of the
@@ -79,6 +79,7 @@ public class ScriptSet : IScriptSet
return existing;
}
script.OnRemoveEvent += s => Remove(s.Name);
var container = new ScriptContainer(script);
_scripts.Add(container);
return container;
@@ -97,6 +98,7 @@ public class ScriptSet : IScriptSet
var script = instantiation();
if (script is null)
return null;
script.OnRemoveEvent += s => Remove(s.Name);
var container = new ScriptContainer(script);
_scripts.Add(container);
return container;
@@ -111,6 +113,7 @@ public class ScriptSet : IScriptSet
var script = _scripts.FirstOrDefault(s => s.Script?.Name == scriptKey);
if (script is null)
return;
script.Script?.OnRemove();
_scripts.Remove(script);
}