Centralize Eve state ref resolver construction
This commit is contained in:
parent
c6e75ef4b8
commit
d20d8d684a
2 changed files with 65 additions and 68 deletions
|
|
@ -340,6 +340,50 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return CreateStateRefResolver(stateFilePath, runtimeId);
|
||||
}
|
||||
|
||||
public static CultMeshStateRefResolver CreateEveSurfaceCultMeshStateRefResolver(
|
||||
AetheriaRuntimeDaemonFrameDocument? frame,
|
||||
AetheriaRuntimeDaemonHealthDocument? health,
|
||||
AetheriaRuntimeDaemonCommandBoundaryDocument? commandBoundary,
|
||||
Func<AetheriaRuntimeCatalogSnapshot?>? catalogProvider = null,
|
||||
CultMeshRouteHint? routeHint = null)
|
||||
{
|
||||
AetheriaRuntimeCatalogSnapshot? catalog = null;
|
||||
|
||||
var daemonRefs = CultMesh.StateRefResolver(
|
||||
"aetheria.daemon.refs",
|
||||
(stateRef, _context) => TryResolveDaemonStateRef(frame, health, commandBoundary, stateRef, out var value)
|
||||
? value
|
||||
: "",
|
||||
new[]
|
||||
{
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString()),
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonHealth.ToString()),
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonCommandBoundary.ToString())
|
||||
},
|
||||
routeHint);
|
||||
|
||||
var itemStatRefs = CultMesh.StateRefResolver(
|
||||
"aetheria.daemon.item_stats.refs",
|
||||
(stateRef, _context) =>
|
||||
{
|
||||
if (!stateRef.StartsWith(AetheriaRuntimeDaemonItemStatQueries.StateRefPrefix + "/", StringComparison.Ordinal))
|
||||
return "";
|
||||
|
||||
catalog ??= catalogProvider?.Invoke();
|
||||
return TryResolveDaemonItemStatRef(frame, catalog, stateRef, out var value)
|
||||
? value
|
||||
: "";
|
||||
},
|
||||
new[]
|
||||
{
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString()),
|
||||
CultMesh.ProjectionSource("catalog:aetheria.runtime")
|
||||
},
|
||||
routeHint);
|
||||
|
||||
return daemonRefs.Or(itemStatRefs);
|
||||
}
|
||||
|
||||
private static EveSurfaceDocument ToResolvedEveSurfaceDocument(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeSurfaceDocument surface)
|
||||
|
|
@ -364,34 +408,12 @@ namespace GameCult.Aetheria.State.Verse
|
|||
AetheriaRuntimeDaemonPublicationStore.TryReadHealth(stateFilePath, out var health);
|
||||
AetheriaRuntimeDaemonPublicationStore.TryReadCommandBoundary(stateFilePath, out var commandBoundary);
|
||||
|
||||
var daemonRefs = CultMesh.StateRefResolver(
|
||||
"aetheria.daemon.refs",
|
||||
(stateRef, _context) => TryResolveDaemonStateRef(frame, health, commandBoundary, stateRef, out var value)
|
||||
? value
|
||||
: "",
|
||||
new[]
|
||||
{
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString()),
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonHealth.ToString()),
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonCommandBoundary.ToString())
|
||||
},
|
||||
return CreateEveSurfaceCultMeshStateRefResolver(
|
||||
frame,
|
||||
health,
|
||||
commandBoundary,
|
||||
() => OpenRuntimeCatalog(stateFilePath),
|
||||
new CultMeshRouteHint(CultMeshLocalityKind.InProcess, runtimeId));
|
||||
|
||||
var itemStatRefs = CultMesh.StateRefResolver(
|
||||
"aetheria.daemon.item_stats.refs",
|
||||
(stateRef, _context) =>
|
||||
stateRef.StartsWith(AetheriaRuntimeDaemonItemStatQueries.StateRefPrefix + "/", StringComparison.Ordinal) &&
|
||||
TryResolveDaemonItemStatRef(frame, OpenRuntimeCatalog(stateFilePath), stateRef, out var value)
|
||||
? value
|
||||
: "",
|
||||
new[]
|
||||
{
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString()),
|
||||
CultMesh.ProjectionSource("catalog:aetheria.runtime")
|
||||
},
|
||||
new CultMeshRouteHint(CultMeshLocalityKind.InProcess, runtimeId));
|
||||
|
||||
return daemonRefs.Or(itemStatRefs);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemCommit? FindDaemonItem(
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
typeof(AetheriaRuntimeDaemonCommandBoundaryDocument),
|
||||
typeof(AetheriaRuntimeDaemonFrameDocument),
|
||||
typeof(AetheriaRuntimeDaemonSoaViewDocument),
|
||||
typeof(AetheriaRuntimeAssetManifestDocument),
|
||||
typeof(AetheriaRuntimeObjectsViewportDocument),
|
||||
typeof(AetheriaRuntimeGravityViewportDocument),
|
||||
typeof(AetheriaRuntimeCurrentZoneDocument),
|
||||
|
|
@ -127,6 +128,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeDaemonCommandBoundaryDocument>(registry),
|
||||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeDaemonFrameDocument>(registry),
|
||||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeDaemonSoaViewDocument>(registry),
|
||||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeAssetManifestDocument>(registry),
|
||||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeObjectsViewportDocument>(registry),
|
||||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeGravityViewportDocument>(registry),
|
||||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeCurrentZoneDocument>(registry),
|
||||
|
|
@ -332,52 +334,25 @@ namespace GameCult.Aetheria.State.Verse
|
|||
}
|
||||
|
||||
public CultMeshStateRefResolver CreateEveSurfaceCultMeshStateRefResolver()
|
||||
{
|
||||
return CreateEveSurfaceCultMeshStateRefResolverAsync().ConfigureAwait(false).GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
public async Task<CultMeshStateRefResolver> CreateEveSurfaceCultMeshStateRefResolverAsync()
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
||||
var frame = GetLatestFrameAsync().GetAwaiter().GetResult();
|
||||
var health = GetHealthAsync().GetAwaiter().GetResult();
|
||||
var commandBoundary = GetCommandBoundaryAsync().GetAwaiter().GetResult();
|
||||
AetheriaRuntimeCatalogSnapshot? catalog = null;
|
||||
var frameTask = GetLatestFrameAsync();
|
||||
var healthTask = GetHealthAsync();
|
||||
var commandBoundaryTask = GetCommandBoundaryAsync();
|
||||
|
||||
var daemonRefs = CultMesh.StateRefResolver(
|
||||
"aetheria.daemon.refs",
|
||||
stateRef =>
|
||||
stateRef.StartsWith(AetheriaRuntimeDaemonStateRefs.Prefix + "/", StringComparison.Ordinal) &&
|
||||
AetheriaRuntimeStateReader.TryResolveDaemonStateRef(
|
||||
frame,
|
||||
health,
|
||||
commandBoundary,
|
||||
stateRef,
|
||||
out var daemonValue)
|
||||
? daemonValue
|
||||
: "",
|
||||
new[]
|
||||
{
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString()),
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonHealth.ToString()),
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonCommandBoundary.ToString())
|
||||
});
|
||||
await Task.WhenAll(frameTask, healthTask, commandBoundaryTask).ConfigureAwait(false);
|
||||
|
||||
var itemStatRefs = CultMesh.StateRefResolver(
|
||||
"aetheria.daemon.item_stats.refs",
|
||||
stateRef =>
|
||||
{
|
||||
if (!stateRef.StartsWith(AetheriaRuntimeDaemonItemStatQueries.StateRefPrefix + "/", StringComparison.Ordinal))
|
||||
return "";
|
||||
|
||||
catalog ??= OpenRuntimeCatalog();
|
||||
return AetheriaRuntimeStateReader.TryResolveDaemonItemStatRef(frame, catalog, stateRef, out var itemValue)
|
||||
? itemValue
|
||||
: "";
|
||||
},
|
||||
new[]
|
||||
{
|
||||
CultMesh.ProjectionSource(AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString()),
|
||||
CultMesh.ProjectionSource("catalog:aetheria.runtime")
|
||||
});
|
||||
|
||||
return daemonRefs.Or(itemStatRefs);
|
||||
return AetheriaRuntimeStateReader.CreateEveSurfaceCultMeshStateRefResolver(
|
||||
frameTask.Result,
|
||||
healthTask.Result,
|
||||
commandBoundaryTask.Result,
|
||||
OpenRuntimeCatalog);
|
||||
}
|
||||
|
||||
public async Task<AetheriaRuntimeDaemonFrameDocument?> GetLatestAuthoritativeRunFrameAsync()
|
||||
|
|
|
|||
Loading…
Reference in a new issue