diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 59ddb9c32..e851446ae 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -3214,10 +3214,10 @@ static void RequireEveRuntimeBootstrap(string root) "AetheriaUnityRuntimeClientProvider.ResolveClient(", "CultMeshReactiveDocument", "ResolveReactiveDaemonSurfaceState(", - "client.State.ReactiveGameSurface()", - "client.State.ReactiveGameTuiSurface()", - "client.State.ReactiveEditorSurface()", - "client.State.ReactiveEditorTuiSurface()", + "client.State.Reactive(AetheriaClientEveSurface.Game)", + "client.State.Reactive(AetheriaClientEveSurface.GameTui)", + "client.State.Reactive(AetheriaClientEveSurface.Editor)", + "client.State.Reactive(AetheriaClientEveSurface.EditorTui)", "DisposeReactiveSurfaceState()", "AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(", "private bool ShouldMountSurface(", @@ -8114,14 +8114,10 @@ static void RequireAetheriaManagedStateAccessorsCoverDomainDocuments(string root "public CultMeshReactiveDocument Reactive(", "public CultMeshReactiveDocument Reactive(", "public CultMeshReactiveDocument Reactive(", - "public global::Aetheria.State.Documents.EveSurfaceState LatestGameSurface()", - "public global::Aetheria.State.Documents.EveSurfaceState LatestGameTuiSurface()", - "public global::Aetheria.State.Documents.EveSurfaceState LatestEditorSurface()", - "public global::Aetheria.State.Documents.EveSurfaceState LatestEditorTuiSurface()", - "public CultMeshReactiveDocument ReactiveGameSurface(", - "public CultMeshReactiveDocument ReactiveGameTuiSurface(", - "public CultMeshReactiveDocument ReactiveEditorSurface(", - "public CultMeshReactiveDocument ReactiveEditorTuiSurface(", + "public enum AetheriaClientEveSurface", + "public CultMeshDocumentHandle Document(AetheriaClientEveSurface surface)", + "public TDocument Latest(AetheriaClientEveSurface surface)", + "public CultMeshReactiveDocument Reactive(", "public CultMeshDocumentHandle Document(AetheriaRuntimeRtsViewportBounds viewport)", "public TDocument Latest(AetheriaRuntimeRtsViewportBounds viewport)", "public CultMeshDocumentHandle Document(int entityOrZoneIndex)", @@ -8206,7 +8202,23 @@ static void RequireAetheriaManagedStateAccessorsCoverDomainDocuments(string root "LatestSummary(", "LatestSummaryAsync(", "ReactiveSummary(", - "ReactiveSummaryAsync(" + "ReactiveSummaryAsync(", + "LatestGameSurface(", + "LatestGameSurfaceAsync(", + "ReactiveGameSurface(", + "ReactiveGameSurfaceAsync(", + "LatestGameTuiSurface(", + "LatestGameTuiSurfaceAsync(", + "ReactiveGameTuiSurface(", + "ReactiveGameTuiSurfaceAsync(", + "LatestEditorSurface(", + "LatestEditorSurfaceAsync(", + "ReactiveEditorSurface(", + "ReactiveEditorSurfaceAsync(", + "LatestEditorTuiSurface(", + "LatestEditorTuiSurfaceAsync(", + "ReactiveEditorTuiSurface(", + "ReactiveEditorTuiSurfaceAsync(" }; var survivingFixedReactiveWrappers = forbiddenFixedReactiveWrappers .Where(symbol => clientState.Contains(symbol, StringComparison.Ordinal)) @@ -8428,6 +8440,14 @@ static void RequireAetheriaManagedStateAccessorsCoverDomainDocuments(string root "client.State.Daemon.LatestGameTuiSurface()", "client.State.Daemon.LatestEditorSurface()", "client.State.Daemon.LatestEditorTuiSurface()", + "client.State.LatestGameSurface()", + "client.State.LatestGameTuiSurface()", + "client.State.LatestEditorSurface()", + "client.State.LatestEditorTuiSurface()", + "client.State.ReactiveGameSurface()", + "client.State.ReactiveGameTuiSurface()", + "client.State.ReactiveEditorSurface()", + "client.State.ReactiveEditorTuiSurface()", "client.State.ObserveCatalog()", "client.State.ObserveDaemonFrame()", "client.State.ObserveLoadoutTemplates()", @@ -8480,7 +8500,7 @@ static void RequireAetheriaManagedStateAccessorsCoverDomainDocuments(string root "Starbridge player-seat examples must use generic parameterized managed document access instead of named wrappers or raw handle walks."); } - Console.WriteLine("Domain document accessors: managed Aetheria state uses generic fixed-document reads plus generic parameterized viewport/detail/Starbridge access"); + Console.WriteLine("Domain document accessors: managed Aetheria state uses generic fixed-document reads plus generic parameterized viewport/detail/Starbridge/Eve-surface access"); } static void RequireVerseHostSettingsAuthority(string root) diff --git a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs index 13df12730..9baea3c99 100644 --- a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs +++ b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs @@ -227,10 +227,10 @@ public class DaemonRuntimeDocumentTests using var playerHudCatalog = client.State.Reactive(); using var playerHudSettings = client.State.Reactive(); using var playerHudEntity = client.State.Reactive(); - var gameSurface = client.State.LatestGameSurface(); - var gameTuiSurface = client.State.LatestGameTuiSurface(); - var editorSurface = client.State.LatestEditorSurface(); - var editorTuiSurface = client.State.LatestEditorTuiSurface(); + var gameSurface = client.State.Latest(AetheriaClientEveSurface.Game); + var gameTuiSurface = client.State.Latest(AetheriaClientEveSurface.GameTui); + var editorSurface = client.State.Latest(AetheriaClientEveSurface.Editor); + var editorTuiSurface = client.State.Latest(AetheriaClientEveSurface.EditorTui); var authorityStatus = client.State.Latest(); var currentDocking = client.State.Current.Docking .LatestAsync() @@ -238,10 +238,10 @@ public class DaemonRuntimeDocumentTests .GetResult(); var stationRefit = client.State.Latest(); var observedDocking = client.State.CurrentDocking(); - using var reactiveGameSurface = client.State.ReactiveGameSurface(); - using var reactiveGameTuiSurface = client.State.ReactiveGameTuiSurface(); - using var reactiveEditorSurface = client.State.ReactiveEditorSurface(); - using var reactiveEditorTuiSurface = client.State.ReactiveEditorTuiSurface(); + using var reactiveGameSurface = client.State.Reactive(AetheriaClientEveSurface.Game); + using var reactiveGameTuiSurface = client.State.Reactive(AetheriaClientEveSurface.GameTui); + using var reactiveEditorSurface = client.State.Reactive(AetheriaClientEveSurface.Editor); + using var reactiveEditorTuiSurface = client.State.Reactive(AetheriaClientEveSurface.EditorTui); Assert.AreEqual("aetheria.current.entity", client.State.Current.Entity.DocumentId); Assert.AreSame(client.State.Current.Entity, client.State.Document()); @@ -603,10 +603,10 @@ public class DaemonRuntimeDocumentTests .OpenAsync(statePath, "unity-surface-test", pullOnOpen: true) .GetAwaiter() .GetResult(); - var unityGameSurfaceState = client.State.LatestGameSurface(); - var unityGameTuiSurfaceState = client.State.LatestGameTuiSurface(); - var unityEditorSurfaceState = client.State.LatestEditorSurface(); - var unityEditorTuiSurfaceState = client.State.LatestEditorTuiSurface(); + var unityGameSurfaceState = client.State.Latest(AetheriaClientEveSurface.Game); + var unityGameTuiSurfaceState = client.State.Latest(AetheriaClientEveSurface.GameTui); + var unityEditorSurfaceState = client.State.Latest(AetheriaClientEveSurface.Editor); + var unityEditorTuiSurfaceState = client.State.Latest(AetheriaClientEveSurface.EditorTui); var surfaceResolver = client.State.CreateEveSurfaceStateRefResolver(); var unityGameSurface = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument( unityGameSurfaceState, @@ -638,7 +638,7 @@ public class DaemonRuntimeDocumentTests Assert.AreEqual(AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId, unityEditorTuiSurface.Surface.Id); Assert.AreEqual("editor.daemon", unityEditorTuiSurface.ProviderKind); var genericGameSurface = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument( - client.State.LatestGameSurface(), + client.State.Latest(AetheriaClientEveSurface.Game), surfaceResolver); Assert.AreEqual(AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId, genericGameSurface.Surface.Id); Assert.AreEqual(unityGameSurface.ProviderId, genericGameSurface.ProviderId); @@ -661,11 +661,11 @@ public class DaemonRuntimeDocumentTests AetheriaRuntimeDaemonStateRefs.CurrentTargetName, AetheriaRuntimeDaemonSchemas.Frame)); var genericGameTuiSurface = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument( - client.State.LatestGameTuiSurface(), + client.State.Latest(AetheriaClientEveSurface.GameTui), surfaceResolver); Assert.AreEqual(AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId, genericGameTuiSurface.Surface.Id); var genericEditorTuiSurface = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument( - client.State.LatestEditorTuiSurface(), + client.State.Latest(AetheriaClientEveSurface.EditorTui), surfaceResolver); Assert.AreEqual(AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId, genericEditorTuiSurface.Surface.Id); } diff --git a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs index fbe348dfd..904c64ad2 100644 --- a/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs +++ b/Packages/org.gamecult.aetheria.eve-runtime/Runtime/AetheriaEveSurfacePresenter.cs @@ -169,16 +169,16 @@ namespace GameCult.Aetheria.EveRuntime AetheriaClient client) { if (string.Equals(surfaceId, AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId, StringComparison.Ordinal)) - return client.State.ReactiveGameSurface(); + return client.State.Reactive(AetheriaClientEveSurface.Game); if (string.Equals(surfaceId, AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId, StringComparison.Ordinal)) - return client.State.ReactiveGameTuiSurface(); + return client.State.Reactive(AetheriaClientEveSurface.GameTui); if (string.Equals(surfaceId, AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId, StringComparison.Ordinal)) - return client.State.ReactiveEditorSurface(); + return client.State.Reactive(AetheriaClientEveSurface.Editor); if (string.Equals(surfaceId, AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId, StringComparison.Ordinal)) - return client.State.ReactiveEditorTuiSurface(); + return client.State.Reactive(AetheriaClientEveSurface.EditorTui); return null; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs index 7562b9c3c..95e1894ff 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs @@ -9,6 +9,14 @@ using R3; namespace GameCult.Aetheria.State.Verse { + public enum AetheriaClientEveSurface + { + Game, + GameTui, + Editor, + EditorTui + } + public sealed class AetheriaClientState { private readonly CultMeshDocumentCatalog _documents; @@ -217,6 +225,40 @@ namespace GameCult.Aetheria.State.Verse : null; } + public CultMeshDocumentHandle Document(AetheriaClientEveSurface surface) + where TDocument : class + { + return Daemon.Document(surface); + } + + public Task LatestAsync(AetheriaClientEveSurface surface) + where TDocument : class + { + return Document(surface).LatestAsync(); + } + + public TDocument Latest(AetheriaClientEveSurface surface) + where TDocument : class + { + return LatestAsync(surface).ConfigureAwait(false).GetAwaiter().GetResult(); + } + + public Task> ReactiveAsync( + AetheriaClientEveSurface surface, + CultMeshReactiveDocumentOptions? options = null) + where TDocument : class + { + return Document(surface).ReactiveAsync(options); + } + + public CultMeshReactiveDocument Reactive( + AetheriaClientEveSurface surface, + CultMeshReactiveDocumentOptions? options = null) + where TDocument : class + { + return Document(surface).Reactive(options); + } + private CultMeshReactiveDocument? TryReactive( CultMeshReactiveDocumentOptions? options) where TDocument : class @@ -246,94 +288,6 @@ namespace GameCult.Aetheria.State.Verse } } - public Task LatestGameSurfaceAsync() - { - return Daemon.LatestGameSurfaceAsync(); - } - - public global::Aetheria.State.Documents.EveSurfaceState LatestGameSurface() - { - return LatestGameSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - } - - public Task> ReactiveGameSurfaceAsync( - CultMeshReactiveDocumentOptions? options = null) - { - return Daemon.ReactiveGameSurfaceAsync(options); - } - - public CultMeshReactiveDocument ReactiveGameSurface( - CultMeshReactiveDocumentOptions? options = null) - { - return Daemon.ReactiveGameSurface(options); - } - - public Task LatestGameTuiSurfaceAsync() - { - return Daemon.LatestGameTuiSurfaceAsync(); - } - - public global::Aetheria.State.Documents.EveSurfaceState LatestGameTuiSurface() - { - return LatestGameTuiSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - } - - public Task> ReactiveGameTuiSurfaceAsync( - CultMeshReactiveDocumentOptions? options = null) - { - return Daemon.ReactiveGameTuiSurfaceAsync(options); - } - - public CultMeshReactiveDocument ReactiveGameTuiSurface( - CultMeshReactiveDocumentOptions? options = null) - { - return Daemon.ReactiveGameTuiSurface(options); - } - - public Task LatestEditorSurfaceAsync() - { - return Daemon.LatestEditorSurfaceAsync(); - } - - public global::Aetheria.State.Documents.EveSurfaceState LatestEditorSurface() - { - return LatestEditorSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - } - - public Task> ReactiveEditorSurfaceAsync( - CultMeshReactiveDocumentOptions? options = null) - { - return Daemon.ReactiveEditorSurfaceAsync(options); - } - - public CultMeshReactiveDocument ReactiveEditorSurface( - CultMeshReactiveDocumentOptions? options = null) - { - return Daemon.ReactiveEditorSurface(options); - } - - public Task LatestEditorTuiSurfaceAsync() - { - return Daemon.LatestEditorTuiSurfaceAsync(); - } - - public global::Aetheria.State.Documents.EveSurfaceState LatestEditorTuiSurface() - { - return LatestEditorTuiSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - } - - public Task> ReactiveEditorTuiSurfaceAsync( - CultMeshReactiveDocumentOptions? options = null) - { - return Daemon.ReactiveEditorTuiSurfaceAsync(options); - } - - public CultMeshReactiveDocument ReactiveEditorTuiSurface( - CultMeshReactiveDocumentOptions? options = null) - { - return Daemon.ReactiveEditorTuiSurface(options); - } - public Observable Watch() where TDocument : class { @@ -433,92 +387,66 @@ namespace GameCult.Aetheria.State.Verse public CultMeshDocumentHandle EditorTuiSurface { get; } - public Task LatestGameSurfaceAsync() + public bool TryGetDocument( + AetheriaClientEveSurface surface, + out CultMeshDocumentHandle document) + where TDocument : class { - return GameSurface.LatestAsync(); + if (typeof(TDocument) == typeof(global::Aetheria.State.Documents.EveSurfaceState)) + { + var eveSurface = surface switch + { + AetheriaClientEveSurface.Game => GameSurface, + AetheriaClientEveSurface.GameTui => GameTuiSurface, + AetheriaClientEveSurface.Editor => EditorSurface, + AetheriaClientEveSurface.EditorTui => EditorTuiSurface, + _ => throw new ArgumentOutOfRangeException(nameof(surface), surface, null) + }; + + document = (CultMeshDocumentHandle)(object)eveSurface; + return true; + } + + document = null!; + return false; } - public global::Aetheria.State.Documents.EveSurfaceState LatestGameSurface() + public CultMeshDocumentHandle Document(AetheriaClientEveSurface surface) + where TDocument : class { - return LatestGameSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); + if (TryGetDocument(surface, out var document)) + return document; + + throw new NotSupportedException( + $"Aetheria daemon state does not expose an Eve surface document for {typeof(TDocument).FullName}."); } - public Task> ReactiveGameSurfaceAsync( + public Task LatestAsync(AetheriaClientEveSurface surface) + where TDocument : class + { + return Document(surface).LatestAsync(); + } + + public TDocument Latest(AetheriaClientEveSurface surface) + where TDocument : class + { + return LatestAsync(surface).ConfigureAwait(false).GetAwaiter().GetResult(); + } + + public Task> ReactiveAsync( + AetheriaClientEveSurface surface, CultMeshReactiveDocumentOptions? options = null) + where TDocument : class { - return GameSurface.ReactiveAsync(options); + return Document(surface).ReactiveAsync(options); } - public CultMeshReactiveDocument ReactiveGameSurface( + public CultMeshReactiveDocument Reactive( + AetheriaClientEveSurface surface, CultMeshReactiveDocumentOptions? options = null) + where TDocument : class { - return GameSurface.Reactive(options); - } - - public Task LatestGameTuiSurfaceAsync() - { - return GameTuiSurface.LatestAsync(); - } - - public global::Aetheria.State.Documents.EveSurfaceState LatestGameTuiSurface() - { - return LatestGameTuiSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - } - - public Task> ReactiveGameTuiSurfaceAsync( - CultMeshReactiveDocumentOptions? options = null) - { - return GameTuiSurface.ReactiveAsync(options); - } - - public CultMeshReactiveDocument ReactiveGameTuiSurface( - CultMeshReactiveDocumentOptions? options = null) - { - return GameTuiSurface.Reactive(options); - } - - public Task LatestEditorSurfaceAsync() - { - return EditorSurface.LatestAsync(); - } - - public global::Aetheria.State.Documents.EveSurfaceState LatestEditorSurface() - { - return LatestEditorSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - } - - public Task> ReactiveEditorSurfaceAsync( - CultMeshReactiveDocumentOptions? options = null) - { - return EditorSurface.ReactiveAsync(options); - } - - public CultMeshReactiveDocument ReactiveEditorSurface( - CultMeshReactiveDocumentOptions? options = null) - { - return EditorSurface.Reactive(options); - } - - public Task LatestEditorTuiSurfaceAsync() - { - return EditorTuiSurface.LatestAsync(); - } - - public global::Aetheria.State.Documents.EveSurfaceState LatestEditorTuiSurface() - { - return LatestEditorTuiSurfaceAsync().ConfigureAwait(false).GetAwaiter().GetResult(); - } - - public Task> ReactiveEditorTuiSurfaceAsync( - CultMeshReactiveDocumentOptions? options = null) - { - return EditorTuiSurface.ReactiveAsync(options); - } - - public CultMeshReactiveDocument ReactiveEditorTuiSurface( - CultMeshReactiveDocumentOptions? options = null) - { - return EditorTuiSurface.Reactive(options); + return Document(surface).Reactive(options); } }