Enhance Calendar and Climate systems with start day offsets
CI / build-test (push) Successful in 1m13s
CI / build-test (push) Successful in 1m13s
- Added a `startDay` parameter to the `Calendar` class to allow for fractional day offsets at clock initialization, enabling more flexible time settings. - Updated `TotalDays` calculation to include the `startDay` offset. - Introduced `StartDayOfYear` in `ClimateSettings` to shift the seasonal phase, allowing worlds to begin at a specific time of year. - Adjusted `YearProgress` and `Year` calculations in the `Climate` class to account for the new `StartDayOfYear`. - Added unit tests to verify the functionality of the new start day features in both `Calendar` and `Climate` classes.
This commit is contained in:
@@ -54,6 +54,20 @@ public class CalendarTests
|
||||
Assert.Equal(14 * 60 + 30, calendar.MinuteOfDay);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartDay_OffsetsTheTimeOfDay()
|
||||
{
|
||||
var clock = new GameClock();
|
||||
var calendar = new Calendar(clock, secondsPerDay: 10f, startDay: 7.0 / 24); // begin at 07:00
|
||||
|
||||
Assert.Equal(1, calendar.Day);
|
||||
Assert.Equal(7, calendar.Hour);
|
||||
Assert.Equal(0, calendar.Minute);
|
||||
|
||||
clock.Advance(5f); // half a day later → 19:00
|
||||
Assert.Equal(19, calendar.Hour);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Pause_DoesNotAdvanceTheCalendar()
|
||||
{
|
||||
|
||||
@@ -81,4 +81,15 @@ public class ClimateTests
|
||||
Assert.Equal(2, climate.Year);
|
||||
Assert.Equal(0, climate.DayOfYear);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartDayOfYear_ShiftsTheSeasonalPhase()
|
||||
{
|
||||
// Begin the world already at the warmest day (15): the curve peaks at clock 0.
|
||||
var (_, climate) = Make(Seasonal with { StartDayOfYear = 15 });
|
||||
|
||||
Assert.Equal(30f, climate.Temperature, 2); // mean 10 + amplitude 20, at the peak
|
||||
Assert.Equal(15, climate.DayOfYear); // day-of-year reflects the offset
|
||||
Assert.Equal(Season.Summer, climate.Season); // day 15 of a 60-day year = start of summer
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user