forked from Shardstone/trail-into-darkness
Added a custom calendar system
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Jovian.Calendar;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Nox.Game {
|
||||
@@ -13,6 +14,7 @@ namespace Nox.Game {
|
||||
public class TimeHandler {
|
||||
private readonly AdventureSettings adventureSettings;
|
||||
private readonly AdventureData adventureData;
|
||||
private readonly WorldClock worldClock;
|
||||
|
||||
private float localTime;
|
||||
|
||||
@@ -23,34 +25,44 @@ namespace Nox.Game {
|
||||
(0.25f, DayPhase.Morning),
|
||||
(0.50f, DayPhase.Afternoon),
|
||||
(0.75f, DayPhase.Dusk),
|
||||
(0.90f, DayPhase.Night),
|
||||
(0.90f, DayPhase.Night)
|
||||
};
|
||||
|
||||
public TimeHandler(AdventureSettings adventureSettings, AdventureData adventureData) {
|
||||
public TimeHandler(AdventureSettings adventureSettings, AdventureData adventureData, WorldClock worldClock) {
|
||||
this.adventureSettings = adventureSettings;
|
||||
this.adventureData = adventureData;
|
||||
this.worldClock = worldClock;
|
||||
localTime = adventureData.currentTime * adventureSettings.dayLength;
|
||||
}
|
||||
|
||||
public void Tick() {
|
||||
if (!adventureData.isPartyMoving) return;
|
||||
if(!adventureData.isPartyMoving) {
|
||||
return;
|
||||
}
|
||||
|
||||
localTime += Time.deltaTime;
|
||||
|
||||
if (localTime >= adventureSettings.dayLength) {
|
||||
if(localTime >= adventureSettings.dayLength) {
|
||||
localTime -= adventureSettings.dayLength;
|
||||
adventureData.currentDay++;
|
||||
}
|
||||
|
||||
adventureData.currentTime = localTime / adventureSettings.dayLength;
|
||||
adventureData.currentDayPhase = GetPhase(adventureData.currentTime);
|
||||
var normalized = localTime / adventureSettings.dayLength;
|
||||
|
||||
worldClock.Tick(normalized);
|
||||
|
||||
adventureData.currentTime = normalized;
|
||||
adventureData.currentDayPhase = GetPhase(normalized);
|
||||
}
|
||||
|
||||
private static DayPhase GetPhase(float t) {
|
||||
var phase = DayPhase.Midnight;
|
||||
foreach (var (start, p) in PhaseThresholds) {
|
||||
if (t >= start) phase = p;
|
||||
else break;
|
||||
foreach(var (start, p) in PhaseThresholds) {
|
||||
if(t >= start) {
|
||||
phase = p;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return phase;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user