Introduce a Calendar in Core that turns scaled clock time into whole in-game days plus a fraction-of-day, with a configurable SecondsPerDay. Pausing or changing TimeScale slows or stops it automatically. Pure read-side and deterministic, registered via context.UseCalendar(...), mirroring GameSpeed. Covered by xUnit tests; docs updated. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
53659450a6
commit
f791ee6c95
@@ -0,0 +1,69 @@
|
||||
using MrGameEng.Core;
|
||||
using Xunit;
|
||||
|
||||
namespace MrGameEng.Core.Tests;
|
||||
|
||||
public class CalendarTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_NonPositiveSecondsPerDay_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => new Calendar(new GameClock(), 0f));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TotalDays_TracksScaledClockTime()
|
||||
{
|
||||
var clock = new GameClock();
|
||||
var calendar = new Calendar(clock, secondsPerDay: 10f);
|
||||
|
||||
clock.Advance(5f); // half a day
|
||||
|
||||
Assert.Equal(0.5, calendar.TotalDays, 5);
|
||||
Assert.Equal(1, calendar.Day);
|
||||
Assert.Equal(0.5f, calendar.DayProgress, 5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Day_CountsFromOne_AndRollsOver()
|
||||
{
|
||||
var clock = new GameClock();
|
||||
var calendar = new Calendar(clock, secondsPerDay: 10f);
|
||||
|
||||
Assert.Equal(1, calendar.Day);
|
||||
|
||||
clock.Advance(10f); // exactly one day
|
||||
Assert.Equal(2, calendar.Day);
|
||||
Assert.Equal(0f, calendar.DayProgress, 5);
|
||||
|
||||
clock.Advance(15f); // total 25s = 2.5 days
|
||||
Assert.Equal(3, calendar.Day);
|
||||
Assert.Equal(0.5f, calendar.DayProgress, 5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pause_DoesNotAdvanceTheCalendar()
|
||||
{
|
||||
var clock = new GameClock { TimeScale = 0f };
|
||||
var calendar = new Calendar(clock, secondsPerDay: 10f);
|
||||
|
||||
clock.Advance(100f);
|
||||
|
||||
Assert.Equal(0.0, calendar.TotalDays, 5);
|
||||
Assert.Equal(1, calendar.Day);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TimeScale_SpeedsUpTheCalendar()
|
||||
{
|
||||
var slow = new GameClock();
|
||||
var fast = new GameClock { TimeScale = 6f };
|
||||
var slowCal = new Calendar(slow, secondsPerDay: 10f);
|
||||
var fastCal = new Calendar(fast, secondsPerDay: 10f);
|
||||
|
||||
slow.Advance(10f);
|
||||
fast.Advance(10f);
|
||||
|
||||
Assert.Equal(6.0, fastCal.TotalDays / slowCal.TotalDays, 5);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user