Add schema lookup for Aetheria state documents
This commit is contained in:
parent
0196b9bca0
commit
fb657bea1d
5 changed files with 115 additions and 4 deletions
|
|
@ -276,7 +276,9 @@ 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.
|
||||
bound live feed. The facade also indexes those handles by `CultDocument`
|
||||
schema name/version, so a caller can resolve the shared schema identity even
|
||||
when exact local CLR type identity is not the public contract.
|
||||
|
||||
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.
|
||||
|
||||
|
|
@ -312,6 +314,9 @@ var refit = await client.Aetheria()
|
|||
var contacts = await client.Aetheria()
|
||||
.LatestAsync<AetheriaRuntimeZoneContactsDocument>();
|
||||
|
||||
var contactsHandle = client.Aetheria()
|
||||
.DocumentBySchema(AetheriaRuntimeDaemonSchemas.ZoneContacts);
|
||||
|
||||
using var render = client
|
||||
.Watch<AetheriaRuntimeZoneRenderDocument>(RenderZone);
|
||||
```
|
||||
|
|
@ -333,7 +338,7 @@ const refit = await client.aetheria()
|
|||
|
||||
Work:
|
||||
|
||||
- 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.
|
||||
- Keep pushing shared CultMesh typed reactive document and collection handles down until type/schema lookup, including safe conversion for schema-compatible CLR aliases, 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 remaining Unity menu/HUD/render calls to `TryResolve*` and `_observedFacadeIndex` with typed handles or generated/internal render adapters.
|
||||
|
|
@ -344,7 +349,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<TDocument>()`, `client.Aetheria().LatestAsync<TDocument>()`, and `client.Watch<TDocument>()` as the C# stepping stone toward CultMesh-native type/schema lookup.
|
||||
- Shared projected documents are reachable through `client.Aetheria().Document<TDocument>()`, `client.Aetheria().DocumentBySchema(schemaVersion)`, `client.Aetheria().LatestAsync<TDocument>()`, and `client.Watch<TDocument>()` 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.
|
||||
|
|
|
|||
|
|
@ -577,6 +577,7 @@ $client = Read-Text "Packages\org.gamecult.aetheria.state\Runtime\AetheriaClient
|
|||
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<TDocument>()" "AetheriaClient must allow callers to retrieve a projected state document by shared document type."
|
||||
Assert-Contains $client "DocumentBySchema(string schemaVersion)" "AetheriaClient must allow projected state lookup by shared schema identity."
|
||||
Assert-Contains $client "LatestAsync<TDocument>()" "AetheriaClient must allow one-call typed state reads by shared document type."
|
||||
Assert-Contains $client "Watch<TDocument>()" "AetheriaClient must allow reactive typed state reads by shared document type."
|
||||
Assert-Contains $client "ObjectsViewportAsync" "AetheriaClient must expose objects viewport facade."
|
||||
|
|
@ -596,9 +597,13 @@ 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 "IAetheriaRuntimeProjectedDocument" "Aetheria projected documents must expose schema metadata independent of exact CLR type."
|
||||
Assert-Contains $clientState "_documentsByType" "Aetheria state facade must index projected documents by shared document type."
|
||||
Assert-Contains $clientState "_documentsBySchema" "Aetheria state facade must index projected documents by shared schema identity."
|
||||
Assert-Contains $clientState "TryGetDocument<TDocument>" "Aetheria state facade must support safe typed document lookup."
|
||||
Assert-Contains $clientState "TryGetDocumentBySchema" "Aetheria state facade must support safe schema document lookup."
|
||||
Assert-Contains $clientState "Document<TDocument>()" "Aetheria state facade must support direct typed document lookup."
|
||||
Assert-Contains $clientState "DocumentBySchema(string schemaVersion)" "Aetheria state facade must support direct schema document lookup."
|
||||
Assert-Contains $clientState "LatestAsync<TDocument>()" "Aetheria state facade must support one-call typed document reads."
|
||||
Assert-Contains $clientState "Watch<TDocument>()" "Aetheria state facade must support reactive typed document lookup."
|
||||
Assert-Contains $clientState "LatestAsync()" "Aetheria state documents must support one-shot typed reads."
|
||||
|
|
|
|||
|
|
@ -180,8 +180,21 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.AreEqual("aetheria.current.entity", client.State.Current.Entity.DocumentId);
|
||||
Assert.AreSame(client.State.Current.Entity, client.State.Document<AetheriaRuntimeCurrentEntityDocument>());
|
||||
Assert.AreSame(client.State.ZoneRender, client.Document<AetheriaRuntimeZoneRenderDocument>());
|
||||
Assert.AreSame(
|
||||
client.State.Current.Entity,
|
||||
client.State.DocumentBySchema(AetheriaRuntimeDaemonSchemas.CurrentEntity));
|
||||
Assert.AreSame(
|
||||
client.State.ZoneContacts,
|
||||
client.DocumentBySchema("gamecult.aetheria.zone_contacts"));
|
||||
Assert.AreEqual(
|
||||
typeof(AetheriaRuntimeCurrentEntityDocument),
|
||||
client.DocumentBySchema(AetheriaRuntimeDaemonSchemas.CurrentEntity).DocumentType);
|
||||
Assert.IsTrue(client.State.TryGetDocument<AetheriaRuntimeSectorMapDocument>(out var sectorMapDocument));
|
||||
Assert.AreSame(client.State.SectorMap, sectorMapDocument);
|
||||
Assert.IsTrue(client.State.TryGetDocumentBySchema(
|
||||
AetheriaRuntimeDaemonSchemas.SectorMap,
|
||||
out var sectorMapBySchema));
|
||||
Assert.AreSame(client.State.SectorMap, sectorMapBySchema);
|
||||
Assert.AreEqual(AetheriaRuntimeDaemonSchemas.CurrentEntity, currentEntity.Schema);
|
||||
Assert.AreEqual("zone.0.entity.0", currentEntity.EntityKey);
|
||||
Assert.AreEqual(0, currentEntity.EntityIndex);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,12 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return State.Document<TDocument>();
|
||||
}
|
||||
|
||||
public IAetheriaRuntimeProjectedDocument DocumentBySchema(string schemaVersion)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
return State.DocumentBySchema(schemaVersion);
|
||||
}
|
||||
|
||||
public Task<TDocument> LatestAsync<TDocument>()
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using GameCult.Caching;
|
||||
using GameCult.Mesh;
|
||||
using R3;
|
||||
|
||||
|
|
@ -13,10 +15,12 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public static readonly AetheriaRuntimeStateQueryParameters Empty = new AetheriaRuntimeStateQueryParameters();
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeProjectedDocument<TDocument>
|
||||
public sealed class AetheriaRuntimeProjectedDocument<TDocument> : IAetheriaRuntimeProjectedDocument
|
||||
{
|
||||
private static readonly CultMeshPollingWatchOptions<TDocument> DefaultWatchOptions =
|
||||
new CultMeshPollingWatchOptions<TDocument>(TimeSpan.FromMilliseconds(100));
|
||||
private static readonly CultDocumentAttribute? DocumentAttribute =
|
||||
typeof(TDocument).GetCustomAttribute<CultDocumentAttribute>();
|
||||
|
||||
private readonly CultMeshBoundLiveFeed<AetheriaRuntimeStateQueryParameters, TDocument> _feed;
|
||||
|
||||
|
|
@ -28,6 +32,12 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
public string DocumentId => _feed.FeedId;
|
||||
|
||||
public Type DocumentType => typeof(TDocument);
|
||||
|
||||
public string SchemaName => DocumentAttribute?.SchemaName ?? "";
|
||||
|
||||
public string SchemaVersion => DocumentAttribute?.SchemaVersion ?? "";
|
||||
|
||||
public CultMeshRouteHint RouteHint => _feed.RouteHint;
|
||||
|
||||
public System.Collections.Generic.IReadOnlyList<CultMeshProjectionSource> Sources => _feed.Sources;
|
||||
|
|
@ -80,9 +90,25 @@ namespace GameCult.Aetheria.State.Verse
|
|||
}
|
||||
}
|
||||
|
||||
public interface IAetheriaRuntimeProjectedDocument
|
||||
{
|
||||
Type DocumentType { get; }
|
||||
|
||||
string DocumentId { get; }
|
||||
|
||||
string SchemaName { get; }
|
||||
|
||||
string SchemaVersion { get; }
|
||||
|
||||
CultMeshRouteHint RouteHint { get; }
|
||||
|
||||
System.Collections.Generic.IReadOnlyList<CultMeshProjectionSource> Sources { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaClientState
|
||||
{
|
||||
private readonly IReadOnlyDictionary<Type, object> _documentsByType;
|
||||
private readonly IReadOnlyDictionary<string, IAetheriaRuntimeProjectedDocument> _documentsBySchema;
|
||||
|
||||
internal AetheriaClientState(
|
||||
AetheriaRuntimeProjectedDocument<AetheriaRuntimeCurrentZoneDocument> currentZone,
|
||||
|
|
@ -108,6 +134,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
[typeof(AetheriaRuntimeSectorMapDocument)] = SectorMap,
|
||||
[typeof(AetheriaRuntimeZoneRenderDocument)] = ZoneRender
|
||||
};
|
||||
_documentsBySchema = BuildSchemaIndex(_documentsByType.Values);
|
||||
}
|
||||
|
||||
public AetheriaClientCurrentState Current { get; }
|
||||
|
|
@ -120,6 +147,29 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
public AetheriaRuntimeProjectedDocument<AetheriaRuntimeZoneRenderDocument> ZoneRender { get; }
|
||||
|
||||
public bool TryGetDocumentBySchema(
|
||||
string schemaVersion,
|
||||
out IAetheriaRuntimeProjectedDocument document)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(schemaVersion) &&
|
||||
_documentsBySchema.TryGetValue(schemaVersion, out document!))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
document = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public IAetheriaRuntimeProjectedDocument DocumentBySchema(string schemaVersion)
|
||||
{
|
||||
if (TryGetDocumentBySchema(schemaVersion, out var document))
|
||||
return document;
|
||||
|
||||
throw new NotSupportedException(
|
||||
$"Aetheria typed state does not expose a projected document for schema '{schemaVersion}'.");
|
||||
}
|
||||
|
||||
public bool TryGetDocument<TDocument>(
|
||||
out AetheriaRuntimeProjectedDocument<TDocument> document)
|
||||
{
|
||||
|
|
@ -130,6 +180,15 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return true;
|
||||
}
|
||||
|
||||
var schemaVersion = SchemaVersionFor(typeof(TDocument));
|
||||
if (!string.IsNullOrWhiteSpace(schemaVersion) &&
|
||||
_documentsBySchema.TryGetValue(schemaVersion, out var schemaDocument) &&
|
||||
schemaDocument is AetheriaRuntimeProjectedDocument<TDocument> schemaTypedDocument)
|
||||
{
|
||||
document = schemaTypedDocument;
|
||||
return true;
|
||||
}
|
||||
|
||||
document = null!;
|
||||
return false;
|
||||
}
|
||||
|
|
@ -157,6 +216,29 @@ namespace GameCult.Aetheria.State.Verse
|
|||
{
|
||||
return Document<TDocument>().Watch(onNext);
|
||||
}
|
||||
|
||||
private static IReadOnlyDictionary<string, IAetheriaRuntimeProjectedDocument> BuildSchemaIndex(
|
||||
IEnumerable<object> documents)
|
||||
{
|
||||
var index = new Dictionary<string, IAetheriaRuntimeProjectedDocument>(StringComparer.Ordinal);
|
||||
foreach (var document in documents)
|
||||
{
|
||||
if (document is not IAetheriaRuntimeProjectedDocument projectedDocument)
|
||||
continue;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(projectedDocument.SchemaVersion))
|
||||
index[projectedDocument.SchemaVersion] = projectedDocument;
|
||||
if (!string.IsNullOrWhiteSpace(projectedDocument.SchemaName))
|
||||
index[projectedDocument.SchemaName] = projectedDocument;
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
|
||||
private static string SchemaVersionFor(Type documentType)
|
||||
{
|
||||
return documentType.GetCustomAttribute<CultDocumentAttribute>()?.SchemaVersion ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class AetheriaClientCurrentState
|
||||
|
|
|
|||
Loading…
Reference in a new issue