Centralize runtime entity record keys

This commit is contained in:
Meta Vens 2026-06-29 04:09:00 +01:00
commit e15eb1b22b
6 changed files with 52 additions and 76 deletions

View file

@ -6579,7 +6579,7 @@ static void RequireStationRefitDockingBaysUseTypedProjection(string root)
"dockParent.DockingBayContents",
"OccupiedEntityIndex = assignedEntity?.EntityIndex ?? assignedEntityIndex",
"OccupiedEntityKey = assignedEntity == null",
"BuildEntityKey(context.RunId, context.Zone.ZoneIndex, assignedEntity.EntityIndex)",
"AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, assignedEntity.EntityIndex)",
"OccupiedEntityName = assignedEntity?.Name",
"OccupiedHullItemKey = assignedEntity?.HullItemKey",
"OccupiedByCurrentEntity = assignedEntityIndex >= 0 && assignedEntityIndex == currentEntityIndex",
@ -6612,6 +6612,13 @@ static void RequireStationRefitDockingBaysUseTypedProjection(string root)
string.Join(", ", missingProjectionSymbols));
}
if (runtimeProjection.Contains("private static string BuildEntityKey(", StringComparison.Ordinal) ||
runtimeProjection.Contains("private static bool TryParseEntityKey(", StringComparison.Ordinal))
{
throw new InvalidOperationException(
"Runtime projection reintroduced local entity key folklore; use AetheriaRuntimeRunCheckpointCommit entity key helpers.");
}
var requiredPanelSymbols = new[]
{
"TryResolveCurrentDockingBayRow(out var currentDockingBay)",
@ -9944,11 +9951,12 @@ static void RequireTypedDaemonCommandPayloads(string root)
var actionGameManagerPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "ActionGameManager.cs");
var testsPath = Path.Combine(root, "Assets", "Scripts", "Tests", "DaemonRuntimeDocumentTests.cs");
var daemonSurfaceCommandsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonSurfaceCommands.cs");
var starbridgeDocumentsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeStarbridgeDocuments.cs");
if (File.Exists(legacyDaemonApplierPath))
throw new InvalidOperationException("Legacy daemon command applier still exists; daemon operations must own execution.");
var requiredFiles = new[] { daemonDocumentsPath, daemonClientPath, daemonRuntimeOperationsPath, stateNodePath, observerPath, actionGameManagerPath, testsPath, daemonSurfaceCommandsPath };
var requiredFiles = new[] { daemonDocumentsPath, daemonClientPath, daemonRuntimeOperationsPath, stateNodePath, observerPath, actionGameManagerPath, testsPath, daemonSurfaceCommandsPath, starbridgeDocumentsPath };
var missingFiles = requiredFiles
.Where(path => !File.Exists(path))
.Select(path => Path.GetRelativePath(root, path))
@ -9968,6 +9976,20 @@ static void RequireTypedDaemonCommandPayloads(string root)
var actionGameManager = File.ReadAllText(actionGameManagerPath);
var tests = File.ReadAllText(testsPath);
var daemonSurfaceCommands = File.ReadAllText(daemonSurfaceCommandsPath);
var starbridgeDocuments = File.ReadAllText(starbridgeDocumentsPath);
if (daemonOperationsSource.Contains("private static string BuildEntityKey(", StringComparison.Ordinal) ||
daemonOperationsSource.Contains("private static bool TryParseEntityKey(", StringComparison.Ordinal))
{
throw new InvalidOperationException(
"Daemon operations reintroduced local entity key parsing/building; use AetheriaRuntimeRunCheckpointCommit entity key helpers.");
}
if (starbridgeDocuments.Contains("private static string BuildEntityKey(", StringComparison.Ordinal))
{
throw new InvalidOperationException(
"Starbridge documents reintroduced local entity key building; use AetheriaRuntimeRunCheckpointCommit entity key helpers.");
}
var requiredPayloadTypes = new[]
{

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
#nullable enable
@ -369,7 +368,7 @@ namespace GameCult.Aetheria.State.Verse
return false;
run.CurrentZoneIndex = zoneIndex;
run.CurrentEntityKey = BuildEntityKey(run.RunId, zoneIndex, entityIndex);
run.CurrentEntityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(run.RunId, zoneIndex, entityIndex);
return true;
}
@ -394,7 +393,7 @@ namespace GameCult.Aetheria.State.Verse
return false;
run.CurrentZoneIndex = zoneIndex;
run.CurrentEntityKey = BuildEntityKey(run.RunId, zoneIndex, entityIndex);
run.CurrentEntityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(run.RunId, zoneIndex, entityIndex);
return true;
}
@ -871,7 +870,7 @@ namespace GameCult.Aetheria.State.Verse
assignments.Add(entityIndex);
parent.DockingBayAssignments = assignments.ToArray();
purchasedShipKey = BuildEntityKey(run.RunId, zoneIndex, entityIndex);
purchasedShipKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(run.RunId, zoneIndex, entityIndex);
return true;
}
@ -899,7 +898,7 @@ namespace GameCult.Aetheria.State.Verse
if (template == null)
return false;
if (!TryParseEntityKey(command.TargetEntityKey, out var zoneIndex, out _))
if (!AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(command.TargetEntityKey, out var zoneIndex, out _))
return false;
var newEntityKey = run.AppendLoadoutTemplateToZone(
@ -1208,7 +1207,7 @@ namespace GameCult.Aetheria.State.Verse
if (closestIndex < 0)
return false;
targetEntityKey = BuildEntityKey(run.RunId, zoneIndex, closestIndex);
targetEntityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(run.RunId, zoneIndex, closestIndex);
return true;
}
@ -1437,7 +1436,7 @@ namespace GameCult.Aetheria.State.Verse
{
movedEntityKey = "";
if (!TryParseEntityKey(entityKey, out var sourceZoneIndex, out var sourceEntityIndex))
if (!AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(entityKey, out var sourceZoneIndex, out var sourceEntityIndex))
return false;
var zones = (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>()).ToList();
@ -1456,7 +1455,7 @@ namespace GameCult.Aetheria.State.Verse
if (IsChildReferencedInZone(run, sourceZoneIndex, sourceEntityIndex))
return false;
var movedCurrentEntity = TryParseEntityKey(run.CurrentEntityKey, out var currentZoneIndex, out var currentEntityIndex) &&
var movedCurrentEntity = AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(run.CurrentEntityKey, out var currentZoneIndex, out var currentEntityIndex) &&
currentZoneIndex == sourceZoneIndex &&
currentEntityIndex == sourceEntityIndex;
@ -1486,7 +1485,7 @@ namespace GameCult.Aetheria.State.Verse
targetEntities.Add(movedEntity);
targetZone.Entities = targetEntities.ToArray();
movedEntityKey = BuildEntityKey(run.RunId, targetZoneIndex, targetEntityIndex);
movedEntityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(run.RunId, targetZoneIndex, targetEntityIndex);
if (movedCurrentEntity)
{
run.CurrentZoneIndex = targetZoneIndex;
@ -1511,7 +1510,7 @@ namespace GameCult.Aetheria.State.Verse
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeDaemonCommandDocument command)
{
if (!TryParseEntityKey(command.TargetEntityKey, out var zoneIndex, out var entityIndex))
if (!AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(command.TargetEntityKey, out var zoneIndex, out var entityIndex))
return false;
var zones = (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>()).ToList();
@ -1566,7 +1565,7 @@ namespace GameCult.Aetheria.State.Verse
int zoneIndex,
int removedEntityIndex)
{
if (!TryParseEntityKey(run.CurrentEntityKey, out var currentZoneIndex, out var currentEntityIndex) ||
if (!AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(run.CurrentEntityKey, out var currentZoneIndex, out var currentEntityIndex) ||
currentZoneIndex != zoneIndex)
{
return;
@ -1575,7 +1574,7 @@ namespace GameCult.Aetheria.State.Verse
var reindexedCurrent = ReindexEntityReference(currentEntityIndex, removedEntityIndex);
run.CurrentEntityKey = reindexedCurrent < 0
? ""
: BuildEntityKey(run.RunId, zoneIndex, reindexedCurrent);
: AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(run.RunId, zoneIndex, reindexedCurrent);
}
private static bool ApplyTargetEntity(
@ -1601,7 +1600,7 @@ namespace GameCult.Aetheria.State.Verse
zoneIndex = -1;
entityIndex = -1;
if (!TryParseEntityKey(entityKey, out zoneIndex, out entityIndex))
if (!AetheriaRuntimeRunCheckpointCommit.TryParseEntityKey(entityKey, out zoneIndex, out entityIndex))
return false;
var parsedZoneIndex = zoneIndex;
@ -1628,12 +1627,6 @@ namespace GameCult.Aetheria.State.Verse
: referencedEntityIndex;
}
private static string BuildEntityKey(string runId, int zoneIndex, int entityIndex)
{
var normalizedRunId = string.IsNullOrWhiteSpace(runId) ? "local" : runId;
return $"global:aetheria.run_state.{normalizedRunId}.zone.{zoneIndex}.entity.{entityIndex}.v1";
}
private static string ResolveActorEntityKey(
AetheriaRuntimeRunCheckpointCommit run,
AetheriaRuntimeDaemonCommandDocument command)
@ -1869,35 +1862,5 @@ namespace GameCult.Aetheria.State.Verse
Math.Abs(pickup.PositionZ - expectedZ) < 0.001;
}
private static bool TryParseEntityKey(
string entityKey,
out int zoneIndex,
out int entityIndex)
{
zoneIndex = -1;
entityIndex = -1;
if (string.IsNullOrWhiteSpace(entityKey))
return false;
var parts = entityKey.Split('.');
for (var i = 0; i < parts.Length - 1; i++)
{
if (string.Equals(parts[i], "zone", StringComparison.Ordinal) &&
int.TryParse(parts[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture, out zoneIndex))
{
continue;
}
if (string.Equals(parts[i], "entity", StringComparison.Ordinal) &&
int.TryParse(parts[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture, out entityIndex))
{
continue;
}
}
return zoneIndex >= 0 && entityIndex >= 0;
}
}
}

View file

@ -286,7 +286,7 @@ namespace GameCult.Aetheria.State.Verse
1,
1,
1,
BuildEntityKey(context.RunId, zone.ZoneIndex, entity.EntityIndex));
AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, zone.ZoneIndex, entity.EntityIndex));
}
return new AetheriaRuntimeRenderSplatsViewportDocument
@ -407,7 +407,7 @@ namespace GameCult.Aetheria.State.Verse
.FirstOrDefault(candidate => candidate.EntityIndex == currentEntityIndex);
var entityKey = entity == null
? context.Run.CurrentEntityKey ?? ""
: BuildEntityKey(context.RunId, context.Zone.ZoneIndex, entity.EntityIndex);
: AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, entity.EntityIndex);
var inventory = entity == null
? Array.Empty<AetheriaRuntimeRtsInventoryItem>()
: Inventory(entity).ToArray();
@ -447,10 +447,10 @@ namespace GameCult.Aetheria.State.Verse
var parent = FindDockParent(context.Zone, currentEntityIndex, out var dockingBayIndex);
var currentEntityKey = currentEntityIndex < 0
? context.Run.CurrentEntityKey ?? ""
: BuildEntityKey(context.RunId, context.Zone.ZoneIndex, currentEntityIndex);
: AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, currentEntityIndex);
var parentKey = parent == null
? ""
: BuildEntityKey(context.RunId, context.Zone.ZoneIndex, parent.EntityIndex);
: AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, parent.EntityIndex);
return new AetheriaRuntimeCurrentDockingDocument
{
@ -515,10 +515,10 @@ namespace GameCult.Aetheria.State.Verse
var parent = FindDockParent(context.Zone, currentEntityIndex, out var dockingBayIndex);
var currentEntityKey = currentEntityIndex < 0
? context.Run.CurrentEntityKey ?? ""
: BuildEntityKey(context.RunId, context.Zone.ZoneIndex, currentEntityIndex);
: AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, currentEntityIndex);
var parentKey = parent == null
? ""
: BuildEntityKey(context.RunId, context.Zone.ZoneIndex, parent.EntityIndex);
: AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, parent.EntityIndex);
var availableEntities = parent == null
? Array.Empty<AetheriaRuntimeStationRefitEntityOption>()
: ProjectStationRefitEntities(context, parent, currentEntityIndex);
@ -768,7 +768,7 @@ namespace GameCult.Aetheria.State.Verse
RunId = context.RunId,
ZoneIndex = context.Zone.ZoneIndex,
EntityIndex = entityIndex,
EntityKey = entity == null ? "" : BuildEntityKey(context.RunId, context.Zone.ZoneIndex, entityIndex),
EntityKey = entity == null ? "" : AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, entityIndex),
Items = items,
Equipment = items.Where(item => string.Equals(item.Source, "equipment", StringComparison.Ordinal)).ToArray(),
Cargo = items.Where(item => string.Equals(item.Source, "cargo", StringComparison.Ordinal)).ToArray()
@ -823,7 +823,7 @@ namespace GameCult.Aetheria.State.Verse
var obj = new AetheriaRuntimeRtsViewportObject
{
EntityIndex = entity.EntityIndex,
EntityKey = BuildEntityKey(runId, zoneIndex, entity.EntityIndex),
EntityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(runId, zoneIndex, entity.EntityIndex),
DisplayName = entity.Name ?? "",
Kind = entity.Kind ?? "",
FactionKey = entity.FactionKey ?? "",
@ -1065,7 +1065,7 @@ namespace GameCult.Aetheria.State.Verse
options.Add(new AetheriaRuntimeStationRefitEntityOption
{
EntityKey = BuildEntityKey(context.RunId, context.Zone.ZoneIndex, entity.EntityIndex),
EntityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, entity.EntityIndex),
EntityIndex = entity.EntityIndex,
DisplayName = entity.Name ?? "",
Kind = entity.Kind ?? "",
@ -1150,7 +1150,7 @@ namespace GameCult.Aetheria.State.Verse
OccupiedEntityIndex = assignedEntity?.EntityIndex ?? assignedEntityIndex,
OccupiedEntityKey = assignedEntity == null
? ""
: BuildEntityKey(context.RunId, context.Zone.ZoneIndex, assignedEntity.EntityIndex),
: AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(context.RunId, context.Zone.ZoneIndex, assignedEntity.EntityIndex),
OccupiedEntityName = assignedEntity?.Name ?? "",
OccupiedHullItemKey = assignedEntity?.HullItemKey ?? "",
OccupiedByCurrentEntity = assignedEntityIndex >= 0 && assignedEntityIndex == currentEntityIndex,
@ -1563,11 +1563,6 @@ namespace GameCult.Aetheria.State.Verse
};
}
private static string BuildEntityKey(string runId, int zoneIndex, int entityIndex)
{
return $"global:aetheria.run_state.{runId}.zone.{zoneIndex}.entity.{entityIndex}.v1";
}
private static AetheriaRuntimeEntitySnapshotCommit? FindDockParent(
AetheriaRuntimeZoneSnapshotCommit zone,
int currentEntityIndex,

View file

@ -884,7 +884,7 @@ namespace GameCult.Aetheria.State.Verse
{
return string.IsNullOrWhiteSpace(runId)
? ""
: $"global:aetheria.run_state.{runId}.zone.{zoneIndex}.entity.{entityIndex}.v1";
: AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(runId, zoneIndex, entityIndex);
}
public AetheriaRuntimeEntitySnapshot[] CreateEntitySnapshots()

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using MessagePack;
@ -272,13 +273,13 @@ namespace GameCult.Aetheria.State.Verse
for (var i = 0; i < parts.Length - 1; i++)
{
if (string.Equals(parts[i], "zone", StringComparison.Ordinal) &&
int.TryParse(parts[i + 1], out zoneIndex))
int.TryParse(parts[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture, out zoneIndex))
{
continue;
}
if (string.Equals(parts[i], "entity", StringComparison.Ordinal) &&
int.TryParse(parts[i + 1], out entityIndex))
int.TryParse(parts[i + 1], NumberStyles.Integer, CultureInfo.InvariantCulture, out entityIndex))
{
continue;
}

View file

@ -174,7 +174,7 @@ namespace GameCult.Aetheria.State.Verse
.ToArray();
foreach (var entity in entities)
{
var entityKey = BuildEntityKey(runId, zoneIndex, entity.EntityIndex);
var entityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(runId, zoneIndex, entity.EntityIndex);
if (keys.Any(key => string.Equals(key, entityKey, StringComparison.Ordinal) ||
string.Equals(key, entity.Name, StringComparison.OrdinalIgnoreCase)))
{
@ -206,7 +206,7 @@ namespace GameCult.Aetheria.State.Verse
return new AetheriaRuntimeStarbridgeBaseStatus
{
EntityKey = BuildEntityKey(runId, zoneIndex, entity.EntityIndex),
EntityKey = AetheriaRuntimeRunCheckpointCommit.EntityRecordKey(runId, zoneIndex, entity.EntityIndex),
DisplayName = entity.Name ?? "",
Hull = Stat(entity, "hull"),
Shield = Stat(entity, "shield"),
@ -307,11 +307,6 @@ namespace GameCult.Aetheria.State.Verse
return grid?.Values?.FirstOrDefault() ?? 0;
}
private static string BuildEntityKey(string runId, int zoneIndex, int entityIndex)
{
return $"global:aetheria.run_state.{runId}.zone.{zoneIndex}.entity.{entityIndex}.v1";
}
private static string FirstNonEmpty(params string?[] values)
{
foreach (var value in values)