More move scripts
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static.Utils;
|
||||
|
||||
@@ -14,8 +15,11 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
|
||||
/// <summary>
|
||||
/// Adds a script to the set. If the script with that name already exists in this set, this
|
||||
/// makes that script stack instead. The return value here is that script.
|
||||
/// If the script was blocked from being added, this will return null.
|
||||
/// </summary>
|
||||
ScriptContainer Add(Script script);
|
||||
/// <param name="script">The script to add.</param>
|
||||
/// <param name="forceAdd">If true, the script cannot be blocked, and will always be added</param>
|
||||
ScriptContainer? Add(Script script, bool forceAdd = false);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a script with a name to the set. If the script with that name already exists in this
|
||||
@@ -77,8 +81,15 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
|
||||
/// <inheritdoc cref="IScriptSet"/>
|
||||
public class ScriptSet : IScriptSet
|
||||
{
|
||||
private IScriptSource _source;
|
||||
|
||||
private readonly List<ScriptContainer> _scripts = [];
|
||||
|
||||
public ScriptSet(IScriptSource source)
|
||||
{
|
||||
_source = source;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerator<ScriptContainer> GetEnumerator() => _scripts.GetEnumerator();
|
||||
|
||||
@@ -86,8 +97,16 @@ public class ScriptSet : IScriptSet
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ScriptContainer Add(Script script)
|
||||
public ScriptContainer? Add(Script script, bool forceAdd = false)
|
||||
{
|
||||
if (!forceAdd)
|
||||
{
|
||||
var preventVolatileAdd = false;
|
||||
_source.RunScriptHook(x => x.PreventVolatileAdd(script, ref preventVolatileAdd));
|
||||
if (preventVolatileAdd)
|
||||
return null;
|
||||
}
|
||||
|
||||
var existing = _scripts.FirstOrDefault(s => s.Script?.Name == script.Name);
|
||||
if (existing != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user