Project sector zone details from daemon snapshots
This commit is contained in:
parent
2a8414aa10
commit
3370802cd0
4 changed files with 135 additions and 35 deletions
|
|
@ -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) ||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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<AetheriaRuntimeZoneDetailsBodyProjection> ProjectZoneBodies(
|
||||
AetheriaRuntimeZoneSnapshotCommit daemonZone)
|
||||
private static string ResolveHullType(string hullItemKey)
|
||||
{
|
||||
return (daemonZone?.Bodies ?? Array.Empty<AetheriaRuntimeBodySnapshotCommit>())
|
||||
.Select(body => new AetheriaRuntimeZoneDetailsBodyProjection(body?.Kind ?? ""))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeZoneDetailsEntityProjection> ProjectZoneEntities(
|
||||
AetheriaRuntimeZoneSnapshotCommit daemonZone)
|
||||
{
|
||||
return (daemonZone?.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
|
||||
.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 ?? "";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,11 +75,58 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public string HullType { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeZoneDetailsDaemonProjection
|
||||
{
|
||||
public AetheriaRuntimeZoneDetailsDaemonProjection(
|
||||
double mass,
|
||||
double radius,
|
||||
IReadOnlyList<AetheriaRuntimeZoneDetailsBodyProjection> bodies,
|
||||
IReadOnlyList<AetheriaRuntimeZoneDetailsEntityProjection> entities,
|
||||
bool hasContents)
|
||||
{
|
||||
Mass = mass;
|
||||
Radius = radius;
|
||||
Bodies = bodies ?? Array.Empty<AetheriaRuntimeZoneDetailsBodyProjection>();
|
||||
Entities = entities ?? Array.Empty<AetheriaRuntimeZoneDetailsEntityProjection>();
|
||||
HasContents = hasContents;
|
||||
}
|
||||
|
||||
public double Mass { get; }
|
||||
public double Radius { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeZoneDetailsBodyProjection> Bodies { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeZoneDetailsEntityProjection> 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<string, string> resolveHullType)
|
||||
{
|
||||
if (zone == null)
|
||||
{
|
||||
return new AetheriaRuntimeZoneDetailsDaemonProjection(
|
||||
0,
|
||||
0,
|
||||
Array.Empty<AetheriaRuntimeZoneDetailsBodyProjection>(),
|
||||
Array.Empty<AetheriaRuntimeZoneDetailsEntityProjection>(),
|
||||
false);
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeZoneDetailsDaemonProjection(
|
||||
(zone.Bodies ?? Array.Empty<AetheriaRuntimeBodySnapshotCommit>())
|
||||
.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<AetheriaRuntimeZoneDetailsBodyProjection> ProjectBodies(
|
||||
AetheriaRuntimeZoneSnapshotCommit zone)
|
||||
{
|
||||
return (zone?.Bodies ?? Array.Empty<AetheriaRuntimeBodySnapshotCommit>())
|
||||
.Where(body => body != null)
|
||||
.Select(body => new AetheriaRuntimeZoneDetailsBodyProjection(body.Kind))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeZoneDetailsEntityProjection> ProjectEntities(
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
Func<string, string> resolveHullType)
|
||||
{
|
||||
resolveHullType ??= _ => "";
|
||||
return (zone?.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
|
||||
.Where(entity => entity != null)
|
||||
.Select(entity => new AetheriaRuntimeZoneDetailsEntityProjection(resolveHullType(entity.HullItemKey)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeZoneDetailsSurfaceState state,
|
||||
long version = 1)
|
||||
|
|
|
|||
Loading…
Reference in a new issue