From 15534b730067cf492243a66833e568d7cc985c39 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 21 Jun 2026 21:46:27 +0100 Subject: [PATCH] Resolve Eve daemon state refs automatically --- Aetheria.State.Verify/Program.cs | 7 +++- .../Runtime/AetheriaEveSurfacePresenter.cs | 2 +- .../Runtime/AetheriaEveUnitySurfaceHost.cs | 41 ++++++++++++++++++- .../Runtime/AetheriaRuntimeStateReader.cs | 11 ++++- 4 files changed, 55 insertions(+), 6 deletions(-) diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 17b4d99b8..ca9c94dd4 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -4272,7 +4272,9 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root) !daemonItemStatQueries.Contains("public static bool TryReadItemStatRef(", StringComparison.Ordinal) || !daemonItemStatQueries.Contains("public string ValueRef =>", StringComparison.Ordinal) || !eveUnitySurfaceHost.Contains("Func stateRefResolver", StringComparison.Ordinal) || - !eveUnitySurfaceHost.Contains("AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(surface, stateRefResolver)", StringComparison.Ordinal) || + !eveUnitySurfaceHost.Contains("ContainsStateRefs(surface)", StringComparison.Ordinal) || + !eveUnitySurfaceHost.Contains("CreateDefaultStateRefResolver()", StringComparison.Ordinal) || + !eveUnitySurfaceHost.Contains("AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver(stateBoot.StateFilePath)", 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) || @@ -9616,6 +9618,7 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root) "AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId", "ToResolvedEveSurfaceDocument(stateFilePath, surface)", "ResolveSurfaceStateRefs(stateFilePath, surface)", + "public static Func CreateEveSurfaceStateRefResolver(string stateFilePath)", "CreateStateRefResolver(string stateFilePath)", "AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(", "AetheriaRuntimeEveSurfaceAdapter.EmptySurface(surfaceId)" @@ -9716,7 +9719,7 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root) "Aetheria Eve surface presenter no longer routes provider surface lookup through the shared runtime state reader."); } - if (!eveSurfacePresenter.Contains("AetheriaRuntimeStateReader.ResolveEveSurfaceStateRef(statePath, stateRef)", StringComparison.Ordinal)) + if (!eveSurfacePresenter.Contains("AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver(statePath)", StringComparison.Ordinal)) { throw new InvalidOperationException( "Aetheria Eve surface presenter no longer resolves provider state refs through the shared runtime state reader."); diff --git a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs index 4f9e953eb..a654a8343 100644 --- a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs +++ b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs @@ -159,7 +159,7 @@ namespace GameCult.Aetheria.EveRuntime surface, request => EmitCommand(statePath, request), RootOnlyChrome, - stateRef => AetheriaRuntimeStateReader.ResolveEveSurfaceStateRef(statePath, stateRef)); + AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver(statePath)); _mountedStatePath = statePath; _mountedSurfaceId = surface.Surface.Id; _mountedSurfaceVersion = surface.Version; diff --git a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveUnitySurfaceHost.cs b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveUnitySurfaceHost.cs index f4510d66c..a4c42f443 100644 --- a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveUnitySurfaceHost.cs +++ b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveUnitySurfaceHost.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using GameCult.Aetheria.State.Verse; using GameCult.Eve.Surface; using GameCult.Eve.UnityUIToolkit; @@ -62,7 +63,11 @@ namespace GameCult.Aetheria.EveRuntime var root = document.rootVisualElement; ConfigureRoot(root, chrome); - surface = AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(surface, stateRefResolver); + var effectiveStateRefResolver = stateRefResolver ?? ( + ContainsStateRefs(surface) + ? CreateDefaultStateRefResolver() + : null); + surface = AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs(surface, effectiveStateRefResolver); var lowerer = new EveUiToolkitSurfaceLowerer(); if (chrome.UseShell) { @@ -189,5 +194,39 @@ namespace GameCult.Aetheria.EveRuntime return shell; } + private static bool ContainsStateRefs(EveSurfaceDocument surface) + { + return surface?.Surface?.Root != null && ContainsStateRefs(surface.Surface.Root); + } + + private static bool ContainsStateRefs(EveSurfaceComponent component) + { + if (component.Props != null && + (component.Props.ContainsKey(AetheriaRuntimeSurfaceStateRefs.Source) || + component.Props.ContainsKey(AetheriaRuntimeSurfaceStateRefs.Value) || + component.Props.ContainsKey(AetheriaRuntimeSurfaceStateRefs.Label))) + { + return true; + } + + foreach (var child in component.Children) + { + if (ContainsStateRefs(child)) + return true; + } + + return false; + } + + private static Func CreateDefaultStateRefResolver() + { + var gameDataDirectory = new DirectoryInfo(Path.Combine(Application.dataPath, "..", "GameData")); + var stateBoot = AetheriaRuntimeStateBoot.Inspect(gameDataDirectory, ""); + if (!stateBoot.SupportsLocalStateFileRead || !stateBoot.StateFileExists) + return _ => ""; + + return AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver(stateBoot.StateFilePath); + } + } } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateReader.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateReader.cs index caa9e6bcb..b78b3ff33 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateReader.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeStateReader.cs @@ -272,13 +272,20 @@ namespace GameCult.Aetheria.State.Verse return AetheriaRuntimeEveSurfaceAdapter.EmptySurface(surfaceId); } + public static Func CreateEveSurfaceStateRefResolver(string stateFilePath) + { + return string.IsNullOrWhiteSpace(stateFilePath) + ? _ => "" + : CreateStateRefResolver(stateFilePath); + } + private static EveSurfaceDocument ToResolvedEveSurfaceDocument( string stateFilePath, AetheriaRuntimeSurfaceDocument surface) { return AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument( surface, - CreateStateRefResolver(stateFilePath)); + CreateEveSurfaceStateRefResolver(stateFilePath)); } private static EveSurfaceDocument ResolveSurfaceStateRefs( @@ -287,7 +294,7 @@ namespace GameCult.Aetheria.State.Verse { return AetheriaRuntimeEveSurfaceAdapter.ResolveStateRefs( surface, - CreateStateRefResolver(stateFilePath)); + CreateEveSurfaceStateRefResolver(stateFilePath)); } private static Func CreateStateRefResolver(string stateFilePath)