forked from Shardstone/trail-into-darkness
Added a custom calendar system
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using Jovian.Calendar;
|
||||
using Jovian.PopupSystem;
|
||||
using Jovian.PopupSystem.UI;
|
||||
using Jovian.SaveSystem;
|
||||
@@ -125,14 +126,16 @@ namespace Nox.Game {
|
||||
partyInventoryHandler ??= new PartyInventoryHandler(adventureData, adventureSettings);
|
||||
partyInventoryHandler.Initialize();
|
||||
|
||||
timeHandler ??= new TimeHandler(adventureSettings, adventureData);
|
||||
var calendarSettings = Addressables.LoadAssetAsync<CalendarSettings>("CalendarSettings").WaitForCompletion();
|
||||
var worldClock = new WorldClock(calendarSettings);
|
||||
timeHandler ??= new TimeHandler(adventureSettings, adventureData, worldClock);
|
||||
zoneSystem ??= new ZoneSystem(mapRef.zonesObjectHolder);
|
||||
|
||||
partyMovementHandler ??= new PartyMovementHandler(partyRef, cameraController, mapLocationsReference, platformSettings.inputSettings, zoneSystem, adventureData, adventureSettings);
|
||||
partyMovementHandler.Initialize();
|
||||
|
||||
guiReferences ??= Object.FindFirstObjectByType<GuiReferences>();
|
||||
adventureView ??= new AdventureView(gameDataState, guiReferences, inputActions, adventureData, adventureSettings);
|
||||
adventureView ??= new AdventureView(gameDataState, guiReferences, inputActions, adventureData, adventureSettings, worldClock);
|
||||
adventureView.Initialize();
|
||||
|
||||
if(partyGuiView == null && guiReferences.partyMemberSlotPrefab != null) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Nox.Game {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using Jovian.Calendar;
|
||||
using Nox.Core;
|
||||
|
||||
namespace Nox.Game.UI {
|
||||
@@ -7,20 +8,22 @@ namespace Nox.Game.UI {
|
||||
private readonly InputSystem_Actions inputActions;
|
||||
private readonly AdventureData adventureData;
|
||||
private readonly AdventureSettings adventureSettings;
|
||||
private DayPhase dayPhase = DayPhase.Midnight;
|
||||
private readonly WorldClock worldClock;
|
||||
private int currentDay;
|
||||
private int previousTime;
|
||||
|
||||
public AdventureView(
|
||||
GameDataState gameDataState,
|
||||
public AdventureView(GameDataState gameDataState,
|
||||
GuiReferences guiReferences,
|
||||
InputSystem_Actions inputActions,
|
||||
AdventureData adventureData,
|
||||
AdventureSettings adventureSettings) {
|
||||
AdventureSettings adventureSettings,
|
||||
WorldClock worldClock) {
|
||||
this.gameDataState = gameDataState;
|
||||
this.guiReferences = guiReferences;
|
||||
this.inputActions = inputActions;
|
||||
this.adventureData = adventureData;
|
||||
this.adventureSettings = adventureSettings;
|
||||
this.worldClock = worldClock;
|
||||
}
|
||||
private void InvokePauseMenu() {
|
||||
gameDataState.ChangePlayMode(PlayMode.PauseMenu);
|
||||
@@ -28,7 +31,8 @@ namespace Nox.Game.UI {
|
||||
|
||||
public void Initialize() {
|
||||
guiReferences.pauseMenuButton.onClick.AddListener(InvokePauseMenu);
|
||||
guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
|
||||
guiReferences.dayText.text = $"{worldClock.FullStringNamed()}";
|
||||
previousTime = -1;
|
||||
guiReferences.suppliesBar.fillAmount = (float)adventureData.suppliesAvailable / adventureSettings.maxSupplies;
|
||||
guiReferences.suppliesText.text = $"{adventureData.suppliesAvailable}/{adventureSettings.maxSupplies}";
|
||||
}
|
||||
@@ -40,14 +44,14 @@ namespace Nox.Game.UI {
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public void Tick() {
|
||||
if(dayPhase != adventureData.currentDayPhase) {
|
||||
dayPhase = adventureData.currentDayPhase;
|
||||
guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
|
||||
var time = worldClock.Now.minute;
|
||||
if (time != previousTime) {
|
||||
previousTime = time;
|
||||
}
|
||||
guiReferences.dayText.text = $"{worldClock.FullStringNamed()}";
|
||||
|
||||
if(currentDay != adventureData.currentDay) {
|
||||
currentDay = adventureData.currentDay;
|
||||
guiReferences.dayText.text = $"Day {adventureData.currentDay}, {adventureData.currentDayPhase.ToString()}";
|
||||
guiReferences.suppliesBar.fillAmount = (float)adventureData.suppliesAvailable / adventureSettings.maxSupplies;
|
||||
guiReferences.suppliesText.text = $"{adventureData.suppliesAvailable}/{adventureSettings.maxSupplies}";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user