Move body and orbit key ownership into zone runtime
This commit is contained in:
parent
6391176a40
commit
0471cb690f
7 changed files with 105 additions and 32 deletions
Binary file not shown.
|
|
@ -764,7 +764,11 @@ static void RequireTypedBehaviorBodyKeys(string root)
|
|||
"ResourceScannerTargetBodyId",
|
||||
"MiningToolAsteroidBeltId",
|
||||
"ParseLegacyGuidFromReferenceKey",
|
||||
"ParseLegacyIdFromReferenceKey"
|
||||
"ParseLegacyIdFromReferenceKey",
|
||||
"private static string OrbitKey(Guid",
|
||||
"private static string BodyKey(Guid",
|
||||
"$\"aetheria.orbit:legacy:",
|
||||
"$\"aetheria.body:legacy:"
|
||||
};
|
||||
|
||||
var hits = checkedFiles
|
||||
|
|
@ -781,6 +785,29 @@ static void RequireTypedBehaviorBodyKeys(string root)
|
|||
"Runtime behavior body references must be named typed BodyKey surfaces; GUID parsing is confined to ParseBodyGuidFromKey: " +
|
||||
string.Join("; ", hits));
|
||||
}
|
||||
|
||||
var zoneSourcePath = Path.Combine(root, "Assets", "Scripts", "ServerShared", "Zone.cs");
|
||||
var zoneSource = File.Exists(zoneSourcePath)
|
||||
? File.ReadAllText(zoneSourcePath)
|
||||
: throw new InvalidOperationException("Cannot verify body/orbit key ownership; Zone source is missing.");
|
||||
var requiredZoneSymbols = new[]
|
||||
{
|
||||
"public const string OrbitKeyPrefix",
|
||||
"public const string BodyKeyPrefix",
|
||||
"public string BodyKey { get; }",
|
||||
"public string OrbitKey { get; }",
|
||||
"public string ParentOrbitKey { get; }",
|
||||
"public string GetBodyKey(Guid bodyId)"
|
||||
};
|
||||
var missingZoneSymbols = requiredZoneSymbols
|
||||
.Where(symbol => !zoneSource.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingZoneSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Zone runtime body/orbit objects must own typed projection key surfaces: " +
|
||||
string.Join(", ", missingZoneSymbols));
|
||||
}
|
||||
}
|
||||
|
||||
static void RequireTypedFactionShellLinks(string root)
|
||||
|
|
|
|||
|
|
@ -125,6 +125,9 @@ deleted. Behavior-state runtime commits and readback snapshots carry typed
|
|||
body-key fields for resource scanner targets and mining tool asteroid belts;
|
||||
the old raw body ID commit/readback field names are deleted. Unity still parses
|
||||
those body keys into GUIDs only at the current `Zone` body runtime boundary.
|
||||
`Zone`, `Planet`, `AsteroidBelt`, and `Orbit` now own the runtime
|
||||
body/orbit key surfaces used for projection, and `ActionGameManager` no longer
|
||||
formats body/orbit keys locally while checkpointing state.
|
||||
The package runtime catalog snapshot indexes items by canonical item key; Unity
|
||||
gameplay, HUD, inventory, trade, ship, and zone helper lookups use `ItemKey`
|
||||
directly instead of deriving `ItemId` and searching by legacy GUID.
|
||||
|
|
|
|||
|
|
@ -354,9 +354,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
if (string.IsNullOrWhiteSpace(bodyKey))
|
||||
return Guid.Empty;
|
||||
|
||||
const string bodyPrefix = "aetheria.body:legacy:";
|
||||
var runtimeBodyId = bodyKey.StartsWith(bodyPrefix, StringComparison.OrdinalIgnoreCase)
|
||||
? bodyKey.Substring(bodyPrefix.Length)
|
||||
var runtimeBodyId = bodyKey.StartsWith(Zone.BodyKeyPrefix, StringComparison.OrdinalIgnoreCase)
|
||||
? bodyKey.Substring(Zone.BodyKeyPrefix.Length)
|
||||
: bodyKey;
|
||||
return Guid.TryParse(runtimeBodyId, out var id) ? id : Guid.Empty;
|
||||
}
|
||||
|
|
@ -620,7 +619,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
EntranceZoneIndex = ZoneIndex(CurrentGalaxy?.Entrance),
|
||||
ExitZoneIndex = ZoneIndex(CurrentGalaxy?.Exit),
|
||||
CurrentZoneIndex = ZoneIndex(Zone?.GalaxyZone),
|
||||
CurrentZoneEntityIndex = entityGraph.IndexOf(CurrentEntity),
|
||||
CurrentZoneEntityIndex = IndexOfEntity(entityGraph, CurrentEntity),
|
||||
GenerationSeed = CurrentGalaxy?.GenerationSeed ?? 0,
|
||||
DiscoveredZoneIndices = CurrentGalaxy?.DiscoveredZones
|
||||
.Select(ZoneIndex)
|
||||
|
|
@ -750,8 +749,8 @@ public class ActionGameManager : MonoBehaviour
|
|||
.OrderBy(orbit => orbit.ID)
|
||||
.Select(orbit => new AetheriaRuntimeOrbitSnapshotCommit
|
||||
{
|
||||
OrbitKey = OrbitKey(orbit.ID),
|
||||
ParentOrbitKey = OrbitKey(orbit.Parent),
|
||||
OrbitKey = orbit.OrbitKey,
|
||||
ParentOrbitKey = orbit.ParentOrbitKey,
|
||||
Distance = orbit.Distance,
|
||||
Phase = orbit.Phase,
|
||||
FixedPositionX = orbit.FixedPosition.x,
|
||||
|
|
@ -776,10 +775,10 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
return new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = BodyKey(planet.ID),
|
||||
BodyKey = planet.BodyKey,
|
||||
Kind = BodyKind(planet),
|
||||
Name = planet.Name,
|
||||
OrbitKey = OrbitKey(planet.OrbitId),
|
||||
OrbitKey = planet.OrbitKey,
|
||||
Mass = planet.Mass,
|
||||
Resources = planet.Resources?
|
||||
.OrderBy(pair => pair.Key)
|
||||
|
|
@ -807,10 +806,10 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
return new AetheriaRuntimeBodySnapshotCommit
|
||||
{
|
||||
BodyKey = BodyKey(belt.ID),
|
||||
BodyKey = belt.BodyKey,
|
||||
Kind = "asteroid_belt",
|
||||
Name = belt.Name,
|
||||
OrbitKey = OrbitKey(belt.Orbit),
|
||||
OrbitKey = belt.OrbitKey,
|
||||
Mass = belt.Mass,
|
||||
Resources = belt.Resources?
|
||||
.OrderBy(pair => pair.Key)
|
||||
|
|
@ -944,7 +943,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
DirectionY = entity.Direction.y,
|
||||
VelocityX = entity.Velocity.x,
|
||||
VelocityY = entity.Velocity.y,
|
||||
TargetEntityIndex = entity.Target?.Value == null ? -1 : entityGraph.IndexOf(entity.Target.Value),
|
||||
TargetEntityIndex = entity.Target?.Value == null ? -1 : IndexOfEntity(entityGraph, entity.Target.Value),
|
||||
IsActive = entity.Active,
|
||||
HeatsinksEnabled = entity.HeatsinksEnabled,
|
||||
OverrideShutdown = entity.OverrideShutdown,
|
||||
|
|
@ -965,7 +964,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
VisibilitySourceCount = entity.VisibilitySources.Count,
|
||||
Contacts = ProjectEntityContacts(entityGraph, entity),
|
||||
ChildEntityIndices = entity.Children?
|
||||
.Select(child => entityGraph.IndexOf(child))
|
||||
.Select(child => IndexOfEntity(entityGraph, child))
|
||||
.Where(index => index >= 0)
|
||||
.ToArray() ?? Array.Empty<int>(),
|
||||
WeaponGroups = entity.WeaponGroups?
|
||||
|
|
@ -984,7 +983,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
return entity.EntityInfoGathered
|
||||
.Select(contact =>
|
||||
{
|
||||
var targetIndex = entityGraph.IndexOf(contact.Key);
|
||||
var targetIndex = IndexOfEntity(entityGraph, contact.Key);
|
||||
entity.EntityHostility.TryGetValue(contact.Key, out var hostile);
|
||||
return new AetheriaRuntimeEntityContactCommit
|
||||
{
|
||||
|
|
@ -998,6 +997,20 @@ public class ActionGameManager : MonoBehaviour
|
|||
.ToArray();
|
||||
}
|
||||
|
||||
private static int IndexOfEntity(IReadOnlyList<Entity> entityGraph, Entity entity)
|
||||
{
|
||||
if (entityGraph == null || entity == null)
|
||||
return -1;
|
||||
|
||||
for (var index = 0; index < entityGraph.Count; index++)
|
||||
{
|
||||
if (ReferenceEquals(entityGraph[index], entity))
|
||||
return index;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCargoBayLoadoutCommit[] ProjectRuntimeCargoBays<TBay>(IEnumerable<TBay> bays)
|
||||
where TBay : EquippedCargoBay
|
||||
{
|
||||
|
|
@ -1019,18 +1032,20 @@ public class ActionGameManager : MonoBehaviour
|
|||
private static AetheriaRuntimeBehaviorStateCommit[] ProjectBehaviorStates(Entity entity)
|
||||
{
|
||||
var states = new List<AetheriaRuntimeBehaviorStateCommit>();
|
||||
var zone = entity.Zone;
|
||||
|
||||
for (var ownerIndex = 0; ownerIndex < entity.Equipment.Count; ownerIndex++)
|
||||
states.AddRange(ProjectBehaviorStates("equipment", ownerIndex, entity.Equipment[ownerIndex].Behaviors));
|
||||
states.AddRange(ProjectBehaviorStates(zone, "equipment", ownerIndex, entity.Equipment[ownerIndex].Behaviors));
|
||||
|
||||
var activeConsumables = entity.ActiveConsumables;
|
||||
for (var ownerIndex = 0; ownerIndex < activeConsumables.Count; ownerIndex++)
|
||||
states.AddRange(ProjectBehaviorStates("active_consumable", ownerIndex, activeConsumables[ownerIndex].Behaviors));
|
||||
states.AddRange(ProjectBehaviorStates(zone, "active_consumable", ownerIndex, activeConsumables[ownerIndex].Behaviors));
|
||||
|
||||
return states.ToArray();
|
||||
}
|
||||
|
||||
private static IEnumerable<AetheriaRuntimeBehaviorStateCommit> ProjectBehaviorStates(
|
||||
Zone zone,
|
||||
string ownerKind,
|
||||
int ownerIndex,
|
||||
IReadOnlyList<Behavior> behaviors)
|
||||
|
|
@ -1104,7 +1119,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
state = new AetheriaRuntimeBehaviorStateCommit
|
||||
{
|
||||
ResourceScannerTargetBodyKey = BodyKey(resourceScanner.ScanTarget),
|
||||
ResourceScannerTargetBodyKey = zone?.GetBodyKey(resourceScanner.ScanTarget) ?? "",
|
||||
ResourceScannerAsteroidIndex = resourceScanner.Asteroid,
|
||||
ResourceScannerScanTime = resourceScanner.ScanTime,
|
||||
ResourceScannerRange = resourceScanner.Range,
|
||||
|
|
@ -1116,7 +1131,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
{
|
||||
state = new AetheriaRuntimeBehaviorStateCommit
|
||||
{
|
||||
MiningToolAsteroidBeltKey = BodyKey(miningTool.AsteroidBelt),
|
||||
MiningToolAsteroidBeltKey = zone?.GetBodyKey(miningTool.AsteroidBelt) ?? "",
|
||||
MiningToolAsteroidIndex = miningTool.Asteroid,
|
||||
MiningToolRange = miningTool.Range
|
||||
};
|
||||
|
|
@ -1260,7 +1275,7 @@ public class ActionGameManager : MonoBehaviour
|
|||
if (weapon is LockWeapon lockWeapon)
|
||||
{
|
||||
state.LockProgress = lockWeapon.LockProgress;
|
||||
state.LockTargetEntityIndex = lockWeapon.LockTarget == null ? -1 : entityGraph.IndexOf(lockWeapon.LockTarget);
|
||||
state.LockTargetEntityIndex = lockWeapon.LockTarget == null ? -1 : IndexOfEntity(entityGraph, lockWeapon.LockTarget);
|
||||
}
|
||||
|
||||
yield return state;
|
||||
|
|
@ -1389,16 +1404,6 @@ public class ActionGameManager : MonoBehaviour
|
|||
.ToArray() ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>();
|
||||
}
|
||||
|
||||
private static string OrbitKey(Guid id)
|
||||
{
|
||||
return id == Guid.Empty ? "" : $"aetheria.orbit:legacy:{id:D}";
|
||||
}
|
||||
|
||||
private static string BodyKey(Guid id)
|
||||
{
|
||||
return id == Guid.Empty ? "" : $"aetheria.body:legacy:{id:D}";
|
||||
}
|
||||
|
||||
private static int ZoneIndex(GalaxyZone zone)
|
||||
{
|
||||
return CurrentGalaxy?.Zones == null || zone == null ? -1 : Array.IndexOf(CurrentGalaxy.Zones, zone);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ using Random = Unity.Mathematics.Random;
|
|||
|
||||
public class Zone
|
||||
{
|
||||
public const string OrbitKeyPrefix = "aetheria.orbit:legacy:";
|
||||
public const string BodyKeyPrefix = "aetheria.body:legacy:";
|
||||
|
||||
public Action<string> Log;
|
||||
public ReactiveCollection<Entity> Entities = new ReactiveCollection<Entity>();
|
||||
public Dictionary<Guid, Planet> PlanetInstances = new Dictionary<Guid, Planet>();
|
||||
|
|
@ -102,6 +105,27 @@ public class Zone
|
|||
return agent;
|
||||
}
|
||||
|
||||
public static string OrbitKey(Guid id)
|
||||
{
|
||||
return id == Guid.Empty ? "" : $"{OrbitKeyPrefix}{id:D}";
|
||||
}
|
||||
|
||||
public static string BodyKey(Guid id)
|
||||
{
|
||||
return id == Guid.Empty ? "" : $"{BodyKeyPrefix}{id:D}";
|
||||
}
|
||||
|
||||
public string GetBodyKey(Guid bodyId)
|
||||
{
|
||||
if (bodyId == Guid.Empty)
|
||||
return "";
|
||||
if (PlanetInstances.TryGetValue(bodyId, out var planet))
|
||||
return planet.BodyKey;
|
||||
if (AsteroidBelts.TryGetValue(bodyId, out var belt))
|
||||
return belt.BodyKey;
|
||||
return BodyKey(bodyId);
|
||||
}
|
||||
|
||||
public void Update(float deltaTime)
|
||||
{
|
||||
_time += deltaTime;
|
||||
|
|
@ -367,8 +391,10 @@ public class Planet
|
|||
public Orbit Orbit;
|
||||
protected readonly PlanetSettings Settings;
|
||||
public Guid ID { get; }
|
||||
public string BodyKey { get; }
|
||||
public string Name { get; }
|
||||
public Guid OrbitId { get; }
|
||||
public string OrbitKey { get; }
|
||||
public float Mass { get; }
|
||||
public IReadOnlyDictionary<string, float> Resources { get; }
|
||||
public float BodyRadiusMultiplier { get; }
|
||||
|
|
@ -384,8 +410,10 @@ public class Planet
|
|||
Settings = settings;
|
||||
Orbit = orbit;
|
||||
ID = data.ID;
|
||||
BodyKey = Zone.BodyKey(data.ID);
|
||||
Name = data.Name ?? "";
|
||||
OrbitId = data.Orbit;
|
||||
OrbitKey = Zone.OrbitKey(data.Orbit);
|
||||
Mass = data.Mass;
|
||||
Resources = data.Resources;
|
||||
BodyRadiusMultiplier = data.BodyRadiusMultiplier;
|
||||
|
|
@ -472,8 +500,10 @@ public class AsteroidBelt
|
|||
{
|
||||
private readonly Asteroid[] _asteroids;
|
||||
public Guid ID { get; }
|
||||
public string BodyKey { get; }
|
||||
public string Name { get; }
|
||||
public Guid Orbit { get; }
|
||||
public string OrbitKey { get; }
|
||||
public float Mass { get; }
|
||||
public IReadOnlyDictionary<string, float> Resources { get; }
|
||||
public float BodyRadiusMultiplier { get; }
|
||||
|
|
@ -493,8 +523,10 @@ public class AsteroidBelt
|
|||
{
|
||||
_asteroids = data.Asteroids;
|
||||
ID = data.ID;
|
||||
BodyKey = Zone.BodyKey(data.ID);
|
||||
Name = data.Name ?? "";
|
||||
Orbit = data.Orbit;
|
||||
OrbitKey = Zone.OrbitKey(data.Orbit);
|
||||
Mass = data.Mass;
|
||||
Resources = data.Resources;
|
||||
BodyRadiusMultiplier = data.BodyRadiusMultiplier;
|
||||
|
|
@ -517,7 +549,9 @@ public class AsteroidBelt
|
|||
public class Orbit
|
||||
{
|
||||
public Guid ID { get; }
|
||||
public string OrbitKey { get; }
|
||||
public Guid Parent { get; }
|
||||
public string ParentOrbitKey { get; }
|
||||
public float Distance { get; }
|
||||
public float Phase { get; }
|
||||
public float2 FixedPosition { get; }
|
||||
|
|
@ -535,7 +569,9 @@ public class Orbit
|
|||
public Orbit(PlanetSettings settings, OrbitConstructionData data)
|
||||
{
|
||||
ID = data.ID;
|
||||
OrbitKey = Zone.OrbitKey(data.ID);
|
||||
Parent = data.Parent;
|
||||
ParentOrbitKey = Zone.OrbitKey(data.Parent);
|
||||
Distance = data.Distance;
|
||||
Phase = data.Phase;
|
||||
FixedPosition = data.FixedPosition;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
|
|
@ -209,7 +210,6 @@ public class MainMenu : MonoBehaviour
|
|||
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;
|
||||
|
||||
|
|
@ -227,7 +227,7 @@ public class MainMenu : MonoBehaviour
|
|||
setState,
|
||||
generationSeed)
|
||||
: new Galaxy(
|
||||
sectorSettings,
|
||||
Settings.SectorGenerationSettings,
|
||||
backgroundSettings,
|
||||
Settings.NameGeneratorSettings,
|
||||
ActionGameManager.RuntimeCatalog,
|
||||
|
|
|
|||
|
|
@ -1774,7 +1774,9 @@ First Aetheria surfaces to publish:
|
|||
- `Aetheria.State.Verify` guards behavior body reference naming:
|
||||
resource-scanner and mining-tool runtime state surfaces use `BodyKey` fields;
|
||||
old `*BodyId` readback names and generic legacy reference parsers may not
|
||||
return.
|
||||
return. `Zone`, `Planet`, `AsteroidBelt`, and `Orbit` now own the runtime
|
||||
body/orbit key surfaces consumed by `ActionGameManager` projection, so local
|
||||
body/orbit key formatters may not return there either.
|
||||
- `Aetheria.State.Verify` guards temporary `Faction` shell links: geoname and
|
||||
boss-hull relationships use typed keys, not legacy GUID projection fields.
|
||||
- `Aetheria.State.Verify` guards temporary `Faction` identity: equality,
|
||||
|
|
|
|||
Loading…
Reference in a new issue