2024-08-10 07:44:46 +00:00
|
|
|
using PkmnLib.Dynamic.ScriptHandling;
|
2024-07-28 10:01:43 +00:00
|
|
|
using PkmnLib.Dynamic.ScriptHandling.Registry;
|
2024-07-27 14:26:45 +00:00
|
|
|
using PkmnLib.Static.Libraries;
|
|
|
|
|
|
|
|
namespace PkmnLib.Dynamic.Libraries;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The dynamic library stores a static data library, as well as holding different libraries and
|
|
|
|
/// calculators that might be customized between different generations and implementations.
|
|
|
|
/// </summary>
|
|
|
|
public interface IDynamicLibrary
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// The static data is the immutable storage data for this library.
|
|
|
|
/// </summary>
|
|
|
|
IStaticLibrary StaticLibrary { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The stat calculator deals with the calculation of flat and boosted stats, based on the
|
|
|
|
/// Pokémon's attributes.
|
|
|
|
/// </summary>
|
|
|
|
IBattleStatCalculator StatCalculator { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The damage calculator deals with the calculation of things relating to damage.
|
|
|
|
/// </summary>
|
|
|
|
IDamageCalculator DamageCalculator { get; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The Misc Library holds minor functions that do not fall in any of the other libraries and
|
|
|
|
/// calculators.
|
|
|
|
/// </summary>
|
|
|
|
IMiscLibrary MiscLibrary { get; }
|
2024-08-10 07:44:46 +00:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A holder of the script types that can be resolved by this library.
|
|
|
|
/// </summary>
|
|
|
|
ScriptResolver ScriptResolver { get; }
|
2024-07-27 14:26:45 +00:00
|
|
|
}
|
|
|
|
|
2024-07-28 10:29:47 +00:00
|
|
|
/// <inheritdoc />
|
2024-07-27 14:26:45 +00:00
|
|
|
public class DynamicLibraryImpl : IDynamicLibrary
|
|
|
|
{
|
2024-07-28 10:29:47 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="DynamicLibraryImpl"/> class, with the given
|
|
|
|
/// plugins and static library.
|
|
|
|
/// </summary>
|
2024-07-28 10:01:43 +00:00
|
|
|
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.");
|
2025-01-10 10:11:50 +00:00
|
|
|
var scriptResolver = new ScriptResolver(registry.ScriptTypes, registry.ItemScriptTypes);
|
2024-07-28 10:01:43 +00:00
|
|
|
return new DynamicLibraryImpl(staticLibrary, registry.BattleStatCalculator,
|
2024-08-10 07:44:46 +00:00
|
|
|
registry.DamageCalculator, registry.MiscLibrary, scriptResolver);
|
2024-07-28 10:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private DynamicLibraryImpl(IStaticLibrary staticLibrary, IBattleStatCalculator statCalculator,
|
2024-08-10 07:44:46 +00:00
|
|
|
IDamageCalculator damageCalculator, IMiscLibrary miscLibrary, ScriptResolver scriptResolver)
|
2024-07-27 14:26:45 +00:00
|
|
|
{
|
|
|
|
StaticLibrary = staticLibrary;
|
|
|
|
StatCalculator = statCalculator;
|
|
|
|
DamageCalculator = damageCalculator;
|
|
|
|
MiscLibrary = miscLibrary;
|
2024-08-10 07:44:46 +00:00
|
|
|
ScriptResolver = scriptResolver;
|
2024-07-27 14:26:45 +00:00
|
|
|
}
|
|
|
|
|
2024-07-28 10:01:43 +00:00
|
|
|
/// <inheritdoc />
|
2024-07-27 14:26:45 +00:00
|
|
|
public IStaticLibrary StaticLibrary { get; }
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IBattleStatCalculator StatCalculator { get; }
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IDamageCalculator DamageCalculator { get; }
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public IMiscLibrary MiscLibrary { get; }
|
2024-08-10 07:44:46 +00:00
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
public ScriptResolver ScriptResolver { get; }
|
2024-07-27 14:26:45 +00:00
|
|
|
}
|