Resolve Eve surface pointer refs generically

This commit is contained in:
Meta Vens 2026-06-21 22:56:23 +01:00
commit 857e404f5a
3 changed files with 70 additions and 6 deletions

View file

@ -4329,8 +4329,10 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
!eveUnitySurfaceHost.Contains("CreateDefaultStateRefResolver()", StringComparison.Ordinal) ||
!eveUnitySurfaceHost.Contains("AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver(stateBoot.StateFilePath)", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("public static EveSurfaceDocument ResolveStateRefs(", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("ResolvePropRefs(props, stateRefResolver)", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Source, \"value\", stateRefResolver)", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, \"value\", stateRefResolver)", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("IsStatePointerProp(prop.Key)", StringComparison.Ordinal) ||
!runtimeEveSurfaceAdapter.Contains("ResolvePointerValueKey(refProp.Key)", 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) ||
@ -9771,9 +9773,10 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root)
"public static class AetheriaRuntimeEveSurfaceAdapter",
"public static EveSurfaceDocument ToEveSurfaceDocument(AetheriaRuntimeSurfaceDocument document)",
"public static EveSurfaceDocument ResolveStateRefs(",
"ResolvePropRefs(props, stateRefResolver)",
"ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Source, \"value\", stateRefResolver)",
"ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, \"value\", stateRefResolver)",
"ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Label, \"label\", stateRefResolver)",
"IsStatePointerProp(prop.Key)",
"ResolvePointerValueKey(refProp.Key)",
"public static EveSurfaceDocument EmptySurface(string surfaceId)",
"new EveSurfaceDocument(",
"new EveSurfaceComponent("

View file

@ -406,6 +406,43 @@ public class DaemonRuntimeDocumentTests
AetheriaRuntimeDaemonStateRefs.CurrentTargetName));
}
[Test]
public void EveSurfaceAdapterResolvesTypedPointerPropsBeforeLowering()
{
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"] = "Heat",
["description"] = "stale",
["descriptionRef"] = AetheriaRuntimeDaemonStateRefs.CurrentTargetName,
[AetheriaRuntimeSurfaceStateRefs.Value] = AetheriaRuntimeDaemonStateRefs.CurrentTargetName
},
Array.Empty<EveSurfaceComponent>()),
Array.Empty<EveStyleToken>()),
Array.Empty<EveCommandTemplate>());
var resolved = AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(
surface,
stateRef => stateRef == AetheriaRuntimeDaemonStateRefs.CurrentTargetName ? "Live Target" : "");
Assert.IsTrue(ContainsEveSurfaceProp(resolved.Surface.Root, "description", "Live Target"));
Assert.IsTrue(ContainsEveSurfaceProp(resolved.Surface.Root, "descriptionRef", AetheriaRuntimeDaemonStateRefs.CurrentTargetName));
Assert.IsTrue(ContainsEveSurfaceProp(resolved.Surface.Root, "value", "Live Target"));
Assert.IsTrue(ContainsEveSurfaceProp(resolved.Surface.Root, AetheriaRuntimeSurfaceStateRefs.Value, AetheriaRuntimeDaemonStateRefs.CurrentTargetName));
}
[Test]
public void RuntimeStateReaderResolvesItemStatRefsFromDaemonFrame()
{

View file

@ -100,9 +100,7 @@ namespace GameCult.Aetheria.State.Verse
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);
ResolvePropRefs(props, stateRefResolver);
return new EveSurfaceComponent(
component.Id,
@ -124,6 +122,32 @@ namespace GameCult.Aetheria.State.Verse
return resolved;
}
private static void ResolvePropRefs(
Dictionary<string, string> props,
Func<string, string> stateRefResolver)
{
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Source, "value", stateRefResolver);
var refProps = props
.Where(prop => IsStatePointerProp(prop.Key) &&
!string.Equals(prop.Key, AetheriaRuntimeSurfaceStateRefs.Source, StringComparison.Ordinal) &&
!string.IsNullOrWhiteSpace(prop.Value))
.ToArray();
foreach (var refProp in refProps)
ResolvePropRef(props, refProp.Key, ResolvePointerValueKey(refProp.Key), stateRefResolver);
}
private static bool IsStatePointerProp(string key)
{
return key.EndsWith("Ref", StringComparison.Ordinal);
}
private static string ResolvePointerValueKey(string refKey)
{
return refKey.Substring(0, refKey.Length - "Ref".Length);
}
private static void ResolvePropRef(
Dictionary<string, string> props,
string refKey,