Hydrate Eve state refs through runtime adapter

This commit is contained in:
Meta Vens 2026-06-21 21:02:53 +01:00
commit 017f3e8932
5 changed files with 205 additions and 75 deletions

View file

@ -4122,6 +4122,12 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
"org.gamecult.aetheria.eve-runtime",
"Runtime",
"AetheriaEveUnitySurfaceHost.cs");
var runtimeEveSurfaceAdapterPath = Path.Combine(
root,
"Packages",
"org.gamecult.aetheria.state",
"Runtime",
"AetheriaRuntimeEveSurfaceAdapter.cs");
var cargoItemSurfaceBuilderPath = Path.Combine(
root,
"Packages",
@ -4141,6 +4147,7 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
surfaceDocumentPath,
daemonItemStatQueriesPath,
eveUnitySurfaceHostPath,
runtimeEveSurfaceAdapterPath,
cargoItemSurfaceBuilderPath,
equippedItemSurfaceBuilderPath
};
@ -4160,6 +4167,7 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
var surfaceDocument = File.ReadAllText(surfaceDocumentPath);
var daemonItemStatQueries = File.ReadAllText(daemonItemStatQueriesPath);
var eveUnitySurfaceHost = File.ReadAllText(eveUnitySurfaceHostPath);
var runtimeEveSurfaceAdapter = File.ReadAllText(runtimeEveSurfaceAdapterPath);
var cargoItemSurfaceBuilder = File.ReadAllText(cargoItemSurfaceBuilderPath);
var equippedItemSurfaceBuilder = File.ReadAllText(equippedItemSurfaceBuilderPath);
var requiredSymbols = new[]
@ -4215,9 +4223,10 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
!daemonItemStatQueries.Contains("public static bool TryReadItemStatRef(", StringComparison.Ordinal) ||
!daemonItemStatQueries.Contains("public string ValueRef =>", StringComparison.Ordinal) ||
!eveUnitySurfaceHost.Contains("Func<string, string> stateRefResolver", StringComparison.Ordinal) ||
!eveUnitySurfaceHost.Contains("surface = ResolveStateRefs(surface, stateRefResolver)", StringComparison.Ordinal) ||
!eveUnitySurfaceHost.Contains("ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Source, \"value\", stateRefResolver)", StringComparison.Ordinal) ||
!eveUnitySurfaceHost.Contains("ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, \"value\", stateRefResolver)", StringComparison.Ordinal) ||
!eveUnitySurfaceHost.Contains("AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(surface, stateRefResolver)", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("public static EveSurfaceDocument ResolveStateRefs(", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Source, \"value\", stateRefResolver)", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, \"value\", stateRefResolver)", StringComparison.Ordinal) ||
!cargoItemSurfaceBuilder.Contains("public string ValueRef { get; }", StringComparison.Ordinal) ||
!cargoItemSurfaceBuilder.Contains("props.Add(AetheriaRuntimeSurfaceStateRefs.ValueRef(valueRef))", StringComparison.Ordinal) ||
!equippedItemSurfaceBuilder.Contains("public string ValueRef { get; }", StringComparison.Ordinal) ||
@ -9501,7 +9510,10 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root)
"AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId",
"AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId",
"AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId",
"AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface)",
"ToResolvedEveSurfaceDocument(stateFilePath, surface)",
"ResolveSurfaceStateRefs(stateFilePath, surface)",
"CreateStateRefResolver(string stateFilePath)",
"AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(",
"AetheriaRuntimeEveSurfaceAdapter.EmptySurface(surfaceId)"
};
@ -9532,6 +9544,10 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root)
{
"public static class AetheriaRuntimeEveSurfaceAdapter",
"public static EveSurfaceDocument ToEveSurfaceDocument(AetheriaRuntimeSurfaceDocument document)",
"public static EveSurfaceDocument ResolveStateRefs(",
"ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Source, \"value\", stateRefResolver)",
"ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, \"value\", stateRefResolver)",
"ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Label, \"label\", stateRefResolver)",
"public static EveSurfaceDocument EmptySurface(string surfaceId)",
"new EveSurfaceDocument(",
"new EveSurfaceComponent("

View file

@ -352,6 +352,11 @@ public class DaemonRuntimeDocumentTests
Assert.IsNotNull(genericGameSurface);
Assert.AreEqual(AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId, genericGameSurface.Surface.Id);
Assert.AreEqual(unityGameSurface.ProviderId, genericGameSurface.ProviderId);
Assert.IsTrue(ContainsEveSurfaceMetric(genericGameSurface.Surface.Root, "Target", "Target"));
Assert.IsTrue(ContainsEveSurfaceProp(
genericGameSurface.Surface.Root,
AetheriaRuntimeSurfaceStateRefs.Source,
AetheriaRuntimeDaemonStateRefs.CurrentTargetName));
var genericGameTuiSurface = AetheriaRuntimeStateReader.ReadEveSurface(
statePath,
AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId);
@ -364,6 +369,43 @@ public class DaemonRuntimeDocumentTests
Assert.AreEqual(AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId, genericEditorTuiSurface.Surface.Id);
}
[Test]
public void EveSurfaceAdapterResolvesDaemonStateRefsBeforeLowering()
{
var surface = new EveSurfaceDocument(
"surface-state",
"gamecult.eve.surface.v1",
"aetheria.daemon",
"daemon",
"Daemon",
1,
"",
new EveSurfaceTree(
"aetheria.test.surface",
new EveSurfaceComponent(
"aetheria.test.metric",
"metric",
new Dictionary<string, string>(StringComparer.Ordinal)
{
["label"] = "Target",
["value"] = "stale",
[AetheriaRuntimeSurfaceStateRefs.Source] = AetheriaRuntimeDaemonStateRefs.CurrentTargetName
},
Array.Empty<EveSurfaceComponent>()),
Array.Empty<EveStyleToken>()),
Array.Empty<EveCommandTemplate>());
var resolved = AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(
surface,
stateRef => stateRef == AetheriaRuntimeDaemonStateRefs.CurrentTargetName ? "Live Target" : "");
Assert.IsTrue(ContainsEveSurfaceMetric(resolved.Surface.Root, "Target", "Live Target"));
Assert.IsTrue(ContainsEveSurfaceProp(
resolved.Surface.Root,
AetheriaRuntimeSurfaceStateRefs.Source,
AetheriaRuntimeDaemonStateRefs.CurrentTargetName));
}
[Test]
public void TickRunnerSkipsPreviouslyAccountedObservedCommands()
{
@ -3489,4 +3531,35 @@ public class DaemonRuntimeDocumentTests
return component.Children.Any(child => ContainsSurfaceProp(child, key, value));
}
private static bool ContainsEveSurfaceMetric(
EveSurfaceComponent component,
string label,
string value)
{
if (component.Kind == "metric" &&
component.Props.TryGetValue("label", out var actualLabel) &&
component.Props.TryGetValue("value", out var actualValue) &&
actualLabel == label &&
actualValue == value)
{
return true;
}
return component.Children.Any(child => ContainsEveSurfaceMetric(child, label, value));
}
private static bool ContainsEveSurfaceProp(
EveSurfaceComponent component,
string key,
string value)
{
if (component.Props.TryGetValue(key, out var actual) &&
string.Equals(actual, value, StringComparison.Ordinal))
{
return true;
}
return component.Children.Any(child => ContainsEveSurfaceProp(child, key, value));
}
}

View file

@ -62,7 +62,7 @@ namespace GameCult.Aetheria.EveRuntime
var root = document.rootVisualElement;
ConfigureRoot(root, chrome);
surface = ResolveStateRefs(surface, stateRefResolver);
surface = AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(surface, stateRefResolver);
var lowerer = new EveUiToolkitSurfaceLowerer();
if (chrome.UseShell)
{
@ -189,69 +189,5 @@ namespace GameCult.Aetheria.EveRuntime
return shell;
}
private static EveSurfaceDocument ResolveStateRefs(
EveSurfaceDocument surface,
Func<string, string> stateRefResolver)
{
if (surface == null || stateRefResolver == null)
return surface;
return new EveSurfaceDocument(
surface.Type,
surface.Schema,
surface.ProviderId,
surface.ProviderKind,
surface.Title,
surface.Version,
surface.UpdatedAtUtc,
new EveSurfaceTree(
surface.Surface.Id,
ResolveStateRefs(surface.Surface.Root, stateRefResolver),
surface.Surface.Styles),
surface.Commands);
}
private static EveSurfaceComponent ResolveStateRefs(
EveSurfaceComponent component,
Func<string, string> stateRefResolver)
{
var props = new Dictionary<string, string>(component.Props, StringComparer.Ordinal);
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Source, "value", stateRefResolver);
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, "value", stateRefResolver);
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Label, "label", stateRefResolver);
return new EveSurfaceComponent(
component.Id,
component.Kind,
props,
ResolveStateRefs(component.Children, stateRefResolver));
}
private static IReadOnlyList<EveSurfaceComponent> ResolveStateRefs(
IReadOnlyList<EveSurfaceComponent> children,
Func<string, string> stateRefResolver)
{
if (children == null || children.Count == 0)
return Array.Empty<EveSurfaceComponent>();
var resolved = new EveSurfaceComponent[children.Count];
for (var index = 0; index < children.Count; index++)
resolved[index] = ResolveStateRefs(children[index], stateRefResolver);
return resolved;
}
private static void ResolvePropRef(
Dictionary<string, string> props,
string refKey,
string valueKey,
Func<string, string> stateRefResolver)
{
if (!props.TryGetValue(refKey, out var stateRef) || string.IsNullOrWhiteSpace(stateRef))
return;
var resolved = stateRefResolver(stateRef);
if (!string.IsNullOrWhiteSpace(resolved))
props[valueKey] = resolved;
}
}
}

View file

@ -10,10 +10,17 @@ namespace GameCult.Aetheria.State.Verse
public static class AetheriaRuntimeEveSurfaceAdapter
{
public static EveSurfaceDocument ToEveSurfaceDocument(AetheriaRuntimeSurfaceDocument document)
{
return ToEveSurfaceDocument(document, null);
}
public static EveSurfaceDocument ToEveSurfaceDocument(
AetheriaRuntimeSurfaceDocument document,
Func<string, string>? stateRefResolver)
{
if (document == null) throw new ArgumentNullException(nameof(document));
return new EveSurfaceDocument(
var surface = new EveSurfaceDocument(
"surface-state",
"gamecult.eve.surface.v1",
document.ProviderId,
@ -30,6 +37,31 @@ namespace GameCult.Aetheria.State.Verse
document.Commands
.Select(command => new EveCommandTemplate(command.Command, command.Label, command.Transport))
.ToArray());
return ResolveStateRefs(surface, stateRefResolver);
}
public static EveSurfaceDocument ResolveStateRefs(
EveSurfaceDocument surface,
Func<string, string>? stateRefResolver)
{
if (surface == null) throw new ArgumentNullException(nameof(surface));
if (stateRefResolver == null)
return surface;
return new EveSurfaceDocument(
surface.Type,
surface.Schema,
surface.ProviderId,
surface.ProviderKind,
surface.Title,
surface.Version,
surface.UpdatedAtUtc,
new EveSurfaceTree(
surface.Surface.Id,
ResolveStateRefs(surface.Surface.Root, stateRefResolver),
surface.Surface.Styles),
surface.Commands);
}
public static EveSurfaceDocument EmptySurface(string surfaceId)
@ -62,5 +94,48 @@ namespace GameCult.Aetheria.State.Verse
new Dictionary<string, string>(component.Props, StringComparer.Ordinal),
component.Children.Select(ToEveSurfaceComponent).ToArray());
}
private static EveSurfaceComponent ResolveStateRefs(
EveSurfaceComponent component,
Func<string, string> stateRefResolver)
{
var props = new Dictionary<string, string>(component.Props, StringComparer.Ordinal);
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Source, "value", stateRefResolver);
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, "value", stateRefResolver);
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Label, "label", stateRefResolver);
return new EveSurfaceComponent(
component.Id,
component.Kind,
props,
ResolveStateRefs(component.Children, stateRefResolver));
}
private static IReadOnlyList<EveSurfaceComponent> ResolveStateRefs(
IReadOnlyList<EveSurfaceComponent> children,
Func<string, string> stateRefResolver)
{
if (children == null || children.Count == 0)
return Array.Empty<EveSurfaceComponent>();
var resolved = new EveSurfaceComponent[children.Count];
for (var index = 0; index < children.Count; index++)
resolved[index] = ResolveStateRefs(children[index], stateRefResolver);
return resolved;
}
private static void ResolvePropRef(
Dictionary<string, string> props,
string refKey,
string valueKey,
Func<string, string> stateRefResolver)
{
if (!props.TryGetValue(refKey, out var stateRef) || string.IsNullOrWhiteSpace(stateRef))
return;
var resolved = stateRefResolver(stateRef);
if (!string.IsNullOrWhiteSpace(resolved))
props[valueKey] = resolved;
}
}
}

View file

@ -105,8 +105,9 @@ namespace GameCult.Aetheria.State.Verse
return editorTuiSurface;
}
return AetheriaRuntimeCatalogStore.ReadEveSurfaces(stateFilePath)
var surface = AetheriaRuntimeCatalogStore.ReadEveSurfaces(stateFilePath)
.FirstOrDefault(candidate => string.Equals(candidate.Surface.Id, surfaceId, StringComparison.Ordinal));
return surface == null ? null : ResolveSurfaceStateRefs(stateFilePath, surface);
}
public static string ResolveEveSurfaceStateRef(string stateFilePath, string stateRef)
@ -220,7 +221,7 @@ namespace GameCult.Aetheria.State.Verse
return false;
}
document = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface);
document = ToResolvedEveSurfaceDocument(stateFilePath, surface);
return true;
}
@ -234,7 +235,7 @@ namespace GameCult.Aetheria.State.Verse
return false;
}
document = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface);
document = ToResolvedEveSurfaceDocument(stateFilePath, surface);
return true;
}
@ -248,7 +249,7 @@ namespace GameCult.Aetheria.State.Verse
return false;
}
document = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface);
document = ToResolvedEveSurfaceDocument(stateFilePath, surface);
return true;
}
@ -262,7 +263,7 @@ namespace GameCult.Aetheria.State.Verse
return false;
}
document = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface);
document = ToResolvedEveSurfaceDocument(stateFilePath, surface);
return true;
}
@ -271,6 +272,35 @@ namespace GameCult.Aetheria.State.Verse
return AetheriaRuntimeEveSurfaceAdapter.EmptySurface(surfaceId);
}
private static EveSurfaceDocument ToResolvedEveSurfaceDocument(
string stateFilePath,
AetheriaRuntimeSurfaceDocument surface)
{
return AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(
surface,
CreateStateRefResolver(stateFilePath));
}
private static EveSurfaceDocument ResolveSurfaceStateRefs(
string stateFilePath,
EveSurfaceDocument surface)
{
return AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(
surface,
CreateStateRefResolver(stateFilePath));
}
private static Func<string, string> CreateStateRefResolver(string stateFilePath)
{
TryReadDaemonFrame(stateFilePath, out var frame);
AetheriaRuntimeDaemonPublicationStore.TryReadHealth(stateFilePath, out var health);
AetheriaRuntimeDaemonPublicationStore.TryReadCommandBoundary(stateFilePath, out var commandBoundary);
return stateRef => TryResolveDaemonStateRef(frame, health, commandBoundary, stateRef, out var value)
? value
: "";
}
private static AetheriaRuntimeZoneSnapshotCommit FindCurrentZone(AetheriaRuntimeRunCheckpointCommit run)
{
return run.Zones.FirstOrDefault(zone => zone.ZoneIndex == run.CurrentZoneIndex)