Own Continue current entity by typed state key
This commit is contained in:
parent
c0aec84af4
commit
4ee0628a5a
12 changed files with 114 additions and 22 deletions
Binary file not shown.
|
|
@ -407,8 +407,8 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s
|
|||
[
|
||||
new AetheriaOrbitSnapshot
|
||||
{
|
||||
OrbitId = "smoke:orbit",
|
||||
ParentId = "smoke:parent-orbit",
|
||||
OrbitKey = "smoke:orbit",
|
||||
ParentOrbitKey = "smoke:parent-orbit",
|
||||
Distance = 100,
|
||||
Phase = 0.25,
|
||||
FixedPosition = new AetheriaVector2 { X = 5, Y = -6 }
|
||||
|
|
@ -418,10 +418,10 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s
|
|||
[
|
||||
new AetheriaBodySnapshot
|
||||
{
|
||||
BodyId = "smoke:body",
|
||||
BodyKey = "smoke:body",
|
||||
Kind = "asteroid_belt",
|
||||
Name = "Smoke Belt",
|
||||
OrbitId = "smoke:orbit",
|
||||
OrbitKey = "smoke:orbit",
|
||||
Mass = 42,
|
||||
Resources =
|
||||
[
|
||||
|
|
@ -463,6 +463,7 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s
|
|||
ExitZoneIndex = 1,
|
||||
CurrentZoneIndex = 0,
|
||||
CurrentZoneEntityIndex = 0,
|
||||
CurrentEntityKey = entityKey.ToString(),
|
||||
GenerationSeed = 424242,
|
||||
DiscoveredZoneIndices = [0],
|
||||
ZoneKeys = [zoneKey.ToString()],
|
||||
|
|
@ -622,6 +623,7 @@ await using (var reopened = await AetheriaStateNode.OpenAsync(statePath, "aether
|
|||
|
||||
if (runState?.RunId != "smoke" ||
|
||||
runState.GenerationSeed != 424242 ||
|
||||
runState.CurrentEntityKey != entityKey.ToString() ||
|
||||
runState.ZoneKeys.Length != 1 ||
|
||||
runState.ActionBarBindings.Length != 1)
|
||||
{
|
||||
|
|
@ -633,7 +635,7 @@ await using (var reopened = await AetheriaStateNode.OpenAsync(statePath, "aether
|
|||
zoneState.Position.X != 4.0 ||
|
||||
zoneState.OwnerFactionIndex != 0 ||
|
||||
zoneState.Orbits.Length != 1 ||
|
||||
zoneState.Orbits[0].OrbitId != "smoke:orbit" ||
|
||||
zoneState.Orbits[0].OrbitKey != "smoke:orbit" ||
|
||||
zoneState.Bodies.Length != 1 ||
|
||||
zoneState.Bodies[0].Kind != "asteroid_belt" ||
|
||||
zoneState.Bodies[0].Resources.Length != 1 ||
|
||||
|
|
|
|||
|
|
@ -243,6 +243,7 @@ try
|
|||
GenerationSeed = 424242,
|
||||
CurrentZoneIndex = 0,
|
||||
CurrentZoneEntityIndex = 0,
|
||||
CurrentEntityKey = "global:aetheria.run_state.smoke-run.zone.0.entity.0.v1",
|
||||
DiscoveredZoneIndices = new[] { 0 },
|
||||
ActionBarBindings = new[]
|
||||
{
|
||||
|
|
@ -719,6 +720,7 @@ try
|
|||
loadout.RootEntity.CargoContents.Length == 1 &&
|
||||
loadout.RootEntity.CargoContents[0].Items[0].Item.Quantity == 5 &&
|
||||
run?.ZoneKeys.Length == 1 &&
|
||||
run.CurrentEntityKey == "global:aetheria.run_state.smoke-run.zone.0.entity.0.v1" &&
|
||||
run.GenerationSeed == 424242 &&
|
||||
run.ActionBarBindings.Length == 2 &&
|
||||
run.ActionBarBindings[0].ControlPath == "<Keyboard>/1" &&
|
||||
|
|
@ -735,12 +737,12 @@ try
|
|||
run.FactionRelationships[0].Standing == 3 &&
|
||||
zone?.EntityKeys.Length == 1 &&
|
||||
zone.Orbits.Length == 1 &&
|
||||
zone.Orbits[0].OrbitId == "aetheria.orbit:legacy:smoke:orbit" &&
|
||||
zone.Orbits[0].ParentId == "aetheria.orbit:legacy:smoke:parent-orbit" &&
|
||||
zone.Orbits[0].OrbitKey == "aetheria.orbit:legacy:smoke:orbit" &&
|
||||
zone.Orbits[0].ParentOrbitKey == "aetheria.orbit:legacy:smoke:parent-orbit" &&
|
||||
zone.Orbits[0].FixedPosition.X == 5.0 &&
|
||||
zone.Bodies.Length == 1 &&
|
||||
zone.Bodies[0].BodyId == "aetheria.body:legacy:smoke:body" &&
|
||||
zone.Bodies[0].OrbitId == "aetheria.orbit:legacy:smoke:orbit" &&
|
||||
zone.Bodies[0].BodyKey == "aetheria.body:legacy:smoke:body" &&
|
||||
zone.Bodies[0].OrbitKey == "aetheria.orbit:legacy:smoke:orbit" &&
|
||||
zone.Bodies[0].Kind == "asteroid_belt" &&
|
||||
zone.Bodies[0].Resources.Length == 1 &&
|
||||
zone.Bodies[0].Resources[0].ItemKey == "aetheria.item_definition:legacy:smoke:ore" &&
|
||||
|
|
@ -884,6 +886,7 @@ try
|
|||
packageRuns.Count != 1 ||
|
||||
packageRuns[0].RunId != "smoke-run" ||
|
||||
packageRuns[0].GenerationSeed != 424242 ||
|
||||
packageRuns[0].CurrentEntityKey != "global:aetheria.run_state.smoke-run.zone.0.entity.0.v1" ||
|
||||
packageRuns[0].ZoneKeys.Count != 1 ||
|
||||
packageRuns[0].ActionBarBindings.Count != 2 ||
|
||||
packageRuns[0].ActionBarBindings[1].TargetKey != "aetheria.item_definition:legacy:smoke:weapon" ||
|
||||
|
|
@ -894,12 +897,12 @@ try
|
|||
packageZones[0].Name != "Unity Smoke Zone" ||
|
||||
packageZones[0].EntityKeys.Count != 1 ||
|
||||
packageZones[0].Orbits.Count != 1 ||
|
||||
packageZones[0].Orbits[0].OrbitId != "aetheria.orbit:legacy:smoke:orbit" ||
|
||||
packageZones[0].Orbits[0].ParentId != "aetheria.orbit:legacy:smoke:parent-orbit" ||
|
||||
packageZones[0].Orbits[0].OrbitKey != "aetheria.orbit:legacy:smoke:orbit" ||
|
||||
packageZones[0].Orbits[0].ParentOrbitKey != "aetheria.orbit:legacy:smoke:parent-orbit" ||
|
||||
packageZones[0].Orbits[0].FixedPositionX != 5.0 ||
|
||||
packageZones[0].Bodies.Count != 1 ||
|
||||
packageZones[0].Bodies[0].BodyId != "aetheria.body:legacy:smoke:body" ||
|
||||
packageZones[0].Bodies[0].OrbitId != "aetheria.orbit:legacy:smoke:orbit" ||
|
||||
packageZones[0].Bodies[0].BodyKey != "aetheria.body:legacy:smoke:body" ||
|
||||
packageZones[0].Bodies[0].OrbitKey != "aetheria.orbit:legacy:smoke:orbit" ||
|
||||
packageZones[0].Bodies[0].ResourceCount != 1 ||
|
||||
packageZones[0].Bodies[0].AsteroidCount != 1 ||
|
||||
packageZones[0].Bodies[0].DamagedAsteroidCount != 1 ||
|
||||
|
|
|
|||
|
|
@ -1904,6 +1904,8 @@ static void RequireMainMenuContinueRunState(string root)
|
|||
"RestoreEntityGraphFromTypedRun(continuingRun)",
|
||||
"ReadEntitySnapshots(RuntimeStateFilePath)",
|
||||
"entity.RecordKey",
|
||||
"run.CurrentEntityKey",
|
||||
"ResolveCurrentEntityRecordKey(run, zoneEntityKeyPrefix)",
|
||||
"ReplaceZoneEntitiesFromTypedSnapshots",
|
||||
"Zone.Agents.Clear()",
|
||||
"FlattenEntityGraph(Zone)",
|
||||
|
|
@ -1937,6 +1939,23 @@ static void RequireMainMenuContinueRunState(string root)
|
|||
string.Join(", ", missingGameplaySymbols));
|
||||
}
|
||||
|
||||
var forbiddenGameplaySymbols = new[]
|
||||
{
|
||||
"if (run == null ||\r\n run.CurrentZoneIndex < 0 ||\r\n run.CurrentZoneEntityIndex < 0)",
|
||||
"var currentEntityKey = $\"{zoneEntityKeyPrefix}{run.CurrentZoneEntityIndex}.v1\""
|
||||
};
|
||||
|
||||
var forbiddenGameplayHits = forbiddenGameplaySymbols
|
||||
.Where(symbol => actionGameManager.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
|
||||
if (forbiddenGameplayHits.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"ActionGameManager still reconstructs Continue current-entity ownership from integer slot state: " +
|
||||
string.Join(", ", forbiddenGameplayHits));
|
||||
}
|
||||
|
||||
var requiredPackageSymbols = new[]
|
||||
{
|
||||
"public string RecordKey",
|
||||
|
|
|
|||
|
|
@ -282,9 +282,22 @@ public static class AetheriaRuntimeCommitLogApplier
|
|||
|
||||
if (zoneKeys.Count > 0)
|
||||
run.ZoneKeys = zoneKeys.ToArray();
|
||||
run.CurrentEntityKey = string.IsNullOrWhiteSpace(checkpoint.CurrentEntityKey)
|
||||
? LegacyCurrentEntityKey(run.RunId, checkpoint.CurrentZoneIndex, checkpoint.CurrentZoneEntityIndex)
|
||||
: checkpoint.CurrentEntityKey;
|
||||
await node.PutRunStateAsync(RunKey(run.RunId), run).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static string LegacyCurrentEntityKey(string runId, int zoneIndex, int entityIndex)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(runId) || zoneIndex < 0 || entityIndex < 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return EntityKey(runId, zoneIndex, entityIndex).ToString();
|
||||
}
|
||||
|
||||
private static AetheriaDroppedPickupSnapshot[] ToDroppedPickups(
|
||||
IReadOnlyList<AetheriaRuntimeDroppedPickupCommit>? pickups)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -234,6 +234,10 @@ public sealed class AetheriaRunState
|
|||
|
||||
[Key(11)]
|
||||
public uint GenerationSeed { get; set; }
|
||||
|
||||
[Key(12)]
|
||||
[CultReference(typeof(AetheriaEntitySnapshot))]
|
||||
public string CurrentEntityKey { get; set; } = "";
|
||||
}
|
||||
|
||||
[CultDocument("aetheria.zone_state", "aetheria.zone_state.v1")]
|
||||
|
|
|
|||
|
|
@ -325,6 +325,9 @@ smoke proves a typed run can reference a typed zone, the zone can preserve
|
|||
orbit/body rows and reference typed entity snapshots, and entity snapshots can
|
||||
preserve equipment slots, weapon groups, and simulation stat grids without
|
||||
reviving `PlayerSettings.msgpack`, `.loadout`, or `.zone` serialization.
|
||||
The run document also carries `CurrentEntityKey`, so Continue restore binds the
|
||||
saved player entity by exact typed record identity instead of reconstructing it
|
||||
from a transient entity-slot index.
|
||||
|
||||
`Aetheria.State.Verify` opens a materialized state file and checks that the
|
||||
typed migration ledger matches the actual item, corporation, and name-file
|
||||
|
|
|
|||
|
|
@ -601,14 +601,17 @@ public class ActionGameManager : MonoBehaviour
|
|||
private AetheriaRuntimeRunCheckpointCommit ProjectRunCheckpoint()
|
||||
{
|
||||
var entityGraph = FlattenEntityGraph(Zone);
|
||||
var runId = IsTutorial ? "tutorial" : "local";
|
||||
var currentZoneIndex = ZoneIndex(Zone?.GalaxyZone);
|
||||
return new AetheriaRuntimeRunCheckpointCommit
|
||||
{
|
||||
RunId = IsTutorial ? "tutorial" : "local",
|
||||
RunId = runId,
|
||||
IsTutorial = IsTutorial,
|
||||
EntranceZoneIndex = ZoneIndex(CurrentGalaxy?.Entrance),
|
||||
ExitZoneIndex = ZoneIndex(CurrentGalaxy?.Exit),
|
||||
CurrentZoneIndex = ZoneIndex(Zone?.GalaxyZone),
|
||||
CurrentZoneIndex = currentZoneIndex,
|
||||
CurrentZoneEntityIndex = IndexOfEntity(entityGraph, CurrentEntity),
|
||||
CurrentEntityKey = CurrentEntityRecordKey(runId, currentZoneIndex, entityGraph, CurrentEntity),
|
||||
GenerationSeed = CurrentGalaxy?.GenerationSeed ?? 0,
|
||||
DiscoveredZoneIndices = CurrentGalaxy?.DiscoveredZones
|
||||
.Select(ZoneIndex)
|
||||
|
|
@ -2494,15 +2497,19 @@ public class ActionGameManager : MonoBehaviour
|
|||
|
||||
private void RestoreEntityGraphFromTypedRun(AetheriaRuntimeRunStateSnapshot run)
|
||||
{
|
||||
if (run == null ||
|
||||
run.CurrentZoneIndex < 0 ||
|
||||
run.CurrentZoneEntityIndex < 0)
|
||||
if (run == null || run.CurrentZoneIndex < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var zoneEntityKeyPrefix = $"global:aetheria.run_state.{run.RunId}.zone.{run.CurrentZoneIndex}.entity.";
|
||||
var currentEntityKey = $"{zoneEntityKeyPrefix}{run.CurrentZoneEntityIndex}.v1";
|
||||
var currentEntityKey = ResolveCurrentEntityRecordKey(run, zoneEntityKeyPrefix);
|
||||
if (string.IsNullOrWhiteSpace(currentEntityKey))
|
||||
{
|
||||
Debug.LogWarning($"Typed run {run.RunId} does not identify a current entity for restored zone {zoneEntityKeyPrefix}.");
|
||||
return;
|
||||
}
|
||||
|
||||
AetheriaRuntimeEntitySnapshot[] entitySnapshots;
|
||||
try
|
||||
{
|
||||
|
|
@ -2526,6 +2533,37 @@ public class ActionGameManager : MonoBehaviour
|
|||
ReplaceZoneEntitiesFromTypedSnapshots(entitySnapshots, currentEntityKey);
|
||||
}
|
||||
|
||||
private static string CurrentEntityRecordKey(
|
||||
string runId,
|
||||
int currentZoneIndex,
|
||||
IReadOnlyList<Entity> entityGraph,
|
||||
Entity currentEntity)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(runId) || currentZoneIndex < 0 || currentEntity == null)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
var currentZoneEntityIndex = IndexOfEntity(entityGraph, currentEntity);
|
||||
return currentZoneEntityIndex < 0
|
||||
? ""
|
||||
: $"global:aetheria.run_state.{runId}.zone.{currentZoneIndex}.entity.{currentZoneEntityIndex}.v1";
|
||||
}
|
||||
|
||||
private static string ResolveCurrentEntityRecordKey(
|
||||
AetheriaRuntimeRunStateSnapshot run,
|
||||
string zoneEntityKeyPrefix)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(run.CurrentEntityKey))
|
||||
{
|
||||
return run.CurrentEntityKey;
|
||||
}
|
||||
|
||||
return run.CurrentZoneEntityIndex < 0
|
||||
? ""
|
||||
: $"{zoneEntityKeyPrefix}{run.CurrentZoneEntityIndex}.v1";
|
||||
}
|
||||
|
||||
private void ReplaceZoneEntitiesFromTypedSnapshots(
|
||||
IReadOnlyList<AetheriaRuntimeEntitySnapshot> entitySnapshots,
|
||||
string currentEntityKey)
|
||||
|
|
|
|||
|
|
@ -691,6 +691,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
int exitZoneIndex,
|
||||
int currentZoneIndex,
|
||||
int currentZoneEntityIndex,
|
||||
string currentEntityKey,
|
||||
IReadOnlyList<int> discoveredZoneIndices,
|
||||
IReadOnlyList<string> zoneKeys,
|
||||
IReadOnlyList<AetheriaRuntimeActionBarBindingSnapshot> actionBarBindings,
|
||||
|
|
@ -704,6 +705,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
ExitZoneIndex = exitZoneIndex;
|
||||
CurrentZoneIndex = currentZoneIndex;
|
||||
CurrentZoneEntityIndex = currentZoneEntityIndex;
|
||||
CurrentEntityKey = currentEntityKey;
|
||||
DiscoveredZoneIndices = discoveredZoneIndices;
|
||||
ZoneKeys = zoneKeys;
|
||||
ActionBarBindings = actionBarBindings;
|
||||
|
|
@ -718,6 +720,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public int ExitZoneIndex { get; }
|
||||
public int CurrentZoneIndex { get; }
|
||||
public int CurrentZoneEntityIndex { get; }
|
||||
public string CurrentEntityKey { get; }
|
||||
public IReadOnlyList<int> DiscoveredZoneIndices { get; }
|
||||
public IReadOnlyList<string> ZoneKeys { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeActionBarBindingSnapshot> ActionBarBindings { get; }
|
||||
|
|
|
|||
|
|
@ -463,7 +463,8 @@ namespace GameCult.Aetheria.State.Unity
|
|||
var factionRelationships = ReadFieldFactionRelationships(ref reader, fields, 9);
|
||||
var updatedAtUtc = ReadFieldString(ref reader, fields, 10);
|
||||
var generationSeed = ReadFieldUInt32(ref reader, fields, 11);
|
||||
SkipRemaining(ref reader, fields, 12);
|
||||
var currentEntityKey = ReadFieldString(ref reader, fields, 12);
|
||||
SkipRemaining(ref reader, fields, 13);
|
||||
return new AetheriaRuntimeRunStateSnapshot(
|
||||
runId,
|
||||
isTutorial,
|
||||
|
|
@ -471,6 +472,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
exitZoneIndex,
|
||||
currentZoneIndex,
|
||||
currentZoneEntityIndex,
|
||||
currentEntityKey,
|
||||
discoveredZoneIndices,
|
||||
zoneKeys,
|
||||
actionBarBindings,
|
||||
|
|
|
|||
|
|
@ -247,6 +247,9 @@ namespace GameCult.Aetheria.State.Unity
|
|||
|
||||
[Key(10)]
|
||||
public uint GenerationSeed { get; set; }
|
||||
|
||||
[Key(11)]
|
||||
public string CurrentEntityKey { get; set; } = "";
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
|
|||
|
|
@ -992,8 +992,10 @@ First Aetheria surfaces to publish:
|
|||
hull-conductivity axes, then reconnects target/contact rows among restored
|
||||
entities, restores child/docking relationships from typed child keys and
|
||||
docking-bay assignments, restores typed weapon and behavior runtime rows
|
||||
into live behavior instances, and binds the saved current entity as the
|
||||
player ship or docked current ship.
|
||||
into live behavior instances, and binds the saved current entity by
|
||||
`AetheriaRunState.CurrentEntityKey` so Continue restore follows exact typed
|
||||
entity identity instead of reconstructing the player ship from an integer
|
||||
slot.
|
||||
- Done: project run checkpoint entity snapshots from the flattened live
|
||||
entity graph, not only `Zone.Entities`, so docked child ships can receive
|
||||
typed entity records and stable child/docking references instead of
|
||||
|
|
|
|||
Loading…
Reference in a new issue