More abilities
All checks were successful
Build / Build (push) Successful in 48s

This commit is contained in:
2025-06-09 13:44:26 +02:00
parent 00005aa4bf
commit 97868ab4c6
94 changed files with 829 additions and 150 deletions

View File

@@ -1,4 +1,5 @@
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using PkmnLib.Dynamic.ScriptHandling.Registry;
using PkmnLib.Static.Utils;
@@ -31,6 +32,11 @@ public interface IScriptSet : IEnumerable<ScriptContainer>
/// </summary>
ScriptContainer? Get(StringKey scriptKey);
/// <summary>
/// Tries to get a script from the set using its type.
/// </summary>
bool TryGet<T>([NotNullWhen(true)] out T? script) where T : Script;
/// <summary>
/// Gets a script from the set using its type.
/// </summary>
@@ -144,6 +150,20 @@ public class ScriptSet : IScriptSet
/// <inheritdoc />
public ScriptContainer? Get(StringKey scriptKey) => _scripts.FirstOrDefault(s => s.Script?.Name == scriptKey);
/// <inheritdoc />
public bool TryGet<T>([NotNullWhen(true)] out T? script) where T : Script
{
var scriptName = ScriptUtils.ResolveName<T>();
var container = _scripts.FirstOrDefault(sc => sc.Script?.Name == scriptName);
if (container?.Script is not T s)
{
script = null;
return false;
}
script = s;
return true;
}
/// <inheritdoc />
public T? Get<T>() where T : Script => Get(ScriptUtils.ResolveName<T>())?.Script as T;