diff --git a/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md b/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md index 1fb79860e..c372ab498 100644 --- a/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md +++ b/Aetheria.State/docs/cultmesh-ergonomics-staged-migration-plan.md @@ -269,9 +269,14 @@ Gates: ## Stage 3A: Collapse State Access To Typed Reactive Handles Status: started; `AetheriaRuntimeVerseClient.Aetheria()` now exposes the first -C# domain facade for current, station, and zone projected documents, and -`AetheriaClient` delegates to that shared facade. Unity and RTS clients still -perform byzantine protocol walks in several menus/renderers. +C# domain facade for current, station, and zone projected documents, +`AetheriaClient` delegates to that shared facade, and the broad Unity +menu/HUD/map/render projected-state reads now use typed state handles instead +of transitional `Current*Async()`, `StationRefitAsync()`, `SectorMapAsync()`, +`ZoneContactsAsync()`, or `ZoneRenderAsync()` helpers. `AetheriaClientState` +also indexes projected state documents by shared document type so callers can +retrieve or watch a known typed document with one call while CultMesh owns the +bound live feed. Goal: every client-facing state access becomes a single CultMesh document, collection, query, or pointer call. The caller names the domain state it wants and gets a typed reactive value. It does not manually inspect daemon frames, current-state projections, station rows, record keys, local facade indexes, or transport route details. @@ -303,6 +308,12 @@ var refit = await client.Aetheria() .Station .Refit .LatestAsync(); + +var contacts = await client.Aetheria() + .LatestAsync(); + +using var render = client + .Watch(RenderZone); ``` Desired TS shape: @@ -322,10 +333,10 @@ const refit = await client.aetheria() Work: -- Add shared CultMesh typed reactive document and collection handles if the existing state-pointer/query primitives are not enough. +- Keep pushing shared CultMesh typed reactive document and collection handles down until type/schema lookup is owned by CultMesh rather than by the Aetheria facade registry. - Generate Aetheria current/station/zone/catalog accessors from schema metadata. - Move derived-state joins, such as current docking bay from current docking plus station refit plus entity records, into generated/internal query executors. -- Replace Unity menu/HUD/render calls to `Current*Async()`, `StationRefitAsync()`, `TryResolve*`, and `_observedFacadeIndex` with typed handles. +- Replace remaining Unity menu/HUD/render calls to `TryResolve*` and `_observedFacadeIndex` with typed handles or generated/internal render adapters. - Replace blocking `GetAwaiter().GetResult()` reads in client presentation code with watch/latest handles that own lifetimes. - Keep renderer-local facade indexes only inside render adapter internals while native/query views are still being migrated. - Add verifiers that treat multi-hop state reads in client code as failures. @@ -333,6 +344,7 @@ Work: Gates: - `InventoryMenu`, `InventoryPanel`, `TradeMenu`, `LocalMenu`, `SchematicDisplay`, `SectorRenderer`, `MapRenderer`, and `ZoneRenderer` do not manually join state projections to obtain domain values. +- Shared projected documents are reachable through `client.Aetheria().Document()`, `client.Aetheria().LatestAsync()`, and `client.Watch()` as the C# stepping stone toward CultMesh-native type/schema lookup. - Client-facing code contains no `_observedFacadeIndex.TryResolve*` outside Unity render adapter internals. - Client-facing code contains no `ResolveClient().Current*Async().GetAwaiter().GetResult()` or equivalent blocking state reads. - `TryGetTypedCurrentDockingBayFacade` and similar transitional helpers are deleted rather than renamed. diff --git a/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 b/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 index 57d2e631d..7df0598b5 100644 --- a/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 +++ b/Aetheria.State/scripts/verify-stage7d-unity-parity.ps1 @@ -576,6 +576,9 @@ Assert-Contains $tickRunner "ProjectTradeValuePolicySurfaceDocument(stateFilePat $client = Read-Text "Packages\org.gamecult.aetheria.state\Runtime\AetheriaClient.cs" Assert-Contains $client "AetheriaClientState State" "AetheriaClient must expose the semantic typed state facade." Assert-Contains $client "Aetheria()" "AetheriaClient must expose the canonical domain facade entrypoint." +Assert-Contains $client "Document()" "AetheriaClient must allow callers to retrieve a projected state document by shared document type." +Assert-Contains $client "LatestAsync()" "AetheriaClient must allow one-call typed state reads by shared document type." +Assert-Contains $client "Watch()" "AetheriaClient must allow reactive typed state reads by shared document type." Assert-Contains $client "ObjectsViewportAsync" "AetheriaClient must expose objects viewport facade." Assert-Contains $client "GravityViewportAsync" "AetheriaClient must expose gravity viewport facade." Assert-Contains $client "CurrentZoneAsync" "AetheriaClient must expose current-zone facade." @@ -593,6 +596,11 @@ Assert-Contains $verseClient "CreateAetheriaStateFacade" "AetheriaRuntimeVerseCl $clientState = Read-Text "Packages\org.gamecult.aetheria.state\Runtime\AetheriaClientState.cs" Assert-Contains $clientState "CultMeshBoundLiveFeed" "Aetheria state documents must bind through CultMesh live feeds." +Assert-Contains $clientState "_documentsByType" "Aetheria state facade must index projected documents by shared document type." +Assert-Contains $clientState "TryGetDocument" "Aetheria state facade must support safe typed document lookup." +Assert-Contains $clientState "Document()" "Aetheria state facade must support direct typed document lookup." +Assert-Contains $clientState "LatestAsync()" "Aetheria state facade must support one-call typed document reads." +Assert-Contains $clientState "Watch()" "Aetheria state facade must support reactive typed document lookup." Assert-Contains $clientState "LatestAsync()" "Aetheria state documents must support one-shot typed reads." Assert-Contains $clientState "Watch()" "Aetheria state documents must support reactive typed reads." diff --git a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs index 8619220d2..c6facb471 100644 --- a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs +++ b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs @@ -167,13 +167,27 @@ public class DaemonRuntimeDocumentTests .GetResult(); var currentEntity = client.Aetheria().Current.Entity.LatestAsync().GetAwaiter().GetResult(); + var currentEntityByType = client.Aetheria() + .LatestAsync() + .GetAwaiter() + .GetResult(); + var currentEntityFromClientType = client + .LatestAsync() + .GetAwaiter() + .GetResult(); var legacyCurrentEntity = client.CurrentEntityAsync().GetAwaiter().GetResult(); Assert.AreEqual("aetheria.current.entity", client.State.Current.Entity.DocumentId); + Assert.AreSame(client.State.Current.Entity, client.State.Document()); + Assert.AreSame(client.State.ZoneRender, client.Document()); + Assert.IsTrue(client.State.TryGetDocument(out var sectorMapDocument)); + Assert.AreSame(client.State.SectorMap, sectorMapDocument); Assert.AreEqual(AetheriaRuntimeDaemonSchemas.CurrentEntity, currentEntity.Schema); Assert.AreEqual("zone.0.entity.0", currentEntity.EntityKey); Assert.AreEqual(0, currentEntity.EntityIndex); Assert.AreEqual("Player", currentEntity.Entity?.Name); + Assert.AreEqual(currentEntity.EntityKey, currentEntityByType.EntityKey); + Assert.AreEqual(currentEntity.EntityKey, currentEntityFromClientType.EntityKey); Assert.AreEqual(legacyCurrentEntity.EntityKey, currentEntity.EntityKey); Assert.IsTrue(client.State.Current.Entity.Sources.Any(source => source.SourceId == AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString())); diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs index 3a3004d06..916bd70f9 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClient.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading.Tasks; using GameCult.Eve.Surface; using GameCult.Mesh; +using R3; #nullable enable @@ -39,6 +40,30 @@ namespace GameCult.Aetheria.State.Verse public AetheriaClientState Aetheria() => State; + public AetheriaRuntimeProjectedDocument Document() + { + ThrowIfDisposed(); + return State.Document(); + } + + public Task LatestAsync() + { + ThrowIfDisposed(); + return State.LatestAsync(); + } + + public Observable Watch() + { + ThrowIfDisposed(); + return State.Watch(); + } + + public IDisposable Watch(Action onNext) + { + ThrowIfDisposed(); + return State.Watch(onNext); + } + internal AetheriaRuntimeDaemonOperationsClient Operations => _operations; public static async Task OpenAsync( diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs index e5a4b4dde..70501feaa 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using GameCult.Mesh; using R3; @@ -81,6 +82,8 @@ namespace GameCult.Aetheria.State.Verse public sealed class AetheriaClientState { + private readonly IReadOnlyDictionary _documentsByType; + internal AetheriaClientState( AetheriaRuntimeProjectedDocument currentZone, AetheriaRuntimeProjectedDocument currentEntity, @@ -95,6 +98,16 @@ namespace GameCult.Aetheria.State.Verse StationRefit = stationRefit ?? throw new ArgumentNullException(nameof(stationRefit)); SectorMap = sectorMap ?? throw new ArgumentNullException(nameof(sectorMap)); ZoneRender = zoneRender ?? throw new ArgumentNullException(nameof(zoneRender)); + _documentsByType = new Dictionary + { + [typeof(AetheriaRuntimeCurrentZoneDocument)] = Current.Zone, + [typeof(AetheriaRuntimeCurrentEntityDocument)] = Current.Entity, + [typeof(AetheriaRuntimeCurrentDockingDocument)] = Current.Docking, + [typeof(AetheriaRuntimeZoneContactsDocument)] = ZoneContacts, + [typeof(AetheriaRuntimeStationRefitDocument)] = StationRefit, + [typeof(AetheriaRuntimeSectorMapDocument)] = SectorMap, + [typeof(AetheriaRuntimeZoneRenderDocument)] = ZoneRender + }; } public AetheriaClientCurrentState Current { get; } @@ -106,6 +119,44 @@ namespace GameCult.Aetheria.State.Verse public AetheriaRuntimeProjectedDocument SectorMap { get; } public AetheriaRuntimeProjectedDocument ZoneRender { get; } + + public bool TryGetDocument( + out AetheriaRuntimeProjectedDocument document) + { + if (_documentsByType.TryGetValue(typeof(TDocument), out var untypedDocument) && + untypedDocument is AetheriaRuntimeProjectedDocument typedDocument) + { + document = typedDocument; + return true; + } + + document = null!; + return false; + } + + public AetheriaRuntimeProjectedDocument Document() + { + if (TryGetDocument(out var document)) + return document; + + throw new NotSupportedException( + $"Aetheria typed state does not expose a projected document for {typeof(TDocument).FullName}."); + } + + public Task LatestAsync() + { + return Document().LatestAsync(); + } + + public Observable Watch() + { + return Document().Watch(); + } + + public IDisposable Watch(Action onNext) + { + return Document().Watch(onNext); + } } public sealed class AetheriaClientCurrentState