Route Continue through typed run state
This commit is contained in:
parent
101d237129
commit
672b133ee1
5 changed files with 172 additions and 8 deletions
|
|
@ -46,7 +46,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
|
||||
private static string _runtimeStateFilePath;
|
||||
private static string RuntimeStateFilePath =>
|
||||
public static string RuntimeStateFilePath =>
|
||||
_runtimeStateFilePath ??= AetheriaRuntimeStateBoundary.GetStateFilePath(GameDataDirectory);
|
||||
|
||||
private static RuntimePlayerSettings _runtimePlayerSettings;
|
||||
|
|
@ -315,6 +315,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
public static Galaxy CurrentGalaxy;
|
||||
public static bool IsTutorial;
|
||||
public static AetheriaRuntimeRunStateSnapshot ContinueRunState { get; set; }
|
||||
public static AetheriaRuntimeCatalogSnapshot RuntimeCatalog { get; private set; }
|
||||
|
||||
public GameSettings Settings;
|
||||
|
|
@ -2420,8 +2421,17 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
if (CurrentGalaxy != null)
|
||||
{
|
||||
SectorMap.QueueZoneReveal(CurrentGalaxy.Entrance.AdjacentZones.Prepend(CurrentGalaxy.Entrance));
|
||||
PopulateLevel(CurrentGalaxy.Entrance);
|
||||
var continuingRun = ContinueRunState;
|
||||
var startZone = ResolveStartZone(continuingRun);
|
||||
SectorMap.QueueZoneReveal(startZone.AdjacentZones.Prepend(startZone));
|
||||
PopulateLevel(startZone);
|
||||
|
||||
if (continuingRun != null)
|
||||
{
|
||||
ContinueRunState = null;
|
||||
return;
|
||||
}
|
||||
|
||||
var loadoutGenerator = new LoadoutGenerator(ref ItemManager.Random, ItemManager, RuntimeCatalog, CurrentGalaxy, Zone.GalaxyZone, IsTutorial ? CurrentGalaxy.ResolveFaction(Settings.TutorialGenerationSettings.ProtagonistFaction) : null, 2);
|
||||
var ship = EntityConstructionBlueprintProjector.InstantiateFromBlueprint(
|
||||
ItemManager,
|
||||
|
|
@ -2437,6 +2447,21 @@ public class ActionGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private static GalaxyZone ResolveStartZone(AetheriaRuntimeRunStateSnapshot run)
|
||||
{
|
||||
if (CurrentGalaxy?.Zones == null || CurrentGalaxy.Zones.Length == 0)
|
||||
return CurrentGalaxy?.Entrance;
|
||||
|
||||
if (run != null &&
|
||||
run.CurrentZoneIndex >= 0 &&
|
||||
run.CurrentZoneIndex < CurrentGalaxy.Zones.Length)
|
||||
{
|
||||
return CurrentGalaxy.Zones[run.CurrentZoneIndex];
|
||||
}
|
||||
|
||||
return CurrentGalaxy.Entrance;
|
||||
}
|
||||
|
||||
private IEnumerator IntroCutscene(Ship ship)
|
||||
{
|
||||
ZoneRenderer.PerspectiveEntity = ship;
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
|
@ -88,7 +89,8 @@ public class MainMenu : MonoBehaviour
|
|||
_nextMenu.panel.Title.text = TitleSubtitle("aetheria", "terminus");
|
||||
if (!InGame)
|
||||
{
|
||||
_nextMenu.panel.AddButton("Continue", null);
|
||||
var continueRun = LatestContinueRun();
|
||||
_nextMenu.panel.AddButton("Continue", continueRun == null ? null : () => ContinueGame(continueRun));
|
||||
}
|
||||
_nextMenu.panel.AddButton("New Game",
|
||||
() =>
|
||||
|
|
@ -171,6 +173,75 @@ public class MainMenu : MonoBehaviour
|
|||
return seed == 0 ? 1u : seed;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeRunStateSnapshot LatestContinueRun()
|
||||
{
|
||||
try
|
||||
{
|
||||
return AetheriaRuntimeCatalogStore
|
||||
.ReadRunStates(ActionGameManager.RuntimeStateFilePath)
|
||||
.Where(run => !string.IsNullOrWhiteSpace(run.RunId))
|
||||
.OrderByDescending(run => run.UpdatedAtUtc, StringComparer.Ordinal)
|
||||
.ThenByDescending(run => run.RunId, StringComparer.Ordinal)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"Failed to read typed Aetheria run state for Continue: {ex}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ContinueGame(AetheriaRuntimeRunStateSnapshot run)
|
||||
{
|
||||
if (run == null)
|
||||
return;
|
||||
|
||||
var generatorState = "Loading typed run";
|
||||
Action<string> setState = s => generatorState = s;
|
||||
|
||||
Fade(true);
|
||||
_nextMenu.panel.gameObject.SetActive(false);
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Continuing Run";
|
||||
Dialog.AddProperty(() => generatorState);
|
||||
Dialog.Show();
|
||||
|
||||
ActionGameManager.IsTutorial = run.IsTutorial;
|
||||
ActionGameManager.ContinueRunState = run;
|
||||
var generationSeed = run.GenerationSeed == 0 ? NextGenerationSeed() : run.GenerationSeed;
|
||||
var sectorSettings = run.IsTutorial ? Settings.TutorialGenerationSettings : Settings.SectorGenerationSettings;
|
||||
var backgroundSettings = run.IsTutorial ? Settings.TutorialBackgroundSettings : Settings.SectorBackgroundSettings;
|
||||
backgroundSettings.NoisePosition = generationSeed;
|
||||
|
||||
Task.Run(() =>
|
||||
{
|
||||
var sector = run.IsTutorial
|
||||
? new Galaxy(
|
||||
Settings.TutorialGenerationSettings,
|
||||
Settings.TutorialBackgroundSettings,
|
||||
Settings.NameGeneratorSettings,
|
||||
ActionGameManager.RuntimeCatalog,
|
||||
ActionGameManager.RuntimePlayerSettings,
|
||||
ActionGameManager.GameDataDirectory.CreateSubdirectory("Narrative"),
|
||||
Debug.Log,
|
||||
setState,
|
||||
generationSeed)
|
||||
: new Galaxy(
|
||||
sectorSettings,
|
||||
backgroundSettings,
|
||||
Settings.NameGeneratorSettings,
|
||||
ActionGameManager.RuntimeCatalog,
|
||||
Debug.Log,
|
||||
setState,
|
||||
generationSeed);
|
||||
Observable.NextFrame().Subscribe(_ =>
|
||||
{
|
||||
ActionGameManager.CurrentGalaxy = sector;
|
||||
SceneManager.LoadScene("ARPG");
|
||||
});
|
||||
}).WrapErrors();
|
||||
}
|
||||
|
||||
private void ShowSettings()
|
||||
{
|
||||
_nextMenu.panel.Clear();
|
||||
|
|
|
|||
Loading…
Reference in a new issue