Move zone details projection into runtime
This commit is contained in:
parent
5fc21cd6b1
commit
a6508332ce
3 changed files with 119 additions and 54 deletions
|
|
@ -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<AetheriaRuntimeBodySnapshotCommit>()",
|
||||
"daemonZone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>()",
|
||||
"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",
|
||||
|
|
|
|||
|
|
@ -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<AetheriaRuntimeBodySnapshotCommit>();
|
||||
var entities = daemonZone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>();
|
||||
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<AetheriaRuntimeZoneDetailsBodyProjection> ProjectZoneBodies(
|
||||
AetheriaRuntimeZoneSnapshotCommit daemonZone)
|
||||
{
|
||||
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 ?? "");
|
||||
return typedHull?.HullType ?? "";
|
||||
}
|
||||
|
||||
// private IEnumerator AnimatePath()
|
||||
// {
|
||||
// var pathZones = ActionGameManager.CurrentSector.ExitPath;
|
||||
|
|
|
|||
|
|
@ -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<string> otherFactions,
|
||||
IEnumerable<AetheriaRuntimeZoneDetailsBodyProjection> bodies,
|
||||
IEnumerable<AetheriaRuntimeZoneDetailsEntityProjection> entities,
|
||||
bool hasContents,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
var bodyList = (bodies ?? Array.Empty<AetheriaRuntimeZoneDetailsBodyProjection>())
|
||||
.Where(body => body != null)
|
||||
.ToArray();
|
||||
var entityList = (entities ?? Array.Empty<AetheriaRuntimeZoneDetailsEntityProjection>())
|
||||
.Where(entity => entity != null)
|
||||
.ToArray();
|
||||
|
||||
return new AetheriaRuntimeZoneDetailsSurfaceState(
|
||||
zoneName,
|
||||
ownerName,
|
||||
mass,
|
||||
radius,
|
||||
(otherFactions ?? Array.Empty<string>())
|
||||
.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<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue