41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using PkmnLib.Static;
|
|
using PkmnLib.Static.Utils;
|
|
|
|
namespace PkmnLib.Dynamic.ScriptHandling;
|
|
|
|
/// <summary>
|
|
/// Class responsible for the creation of <see cref="Script"/> instances.
|
|
/// </summary>
|
|
public class ScriptResolver
|
|
{
|
|
private Dictionary<(ScriptCategory, StringKey), Func<Script>> _scriptCtors;
|
|
|
|
/// <inheritdoc cref="ScriptResolver"/>
|
|
public ScriptResolver(Dictionary<(ScriptCategory, StringKey), Func<Script>> scriptCtors)
|
|
{
|
|
_scriptCtors = scriptCtors;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Try and create a new script for the given category and key. If the script does not exist, return false.
|
|
/// </summary>
|
|
public bool TryResolve(ScriptCategory category, StringKey key, [MaybeNullWhen(false)] out Script script)
|
|
{
|
|
if (!_scriptCtors.TryGetValue((category, key), out var scriptCtor))
|
|
{
|
|
script = null;
|
|
return false;
|
|
}
|
|
script = scriptCtor();
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Try and resolve an item script for the given item. If the item does not have a script, return false.
|
|
/// </summary>
|
|
public bool TryResolveItemScript(IItem item, [MaybeNullWhen(false)] out Script script)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
} |