125 lines
4.8 KiB
C#
125 lines
4.8 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using GameCult.Mesh;
|
|
using R3;
|
|
|
|
#nullable enable
|
|
|
|
namespace GameCult.Aetheria.State.Verse
|
|
{
|
|
public sealed class AetheriaClientState
|
|
{
|
|
private readonly CultMeshDocumentCatalog _documents;
|
|
|
|
internal AetheriaClientState(
|
|
CultMeshDocumentHandle<AetheriaRuntimeCurrentZoneDocument> currentZone,
|
|
CultMeshDocumentHandle<AetheriaRuntimeCurrentEntityDocument> currentEntity,
|
|
CultMeshDocumentHandle<AetheriaRuntimeCurrentDockingDocument> currentDocking,
|
|
CultMeshDocumentHandle<AetheriaRuntimeZoneContactsDocument> zoneContacts,
|
|
CultMeshDocumentHandle<AetheriaRuntimeStationRefitDocument> stationRefit,
|
|
CultMeshDocumentHandle<AetheriaRuntimeSectorMapDocument> sectorMap,
|
|
CultMeshDocumentHandle<AetheriaRuntimeZoneRenderDocument> zoneRender)
|
|
{
|
|
Current = new AetheriaClientCurrentState(currentZone, currentEntity, currentDocking);
|
|
ZoneContacts = zoneContacts ?? throw new ArgumentNullException(nameof(zoneContacts));
|
|
StationRefit = stationRefit ?? throw new ArgumentNullException(nameof(stationRefit));
|
|
SectorMap = sectorMap ?? throw new ArgumentNullException(nameof(sectorMap));
|
|
ZoneRender = zoneRender ?? throw new ArgumentNullException(nameof(zoneRender));
|
|
_documents = CultMesh.Documents(
|
|
Current.Zone,
|
|
Current.Entity,
|
|
Current.Docking,
|
|
ZoneContacts,
|
|
StationRefit,
|
|
SectorMap,
|
|
ZoneRender);
|
|
}
|
|
|
|
public AetheriaClientCurrentState Current { get; }
|
|
|
|
public CultMeshDocumentHandle<AetheriaRuntimeZoneContactsDocument> ZoneContacts { get; }
|
|
|
|
public CultMeshDocumentHandle<AetheriaRuntimeStationRefitDocument> StationRefit { get; }
|
|
|
|
public CultMeshDocumentHandle<AetheriaRuntimeSectorMapDocument> SectorMap { get; }
|
|
|
|
public CultMeshDocumentHandle<AetheriaRuntimeZoneRenderDocument> ZoneRender { get; }
|
|
|
|
public bool TryGetDocumentBySchema(
|
|
string schemaVersion,
|
|
out ICultMeshDocumentHandle document)
|
|
{
|
|
return _documents.TryGetDocumentBySchema(schemaVersion, out document);
|
|
}
|
|
|
|
public ICultMeshDocumentHandle 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 CultMeshDocumentHandle<TDocument> document)
|
|
where TDocument : class
|
|
{
|
|
return _documents.TryGetDocument(out document);
|
|
}
|
|
|
|
public CultMeshDocumentHandle<TDocument> Document<TDocument>()
|
|
where TDocument : class
|
|
{
|
|
if (TryGetDocument<TDocument>(out var document))
|
|
return document;
|
|
|
|
throw new NotSupportedException(
|
|
$"Aetheria typed state does not expose a projected document for {typeof(TDocument).FullName}.");
|
|
}
|
|
|
|
public Task<TDocument> LatestAsync<TDocument>()
|
|
where TDocument : class
|
|
{
|
|
return Document<TDocument>().LatestAsync();
|
|
}
|
|
|
|
public TDocument Latest<TDocument>()
|
|
where TDocument : class
|
|
{
|
|
return Document<TDocument>().LatestAsync().ConfigureAwait(false).GetAwaiter().GetResult();
|
|
}
|
|
|
|
public Observable<TDocument> Watch<TDocument>()
|
|
where TDocument : class
|
|
{
|
|
return Document<TDocument>().Watch();
|
|
}
|
|
|
|
public IDisposable Watch<TDocument>(Action<TDocument> onNext)
|
|
where TDocument : class
|
|
{
|
|
if (onNext == null) throw new ArgumentNullException(nameof(onNext));
|
|
return Document<TDocument>().Watch(onNext);
|
|
}
|
|
}
|
|
|
|
public sealed class AetheriaClientCurrentState
|
|
{
|
|
internal AetheriaClientCurrentState(
|
|
CultMeshDocumentHandle<AetheriaRuntimeCurrentZoneDocument> zone,
|
|
CultMeshDocumentHandle<AetheriaRuntimeCurrentEntityDocument> entity,
|
|
CultMeshDocumentHandle<AetheriaRuntimeCurrentDockingDocument> docking)
|
|
{
|
|
Zone = zone ?? throw new ArgumentNullException(nameof(zone));
|
|
Entity = entity ?? throw new ArgumentNullException(nameof(entity));
|
|
Docking = docking ?? throw new ArgumentNullException(nameof(docking));
|
|
}
|
|
|
|
public CultMeshDocumentHandle<AetheriaRuntimeCurrentZoneDocument> Zone { get; }
|
|
|
|
public CultMeshDocumentHandle<AetheriaRuntimeCurrentEntityDocument> Entity { get; }
|
|
|
|
public CultMeshDocumentHandle<AetheriaRuntimeCurrentDockingDocument> Docking { get; }
|
|
}
|
|
}
|