From c22d104812540a662779925c075336eeba53e14f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Mon, 22 Jun 2026 14:08:25 +0100 Subject: [PATCH] Move daemon operation facade into runtime client --- Aetheria.State.Verify/Program.cs | 50 ++++++++++++---- .../Gameplay/AetheriaDaemonObserver.cs | 5 +- GameCult.Aetheria.State.Unity.csproj | 1 + .../Runtime/AetheriaEveSurfacePresenter.cs | 58 ++++++++++++++++++- .../AetheriaRuntimeDaemonOperationsClient.cs | 15 +++-- .../AetheriaRuntimeEveSurfaceAdapter.cs | 45 ++++++++++++++ 6 files changed, 154 insertions(+), 20 deletions(-) rename Assets/Scripts/Gameplay/AetheriaDaemonOperations.cs => Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs (94%) diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 2ffd6e293..f7dd9a47d 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -2879,8 +2879,15 @@ static void RequireEveRuntimeBootstrap(string root) var requiredPresenterSymbols = new[] { "private string surfaceId = AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId", - "AetheriaRuntimeStateReader.ReadEveSurface(statePath, surfaceId)", - "AetheriaRuntimeStateReader.ReadEveSurface(stateBoot.StateFilePath, surfaceId)", + "private AetheriaRuntimeVerseClient? _verseClient", + "ReadDaemonSurface(statePath)", + "ReadDaemonSurface(stateBoot.StateFilePath)", + "AetheriaRuntimeVerseClient.OpenAsync(", + "GetDaemonGameSurfaceAsync()", + "GetDaemonGameTuiSurfaceAsync()", + "GetDaemonEditorSurfaceAsync()", + "GetDaemonEditorTuiSurfaceAsync()", + "AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(", "private bool ShouldMountSurface(", "_mountedSurfaceVersion != surface.Version", "private static readonly AetheriaEveUnitySurfaceChrome RootOnlyChrome", @@ -2900,6 +2907,12 @@ static void RequireEveRuntimeBootstrap(string root) string.Join(", ", missingPresenterSymbols)); } + if (presenter.Contains("AetheriaRuntimeStateReader.ReadEveSurface", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "Aetheria Eve presenter still mounts daemon surfaces through file-reader lookup instead of AetheriaRuntimeVerseClient."); + } + if (presenter.Contains("new EveUiToolkitSurfaceLowerer", StringComparison.Ordinal)) { throw new InvalidOperationException( @@ -7194,8 +7207,18 @@ static void RequireTypedDaemonCommandPayloads(string root) "command.EquipmentTransfer.SourceKind", "command.StoreItem.SourceEquipmentIndex" }; - var daemonOperationsUnity = File.ReadAllText(Path.Combine(root, "Assets", "Scripts", "Gameplay", "AetheriaDaemonOperations.cs")); - var clientAndObserver = daemonClient + "\n" + observer + "\n" + stateNode + "\n" + daemonOperationsUnity; + var daemonOperationsClientPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonOperationsClient.cs"); + var daemonOperationsClient = File.Exists(daemonOperationsClientPath) + ? File.ReadAllText(daemonOperationsClientPath) + : throw new InvalidOperationException("Shared daemon operations client is missing from the runtime package."); + var legacyUnityOperationsPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "AetheriaDaemonOperations.cs"); + if (File.Exists(legacyUnityOperationsPath)) + { + throw new InvalidOperationException( + "Aetheria daemon operation facade still lives under Unity gameplay; move shared client operations into the runtime package."); + } + + var clientAndObserver = daemonClient + "\n" + observer + "\n" + stateNode + "\n" + daemonOperationsClient; var missingClientSymbols = requiredClientSymbols .Where(symbol => !clientAndObserver.Contains(symbol, StringComparison.Ordinal)) .ToArray(); @@ -7260,8 +7283,7 @@ static void RequireTypedDaemonCommandPayloads(string root) }; var unityDocumentSubmitHits = new Dictionary { - ["Unity daemon observer"] = observer, - ["Unity daemon operations"] = daemonOperationsUnity + ["Unity daemon observer"] = observer } .SelectMany(source => forbiddenUnityDocumentSubmitSymbols .Where(symbol => source.Value.Contains(symbol, StringComparison.Ordinal)) @@ -8957,7 +8979,8 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root) var daemonRuntimeOperationsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonOperations.cs"); var daemonIntentPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonIntentState.cs"); var daemonObserverPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "AetheriaDaemonObserver.cs"); - var daemonGameplayOperationsPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "AetheriaDaemonOperations.cs"); + var daemonGameplayOperationsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonOperationsClient.cs"); + var legacyDaemonGameplayOperationsPath = Path.Combine(root, "Assets", "Scripts", "Gameplay", "AetheriaDaemonOperations.cs"); var actionGameManager = File.Exists(actionGameManagerPath) ? File.ReadAllText(actionGameManagerPath) : throw new InvalidOperationException("Cannot verify Unity observer authority; ActionGameManager.cs is missing."); @@ -8984,7 +9007,13 @@ static void RequireUnityObserverDoesNotTickLocalSimulation(string root) : throw new InvalidOperationException("Cannot verify Unity observer authority; AetheriaDaemonObserver.cs is missing."); var daemonOperations = File.Exists(daemonGameplayOperationsPath) ? File.ReadAllText(daemonGameplayOperationsPath) - : throw new InvalidOperationException("Cannot verify Unity observer authority; AetheriaDaemonOperations.cs is missing."); + : throw new InvalidOperationException("Cannot verify Unity observer authority; shared daemon operations client is missing."); + + if (File.Exists(legacyDaemonGameplayOperationsPath)) + { + throw new InvalidOperationException( + "Unity gameplay still owns AetheriaDaemonOperations; shared daemon operation access belongs in the runtime package."); + } var forbiddenGameplaySymbols = new[] { @@ -10305,10 +10334,11 @@ static void RequireRuntimeStateReaderOwnsUnityStateAcquisition(string root) "MainMenu no longer routes daemon-frame lookup through the shared runtime state reader."); } - if (!eveSurfacePresenter.Contains("AetheriaRuntimeStateReader.ReadEveSurface", StringComparison.Ordinal)) + if (!eveSurfacePresenter.Contains("AetheriaRuntimeVerseClient.OpenAsync(", StringComparison.Ordinal) || + !eveSurfacePresenter.Contains("ReadDaemonSurface(statePath)", StringComparison.Ordinal)) { throw new InvalidOperationException( - "Aetheria Eve surface presenter no longer routes provider surface lookup through the shared runtime state reader."); + "Aetheria Eve surface presenter no longer routes daemon surface lookup through the shared runtime Verse client."); } if (!eveSurfacePresenter.Contains("AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver(statePath)", StringComparison.Ordinal)) diff --git a/Assets/Scripts/Gameplay/AetheriaDaemonObserver.cs b/Assets/Scripts/Gameplay/AetheriaDaemonObserver.cs index e8cb98d66..ce83a7183 100644 --- a/Assets/Scripts/Gameplay/AetheriaDaemonObserver.cs +++ b/Assets/Scripts/Gameplay/AetheriaDaemonObserver.cs @@ -19,7 +19,7 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour private readonly AetheriaRuntimeDaemonObservationCursor _cursor = new AetheriaRuntimeDaemonObservationCursor(); private float _nextPollTime; private AetheriaRuntimeDaemonOperationClient _operationClient; - private AetheriaDaemonOperations _operations; + private AetheriaRuntimeDaemonOperationsClient _operations; private AetheriaDaemonSoaMemoryMap _soaMemoryMap; private AetheriaDaemonRenderNativeView _renderNativeView; @@ -34,7 +34,8 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour public AetheriaDaemonSoaMemoryMap LastSoaMemoryMap => _soaMemoryMap; public AetheriaDaemonRenderNativeView LastRenderNativeView => _renderNativeView; public bool HasRenderNativeView => _renderNativeView.IsCreated; - public AetheriaDaemonOperations Operations => _operations ??= new AetheriaDaemonOperations(this); + public AetheriaRuntimeDaemonOperationsClient Operations => + _operations ??= new AetheriaRuntimeDaemonOperationsClient(SendOperation); public event Action ObservedDaemonStateChanged; diff --git a/GameCult.Aetheria.State.Unity.csproj b/GameCult.Aetheria.State.Unity.csproj index 19c1f1f17..582a77c5d 100644 --- a/GameCult.Aetheria.State.Unity.csproj +++ b/GameCult.Aetheria.State.Unity.csproj @@ -91,6 +91,7 @@ + diff --git a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs index a654a8343..7229d7367 100644 --- a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs +++ b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs @@ -29,6 +29,8 @@ namespace GameCult.Aetheria.EveRuntime private float refreshIntervalSeconds = 0.1f; private UIDocument? _document; + private AetheriaRuntimeVerseClient? _verseClient; + private string _verseClientStatePath = ""; private float _nextRefreshTime; private string _mountedStatePath = ""; private string _mountedSurfaceId = ""; @@ -81,7 +83,7 @@ namespace GameCult.Aetheria.EveRuntime return; } - var surface = AetheriaRuntimeStateReader.ReadEveSurface(statePath, surfaceId); + var surface = ReadDaemonSurface(statePath); if (surface == null) { root.Add(BuildError($"Eve surface not found: {surfaceId}")); @@ -112,13 +114,58 @@ namespace GameCult.Aetheria.EveRuntime if (!stateBoot.SupportsLocalStateFileRead || !stateBoot.StateFileExists) return; - var surface = AetheriaRuntimeStateReader.ReadEveSurface(stateBoot.StateFilePath, surfaceId); + var surface = ReadDaemonSurface(stateBoot.StateFilePath); if (surface == null || !ShouldMountSurface(stateBoot.StateFilePath, surface)) return; MountSurface(stateBoot.StateFilePath, surface); } + private EveSurfaceDocument? ReadDaemonSurface(string statePath) + { + var client = ResolveVerseClient(statePath); + var surface = ReadDaemonSurfaceState(client); + return surface == null + ? null + : AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument( + surface, + AetheriaRuntimeStateReader.CreateEveSurfaceStateRefResolver(statePath)); + } + + private global::Aetheria.State.Documents.EveSurfaceState? ReadDaemonSurfaceState(AetheriaRuntimeVerseClient client) + { + if (string.Equals(surfaceId, AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId, StringComparison.Ordinal)) + return client.GetDaemonGameSurfaceAsync().GetAwaiter().GetResult(); + + if (string.Equals(surfaceId, AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId, StringComparison.Ordinal)) + return client.GetDaemonGameTuiSurfaceAsync().GetAwaiter().GetResult(); + + if (string.Equals(surfaceId, AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId, StringComparison.Ordinal)) + return client.GetDaemonEditorSurfaceAsync().GetAwaiter().GetResult(); + + if (string.Equals(surfaceId, AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId, StringComparison.Ordinal)) + return client.GetDaemonEditorTuiSurfaceAsync().GetAwaiter().GetResult(); + + return null; + } + + private AetheriaRuntimeVerseClient ResolveVerseClient(string statePath) + { + if (_verseClient != null && string.Equals(_verseClientStatePath, statePath, StringComparison.Ordinal)) + return _verseClient; + + _verseClient?.Dispose(); + _verseClientStatePath = statePath ?? ""; + _verseClient = AetheriaRuntimeVerseClient.OpenAsync( + _verseClientStatePath, + "unity-eve-surface-presenter", + startServer: false, + pullOnOpen: true) + .GetAwaiter() + .GetResult(); + return _verseClient; + } + private UIDocument ResolveDocument() { if (_document == null) @@ -190,5 +237,12 @@ namespace GameCult.Aetheria.EveRuntime Debug.Log( $"Submitted Eve command for CultMesh bridge: {envelope!.ProviderId}/{envelope.SurfaceId}/{envelope.Command} {envelope.CommandId}"); } + + private void OnDisable() + { + _verseClient?.Dispose(); + _verseClient = null; + _verseClientStatePath = ""; + } } } diff --git a/Assets/Scripts/Gameplay/AetheriaDaemonOperations.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs similarity index 94% rename from Assets/Scripts/Gameplay/AetheriaDaemonOperations.cs rename to Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs index 750bda4c6..f4de954b1 100644 --- a/Assets/Scripts/Gameplay/AetheriaDaemonOperations.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperationsClient.cs @@ -1,13 +1,15 @@ using System; -using GameCult.Aetheria.State.Verse; -public sealed class AetheriaDaemonOperations +namespace GameCult.Aetheria.State.Verse { - private readonly AetheriaDaemonObserver _observer; +public sealed class AetheriaRuntimeDaemonOperationsClient +{ + private readonly Func, AetheriaRuntimeDaemonCommandEnvelope> _submit; - internal AetheriaDaemonOperations(AetheriaDaemonObserver observer) + public AetheriaRuntimeDaemonOperationsClient( + Func, AetheriaRuntimeDaemonCommandEnvelope> submit) { - _observer = observer ?? throw new ArgumentNullException(nameof(observer)); + _submit = submit ?? throw new ArgumentNullException(nameof(submit)); } public AetheriaRuntimeDaemonCommandEnvelope SetTarget(string targetEntityKey) @@ -377,6 +379,7 @@ public sealed class AetheriaDaemonOperations private AetheriaRuntimeDaemonCommandEnvelope Send( Func submit) { - return _observer.SendOperation(submit); + return _submit(submit); } } +} diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveSurfaceAdapter.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveSurfaceAdapter.cs index b05cf439b..b749602c3 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveSurfaceAdapter.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveSurfaceAdapter.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using GameCult.Eve.Surface; +using EveSurfaceState = global::Aetheria.State.Documents.EveSurfaceState; #nullable enable @@ -14,6 +15,41 @@ namespace GameCult.Aetheria.State.Verse return ToEveSurfaceDocument(document, null); } + public static EveSurfaceDocument ToEveSurfaceDocument(EveSurfaceState state) + { + return ToEveSurfaceDocument(state, null); + } + + public static EveSurfaceDocument ToEveSurfaceDocument( + EveSurfaceState state, + Func? stateRefResolver) + { + if (state == null) throw new ArgumentNullException(nameof(state)); + + var surface = new EveSurfaceDocument( + state.Type, + state.Schema, + state.ProviderId, + state.ProviderKind, + state.Title, + state.Version, + state.UpdatedAtUtc, + new EveSurfaceTree( + state.Surface.Id, + ToEveSurfaceComponent(state.Surface.Root), + state.Surface.Styles + .Select(style => new GameCult.Eve.Surface.EveStyleToken(style.Name, style.Value)) + .ToArray()), + state.Commands + .Select(command => new GameCult.Eve.Surface.EveCommandTemplate( + command.Command, + command.Label, + command.Transport)) + .ToArray()); + + return ResolveStateRefs(surface, stateRefResolver); + } + public static EveSurfaceDocument ToEveSurfaceDocument( AetheriaRuntimeSurfaceDocument document, Func? stateRefResolver) @@ -95,6 +131,15 @@ namespace GameCult.Aetheria.State.Verse component.Children.Select(ToEveSurfaceComponent).ToArray()); } + private static EveSurfaceComponent ToEveSurfaceComponent(global::Aetheria.State.Documents.EveSurfaceComponent component) + { + return new EveSurfaceComponent( + component.Id, + component.Kind, + new Dictionary(component.Props, StringComparer.Ordinal), + component.Children.Select(ToEveSurfaceComponent).ToArray()); + } + private static EveSurfaceComponent ResolveStateRefs( EveSurfaceComponent component, Func stateRefResolver)