Set up DynamicLibrary from plugins
This commit is contained in:
parent
c7a6823896
commit
5b495ac871
|
@ -1,3 +1,5 @@
|
|||
using PkmnLib.Dynamic.ScriptHandling;
|
||||
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
||||
using PkmnLib.Static.Libraries;
|
||||
|
||||
namespace PkmnLib.Dynamic.Libraries;
|
||||
|
@ -33,7 +35,24 @@ public interface IDynamicLibrary
|
|||
|
||||
public class DynamicLibraryImpl : IDynamicLibrary
|
||||
{
|
||||
public DynamicLibraryImpl(IStaticLibrary staticLibrary, IBattleStatCalculator statCalculator,
|
||||
public static IDynamicLibrary Create(IStaticLibrary staticLibrary, IEnumerable<Plugin> plugins)
|
||||
{
|
||||
var registry = new ScriptRegistry();
|
||||
foreach (var plugin in plugins.OrderBy(x => x.LoadOrder))
|
||||
{
|
||||
plugin.Register(registry);
|
||||
}
|
||||
if (registry.DamageCalculator is null)
|
||||
throw new InvalidOperationException("Damage calculator not found in plugins.");
|
||||
if (registry.BattleStatCalculator is null)
|
||||
throw new InvalidOperationException("Stat calculator not found in plugins.");
|
||||
if (registry.MiscLibrary is null)
|
||||
throw new InvalidOperationException("Misc library not found in plugins.");
|
||||
return new DynamicLibraryImpl(staticLibrary, registry.BattleStatCalculator,
|
||||
registry.DamageCalculator, registry.MiscLibrary);
|
||||
}
|
||||
|
||||
private DynamicLibraryImpl(IStaticLibrary staticLibrary, IBattleStatCalculator statCalculator,
|
||||
IDamageCalculator damageCalculator, IMiscLibrary miscLibrary)
|
||||
{
|
||||
StaticLibrary = staticLibrary;
|
||||
|
@ -42,6 +61,7 @@ public class DynamicLibraryImpl : IDynamicLibrary
|
|||
MiscLibrary = miscLibrary;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public IStaticLibrary StaticLibrary { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
Loading…
Reference in New Issue