diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 464c81094..b24dcac70 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -3797,13 +3797,10 @@ static void RequireSectorMapZoneDetailsUseEveSurface(string root) "AetheriaEveUnitySurfaceHost.RenderRuntime(", "AetheriaEveUnitySurfaceHost.Hide(_zoneDetailsSurfaceDocument)", "AetheriaRuntimeZoneDetailsSurfaceBuilder.Build(ProjectZoneDetailsSurfaceState(", + "AetheriaRuntimeZoneDetailsSurfaceBuilder.ProjectDaemonZone(", "AetheriaRuntimeZoneDetailsSurfaceBuilder.Project(", "ProjectZoneDetailsSurfaceState(", "GameManager.TryGetObservedZoneSnapshot(zone?.ZoneIndex ?? -1, out var daemonZone)", - "ProjectZoneBodies(", - "ProjectZoneEntities(", - "new AetheriaRuntimeZoneDetailsBodyProjection(", - "new AetheriaRuntimeZoneDetailsEntityProjection(", "AetheriaRuntimeZoneDetailsSurfaceCommands.TryRead(request, out var command)", "AetheriaRuntimeZoneDetailsCommandKind.Close" }; @@ -3839,6 +3836,12 @@ static void RequireSectorMapZoneDetailsUseEveSurface(string root) "Properties.AddProperty(\"Stations\"", "Properties.AddProperty(\"Turrets\"", "Properties.AddProperty(\"Ships\"", + "GameManager.Settings.ZoneSettings.ZoneRadius.Evaluate(", + "GameManager.Settings.ZoneSettings.ZoneMass.Evaluate(", + "ProjectZoneBodies(", + "ProjectZoneEntities(", + "new AetheriaRuntimeZoneDetailsBodyProjection(", + "new AetheriaRuntimeZoneDetailsEntityProjection(", "runtimeZone.PlanetInstances", "runtimeZone.AsteroidBelts", "runtimeZone.Entities", @@ -3863,8 +3866,12 @@ static void RequireSectorMapZoneDetailsUseEveSurface(string root) var requiredBuilderSymbols = new[] { "public static class AetheriaRuntimeZoneDetailsSurfaceBuilder", + "public sealed class AetheriaRuntimeZoneDetailsDaemonProjection", "public sealed class AetheriaRuntimeZoneDetailsBodyProjection", "public sealed class AetheriaRuntimeZoneDetailsEntityProjection", + "public static AetheriaRuntimeZoneDetailsDaemonProjection ProjectDaemonZone(", + "Math.Max(0, zone.GravityTerrainRadius)", + ".Sum(body => body.Mass)", "public static AetheriaRuntimeZoneDetailsSurfaceState Project(", "private static bool IsBodyKind(", "private static bool IsPlanetBody(", @@ -8699,10 +8706,10 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root) !mapRenderer.Contains("GameManager.TryGetObservedRunZone(out var currentZone)", StringComparison.Ordinal) || !sectorRenderer.Contains("GameManager.TryGetObservedRunZone(out var currentZone)", StringComparison.Ordinal) || !sectorMap.Contains("ActionGameManager.TryGetObservedGalaxy(out var observedGalaxy)", StringComparison.Ordinal) || - !sectorRenderer.Contains("ActionGameManager.TryGetObservedGalaxy(out var observedGalaxy)", StringComparison.Ordinal)) + !sectorRenderer.Contains("AetheriaRuntimeZoneDetailsSurfaceBuilder.ProjectDaemonZone(", StringComparison.Ordinal)) { throw new InvalidOperationException( - "Map and sector UI must request projected galaxy data through an explicit observed-galaxy boundary."); + "Map and sector UI must request projected galaxy/zone data through explicit observed daemon boundaries."); } if (sectorMap.Contains("ActionGameManager.ObservedGalaxy", StringComparison.Ordinal) || diff --git a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs index 2a2e4ad38..420167e9b 100644 --- a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs +++ b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs @@ -929,6 +929,50 @@ public class DaemonRuntimeDocumentTests Assert.AreEqual(11.75, band.DepthRange, 0.0001); } + [Test] + public void ZoneDetailsProjectionReadsMassRadiusAndContentsFromDaemonZone() + { + var zone = new AetheriaRuntimeZoneSnapshotCommit + { + Name = "Tir Na Nog", + GravityTerrainRadius = 420, + Bodies = new[] + { + new AetheriaRuntimeBodySnapshotCommit { Kind = "planet", Mass = 10 }, + new AetheriaRuntimeBodySnapshotCommit { Kind = "gas_giant", Mass = 30 }, + new AetheriaRuntimeBodySnapshotCommit { Kind = "asteroid_belt" } + }, + Entities = new[] + { + new AetheriaRuntimeEntitySnapshotCommit { HullItemKey = "station-hull" }, + new AetheriaRuntimeEntitySnapshotCommit { HullItemKey = "ship-hull" } + } + }; + + var projection = AetheriaRuntimeZoneDetailsSurfaceBuilder.ProjectDaemonZone( + zone, + key => key == "station-hull" ? "Station" : "Ship"); + var state = AetheriaRuntimeZoneDetailsSurfaceBuilder.Project( + zone.Name, + "GameCult", + projection.Mass.ToString("0"), + projection.Radius.ToString("0"), + new[] { "A", "B" }, + projection.Bodies, + projection.Entities, + projection.HasContents, + ""); + + Assert.AreEqual(40, projection.Mass, 0.0001); + Assert.AreEqual(420, projection.Radius, 0.0001); + Assert.IsTrue(projection.HasContents); + Assert.AreEqual("1", state.Planets); + Assert.AreEqual("1", state.GasGiants); + Assert.AreEqual("1", state.AsteroidBelts); + Assert.AreEqual("1", state.Stations); + Assert.AreEqual("1", state.Ships); + } + [Test] public void DaemonRenderQueriesPublishBodyPosesFromZoneSnapshot() { diff --git a/Assets/Scripts/UI/Menu/SectorRenderer.cs b/Assets/Scripts/UI/Menu/SectorRenderer.cs index 92413f535..38b880760 100644 --- a/Assets/Scripts/UI/Menu/SectorRenderer.cs +++ b/Assets/Scripts/UI/Menu/SectorRenderer.cs @@ -122,11 +122,6 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS private AetheriaRuntimeZoneDetailsSurfaceState ProjectZoneDetailsSurfaceState(GalaxyZone zone) { - var density = ActionGameManager.TryGetObservedGalaxy(out var observedGalaxy) - ? saturate(observedGalaxy.Background.CloudDensity(zone.Position) / 2) - : 0f; - var radius = GameManager.Settings.ZoneSettings.ZoneRadius.Evaluate(density); - var mass = GameManager.Settings.ZoneSettings.ZoneMass.Evaluate(density); var otherFactions = zone.Factions .Where(faction => !faction.HasSameKey(zone.Owner)) .Select(faction => faction.Name) @@ -135,37 +130,24 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS var hasContents = GameManager != null && GameManager.TryGetObservedZoneSnapshot(zone?.ZoneIndex ?? -1, out var daemonZone); + var daemonProjection = AetheriaRuntimeZoneDetailsSurfaceBuilder.ProjectDaemonZone( + hasContents ? daemonZone : null, + ResolveHullType); return AetheriaRuntimeZoneDetailsSurfaceBuilder.Project( - zone.Name, + string.IsNullOrWhiteSpace(daemonZone?.Name) ? zone.Name : daemonZone.Name, zone.Owner?.Name ?? "None", - ActionGameManager.RuntimePlayerSettings.Format(mass), - ActionGameManager.RuntimePlayerSettings.Format(radius), + ActionGameManager.RuntimePlayerSettings.Format(daemonProjection.Mass), + ActionGameManager.RuntimePlayerSettings.Format(daemonProjection.Radius), otherFactions, - ProjectZoneBodies(hasContents ? daemonZone : null), - ProjectZoneEntities(hasContents ? daemonZone : null), - hasContents, + daemonProjection.Bodies, + daemonProjection.Entities, + daemonProjection.HasContents, updatedAtUtc: DateTime.UtcNow.ToString("O")); } - private static IReadOnlyList ProjectZoneBodies( - AetheriaRuntimeZoneSnapshotCommit daemonZone) + private static string ResolveHullType(string hullItemKey) { - return (daemonZone?.Bodies ?? Array.Empty()) - .Select(body => new AetheriaRuntimeZoneDetailsBodyProjection(body?.Kind ?? "")) - .ToArray(); - } - - private static IReadOnlyList ProjectZoneEntities( - AetheriaRuntimeZoneSnapshotCommit daemonZone) - { - return (daemonZone?.Entities ?? Array.Empty()) - .Select(entity => new AetheriaRuntimeZoneDetailsEntityProjection(ResolveHullType(entity))) - .ToArray(); - } - - private static string ResolveHullType(AetheriaRuntimeEntitySnapshotCommit entity) - { - var typedHull = ActionGameManager.RuntimeCatalog?.FindItem(entity?.HullItemKey ?? ""); + var typedHull = ActionGameManager.RuntimeCatalog?.FindItem(hullItemKey ?? ""); return typedHull?.HullType ?? ""; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeZoneDetailsSurfaceBuilder.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeZoneDetailsSurfaceBuilder.cs index 36334f0b4..180d06ee5 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeZoneDetailsSurfaceBuilder.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeZoneDetailsSurfaceBuilder.cs @@ -75,11 +75,58 @@ namespace GameCult.Aetheria.State.Verse public string HullType { get; } } + public sealed class AetheriaRuntimeZoneDetailsDaemonProjection + { + public AetheriaRuntimeZoneDetailsDaemonProjection( + double mass, + double radius, + IReadOnlyList bodies, + IReadOnlyList entities, + bool hasContents) + { + Mass = mass; + Radius = radius; + Bodies = bodies ?? Array.Empty(); + Entities = entities ?? Array.Empty(); + HasContents = hasContents; + } + + public double Mass { get; } + public double Radius { get; } + public IReadOnlyList Bodies { get; } + public IReadOnlyList Entities { get; } + public bool HasContents { get; } + } + public static class AetheriaRuntimeZoneDetailsSurfaceBuilder { public const string SurfaceId = "aetheria.sector_map.zone_details"; public const string Close = "aetheria.sector_map.zone_details.close"; + public static AetheriaRuntimeZoneDetailsDaemonProjection ProjectDaemonZone( + AetheriaRuntimeZoneSnapshotCommit zone, + Func resolveHullType) + { + if (zone == null) + { + return new AetheriaRuntimeZoneDetailsDaemonProjection( + 0, + 0, + Array.Empty(), + Array.Empty(), + false); + } + + return new AetheriaRuntimeZoneDetailsDaemonProjection( + (zone.Bodies ?? Array.Empty()) + .Where(body => body != null) + .Sum(body => body.Mass), + Math.Max(0, zone.GravityTerrainRadius), + ProjectBodies(zone), + ProjectEntities(zone, resolveHullType), + true); + } + public static AetheriaRuntimeZoneDetailsSurfaceState Project( string zoneName, string ownerName, @@ -118,6 +165,26 @@ namespace GameCult.Aetheria.State.Verse updatedAtUtc); } + private static IReadOnlyList ProjectBodies( + AetheriaRuntimeZoneSnapshotCommit zone) + { + return (zone?.Bodies ?? Array.Empty()) + .Where(body => body != null) + .Select(body => new AetheriaRuntimeZoneDetailsBodyProjection(body.Kind)) + .ToArray(); + } + + private static IReadOnlyList ProjectEntities( + AetheriaRuntimeZoneSnapshotCommit zone, + Func resolveHullType) + { + resolveHullType ??= _ => ""; + return (zone?.Entities ?? Array.Empty()) + .Where(entity => entity != null) + .Select(entity => new AetheriaRuntimeZoneDetailsEntityProjection(resolveHullType(entity.HullItemKey))) + .ToArray(); + } + public static AetheriaRuntimeSurfaceDocument Build( AetheriaRuntimeZoneDetailsSurfaceState state, long version = 1)