Refactor the handling of date time to no longer depend on a static
Build / Build (push) Successful in 10m13s

This commit is contained in:
Deukhoofd committed 2026-11-14 21:46:12 +01:00
1 parent 4c51e67985
commit 7649be8294
11 files changed
+53 -39

No files matched your search

@@ -1,4 +1,5 @@
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Plugins;
namespace PkmnLib.Plugin.Gen7.Tests;
@@ -11,7 +12,10 @@ public static class LibraryHelpers
{
DamageCalculatorHasRandomness = false,
}),
]);
], new PluginEnvironmentHelpers
{
DateTimeProvider = () => DateTimeOffset.Now,
});
return dynamicLibrary;
}
}
+2 -2
View File
@@ -42,12 +42,12 @@ public class Gen7Plugin : Plugin<Gen7PluginConfiguration>, IResourceProvider
public override uint LoadOrder => 0;
/// <inheritdoc />
public override void Register(ScriptRegistry registry)
public override void Register(ScriptRegistry registry, PluginEnvironmentHelpers helpers)
{
registry.RegisterAssemblyScripts(typeof(Gen7Plugin).Assembly);
registry.RegisterBattleStatCalculator(new Gen7BattleStatCalculator());
registry.RegisterDamageCalculator(new Gen7DamageCalculator(Configuration));
registry.RegisterMiscLibrary(new Gen7MiscLibrary());
registry.RegisterMiscLibrary(new Gen7MiscLibrary(helpers.DateTimeProvider));
registry.RegisterCaptureLibrary(new Gen7CaptureLibrary(Configuration));
registry.RegisterExperienceGainCalculator(new Gen7ExperienceGainCalculator());
@@ -1,10 +1,11 @@
using PkmnLib.Dynamic;
using PkmnLib.Dynamic.Libraries;
using PkmnLib.Dynamic.Plugins;
using PkmnLib.Static.Moves;
namespace PkmnLib.Plugin.Gen7.Libraries.Battling;
public class Gen7MiscLibrary : IMiscLibrary
public class Gen7MiscLibrary(PluginEnvironmentHelpers.DateTimeProviderDelegate dateTimeProvider) : IMiscLibrary
{
private readonly IMoveData _struggleData = new MoveDataImpl("struggle", new TypeIdentifier(0, "none"),
MoveCategory.Physical, 50, 255, 255, MoveTarget.Any, 0,
@@ -21,7 +22,7 @@ public class Gen7MiscLibrary : IMiscLibrary
/// <inheritdoc />
public TimeOfDay GetTimeOfDay()
{
var time = StaticHelpers.GetCurrentDateTime().LocalDateTime;
var time = dateTimeProvider().LocalDateTime;
var hour = time.Hour;
return hour switch
{