From a6508332cebcfaf20300e1b5a0d5d79984b1dda2 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 21 Jun 2026 22:00:17 +0100 Subject: [PATCH] Move zone details projection into runtime --- Aetheria.State.Verify/Program.cs | 18 ++++- Assets/Scripts/UI/Menu/SectorRenderer.cs | 79 +++++++------------ ...etheriaRuntimeZoneDetailsSurfaceBuilder.cs | 76 ++++++++++++++++++ 3 files changed, 119 insertions(+), 54 deletions(-) diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 37c68b555..98ec3d775 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -3782,11 +3782,13 @@ static void RequireSectorMapZoneDetailsUseEveSurface(string root) "AetheriaEveUnitySurfaceHost.RenderRuntime(", "AetheriaEveUnitySurfaceHost.Hide(_zoneDetailsSurfaceDocument)", "AetheriaRuntimeZoneDetailsSurfaceBuilder.Build(ProjectZoneDetailsSurfaceState(", + "AetheriaRuntimeZoneDetailsSurfaceBuilder.Project(", "ProjectZoneDetailsSurfaceState(", "GameManager.TryGetObservedZoneSnapshot(zone?.ZoneIndex ?? -1, out var daemonZone)", - "daemonZone.Bodies ?? Array.Empty()", - "daemonZone.Entities ?? Array.Empty()", - "typedHull.HullType", + "ProjectZoneBodies(", + "ProjectZoneEntities(", + "new AetheriaRuntimeZoneDetailsBodyProjection(", + "new AetheriaRuntimeZoneDetailsEntityProjection(", "AetheriaRuntimeZoneDetailsSurfaceCommands.TryRead(request, out var command)", "AetheriaRuntimeZoneDetailsCommandKind.Close" }; @@ -3825,6 +3827,10 @@ static void RequireSectorMapZoneDetailsUseEveSurface(string root) "runtimeZone.PlanetInstances", "runtimeZone.AsteroidBelts", "runtimeZone.Entities", + "new AetheriaRuntimeZoneDetailsSurfaceState(", + "private static bool IsBodyKind(", + "private static bool IsPlanetBody(", + "private static bool HasHullType(", "string.Equals(request.Command, AetheriaRuntimeZoneDetailsSurfaceBuilder.Close" }; @@ -3842,6 +3848,12 @@ static void RequireSectorMapZoneDetailsUseEveSurface(string root) var requiredBuilderSymbols = new[] { "public static class AetheriaRuntimeZoneDetailsSurfaceBuilder", + "public sealed class AetheriaRuntimeZoneDetailsBodyProjection", + "public sealed class AetheriaRuntimeZoneDetailsEntityProjection", + "public static AetheriaRuntimeZoneDetailsSurfaceState Project(", + "private static bool IsBodyKind(", + "private static bool IsPlanetBody(", + "private static bool HasHullType(", "public const string SurfaceId = \"aetheria.sector_map.zone_details\"", "public const string Close = \"aetheria.sector_map.zone_details.close\"", "public enum AetheriaRuntimeZoneDetailsCommandKind", diff --git a/Assets/Scripts/UI/Menu/SectorRenderer.cs b/Assets/Scripts/UI/Menu/SectorRenderer.cs index 59dbae810..92413f535 100644 --- a/Assets/Scripts/UI/Menu/SectorRenderer.cs +++ b/Assets/Scripts/UI/Menu/SectorRenderer.cs @@ -84,26 +84,6 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS // }); } - private static bool IsBodyKind(AetheriaRuntimeBodySnapshotCommit body, string kind) - { - return body != null && string.Equals(body.Kind ?? "", kind, StringComparison.OrdinalIgnoreCase); - } - - private static bool IsPlanetBody(AetheriaRuntimeBodySnapshotCommit body) - { - return body != null && - !IsBodyKind(body, "asteroid_belt") && - !IsBodyKind(body, "gas_giant") && - !IsBodyKind(body, "sun"); - } - - private static bool HasHullType(AetheriaRuntimeEntitySnapshotCommit entity, HullType hullType) - { - var typedHull = ActionGameManager.RuntimeCatalog?.FindItem(entity?.HullItemKey ?? ""); - return typedHull != null && - string.Equals(typedHull.HullType, hullType.ToString(), StringComparison.Ordinal); - } - private void RenderZoneDetailsSurface(GalaxyZone zone) { _zoneDetailsSurfaceDocument = AetheriaEveUnitySurfaceHost.RenderRuntime( @@ -153,45 +133,42 @@ public class SectorRenderer : MonoBehaviour, IBeginDragHandler, IDragHandler, IS .Where(name => !string.IsNullOrWhiteSpace(name)) .ToArray(); - if (GameManager == null || - !GameManager.TryGetObservedZoneSnapshot(zone?.ZoneIndex ?? -1, out var daemonZone)) - { - return new AetheriaRuntimeZoneDetailsSurfaceState( - zone.Name, - zone.Owner?.Name ?? "None", - ActionGameManager.RuntimePlayerSettings.Format(mass), - ActionGameManager.RuntimePlayerSettings.Format(radius), - otherFactions, - hasContents: false, - planets: "", - asteroidBelts: "", - gasGiants: "", - stars: "", - stations: "", - turrets: "", - ships: "", - updatedAtUtc: DateTime.UtcNow.ToString("O")); - } - - var bodies = daemonZone.Bodies ?? Array.Empty(); - var entities = daemonZone.Entities ?? Array.Empty(); - return new AetheriaRuntimeZoneDetailsSurfaceState( + var hasContents = GameManager != null && + GameManager.TryGetObservedZoneSnapshot(zone?.ZoneIndex ?? -1, out var daemonZone); + return AetheriaRuntimeZoneDetailsSurfaceBuilder.Project( zone.Name, zone.Owner?.Name ?? "None", ActionGameManager.RuntimePlayerSettings.Format(mass), ActionGameManager.RuntimePlayerSettings.Format(radius), otherFactions, - hasContents: true, - planets: bodies.Count(IsPlanetBody).ToString(), - asteroidBelts: bodies.Count(body => IsBodyKind(body, "asteroid_belt")).ToString(), - gasGiants: bodies.Count(body => IsBodyKind(body, "gas_giant")).ToString(), - stars: bodies.Count(body => IsBodyKind(body, "sun")).ToString(), - stations: entities.Count(entity => HasHullType(entity, HullType.Station)).ToString(), - turrets: entities.Count(entity => HasHullType(entity, HullType.Turret)).ToString(), - ships: entities.Count(entity => HasHullType(entity, HullType.Ship)).ToString(), + ProjectZoneBodies(hasContents ? daemonZone : null), + ProjectZoneEntities(hasContents ? daemonZone : null), + hasContents, updatedAtUtc: DateTime.UtcNow.ToString("O")); } + private static IReadOnlyList ProjectZoneBodies( + AetheriaRuntimeZoneSnapshotCommit daemonZone) + { + 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 ?? ""); + return typedHull?.HullType ?? ""; + } + // private IEnumerator AnimatePath() // { // var pathZones = ActionGameManager.CurrentSector.ExitPath; diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeZoneDetailsSurfaceBuilder.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeZoneDetailsSurfaceBuilder.cs index baa211bd4..36334f0b4 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeZoneDetailsSurfaceBuilder.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeZoneDetailsSurfaceBuilder.cs @@ -55,11 +55,69 @@ namespace GameCult.Aetheria.State.Verse public string UpdatedAtUtc { get; } } + public sealed class AetheriaRuntimeZoneDetailsBodyProjection + { + public AetheriaRuntimeZoneDetailsBodyProjection(string kind) + { + Kind = kind ?? ""; + } + + public string Kind { get; } + } + + public sealed class AetheriaRuntimeZoneDetailsEntityProjection + { + public AetheriaRuntimeZoneDetailsEntityProjection(string hullType) + { + HullType = hullType ?? ""; + } + + public string HullType { 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 AetheriaRuntimeZoneDetailsSurfaceState Project( + string zoneName, + string ownerName, + string mass, + string radius, + IEnumerable otherFactions, + IEnumerable bodies, + IEnumerable entities, + bool hasContents, + string updatedAtUtc) + { + var bodyList = (bodies ?? Array.Empty()) + .Where(body => body != null) + .ToArray(); + var entityList = (entities ?? Array.Empty()) + .Where(entity => entity != null) + .ToArray(); + + return new AetheriaRuntimeZoneDetailsSurfaceState( + zoneName, + ownerName, + mass, + radius, + (otherFactions ?? Array.Empty()) + .Where(name => !string.IsNullOrWhiteSpace(name)) + .OrderBy(name => name, StringComparer.Ordinal) + .ToArray(), + hasContents, + bodyList.Count(IsPlanetBody).ToString(), + bodyList.Count(body => IsBodyKind(body, "asteroid_belt")).ToString(), + bodyList.Count(body => IsBodyKind(body, "gas_giant")).ToString(), + bodyList.Count(body => IsBodyKind(body, "sun")).ToString(), + entityList.Count(entity => HasHullType(entity, "Station")).ToString(), + entityList.Count(entity => HasHullType(entity, "Turret")).ToString(), + entityList.Count(entity => HasHullType(entity, "Ship")).ToString(), + updatedAtUtc); + } + public static AetheriaRuntimeSurfaceDocument Build( AetheriaRuntimeZoneDetailsSurfaceState state, long version = 1) @@ -184,6 +242,24 @@ namespace GameCult.Aetheria.State.Verse .ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal), children ?? Array.Empty()); } + + private static bool IsBodyKind(AetheriaRuntimeZoneDetailsBodyProjection body, string kind) + { + return body != null && string.Equals(body.Kind ?? "", kind, StringComparison.OrdinalIgnoreCase); + } + + private static bool IsPlanetBody(AetheriaRuntimeZoneDetailsBodyProjection body) + { + return body != null && + !IsBodyKind(body, "asteroid_belt") && + !IsBodyKind(body, "gas_giant") && + !IsBodyKind(body, "sun"); + } + + private static bool HasHullType(AetheriaRuntimeZoneDetailsEntityProjection entity, string hullType) + { + return entity != null && string.Equals(entity.HullType ?? "", hullType, StringComparison.Ordinal); + } } public enum AetheriaRuntimeZoneDetailsCommandKind