refactor(CS): schedule + periods are config-owned, AdminPanel-editable
Some checks failed
.NET Core / build (push) Has been cancelled

Move the auto-schedule from context-owned state to the plugin config (single source
of truth): RegistrationOpenDays + RegistrationOpenTimes + Registration/Preparation/
SiegeDuration are all editable in the AdminPanel plugin config and take effect live
(context refreshes its config reference each tick via UpdateConfiguration). /csschedule
now writes the config. Removed the duplicate Persisted schedule fields. 12 tests pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Acentech Dev
2026-07-15 14:52:07 +03:00
parent f586321123
commit 4651ef232c
5 changed files with 61 additions and 69 deletions

View File

@@ -131,34 +131,34 @@ public class CastleSiegeContextTest
var phaseChangedFired = false;
ctx.PhaseChanged += _ => phaseChangedFired = true;
ctx.RestoreState("Winners", CastleSiegePhase.Ownership, T0, new[] { "Winners", "Losers" }, new[] { DayOfWeek.Sunday }, new TimeOnly(20, 0));
ctx.RestoreState("Winners", CastleSiegePhase.Ownership, T0, new[] { "Winners", "Losers" });
Assert.That(ctx.Phase, Is.EqualTo(CastleSiegePhase.Ownership));
Assert.That(ctx.OwnerGuildName, Is.EqualTo("Winners"));
Assert.That(ctx.RegisteredGuilds, Is.EquivalentTo(new[] { "Winners", "Losers" }));
Assert.That(ctx.ScheduleDays, Is.EquivalentTo(new[] { DayOfWeek.Sunday }));
Assert.That(ctx.ScheduleTime, Is.EqualTo(new TimeOnly(20, 0)));
Assert.That(phaseChangedFired, Is.False);
Assert.That(ctx.ConsumeDirty(), Is.False, "restore must not mark the state dirty");
}
/// <summary>Tests that the weekly auto-schedule only opens registration on a matching day within the time window.</summary>
/// <summary>Tests that the weekly auto-schedule (stored in config) only fires on a matching day/time window.</summary>
[Test]
public void ShouldOpenRegistrationMatchesDayAndTimeWindow()
public void ScheduleFiresOnMatchingDayAndTimeWindow()
{
var ctx = new CastleSiegeContext(Config());
ctx.SetSchedule(new[] { DayOfWeek.Sunday }, new TimeOnly(20, 0));
var config = ctx.Configuration;
var sunday = new DateTime(2026, 1, 4, 20, 0, 2, DateTimeKind.Utc); // a Sunday, +2s into the window
var sundayLate = new DateTime(2026, 1, 4, 20, 0, 30, DateTimeKind.Utc); // past the 5s window
var monday = new DateTime(2026, 1, 5, 20, 0, 2, DateTimeKind.Utc); // wrong day
Assert.That(ctx.ShouldOpenRegistration(sunday), Is.True);
Assert.That(ctx.ShouldOpenRegistration(sundayLate), Is.False);
Assert.That(ctx.ShouldOpenRegistration(monday), Is.False);
Assert.That(config.IsRegistrationOpenTime(sunday), Is.True);
Assert.That(config.IsRegistrationOpenTime(sundayLate), Is.False);
Assert.That(config.IsRegistrationOpenTime(monday), Is.False);
Assert.That(ctx.ConsumeDirty(), Is.True, "SetSchedule marks the state dirty");
ctx.SetSchedule(Array.Empty<DayOfWeek>(), null); // cleared -> never opens
Assert.That(ctx.ShouldOpenRegistration(sunday), Is.False);
Assert.That(config.IsRegistrationOpenTime(sunday), Is.False);
}
/// <summary>Tests that state-changing operations flip the dirty flag, which ConsumeDirty reads-and-resets.</summary>