Centralize player HUD state access
This commit is contained in:
parent
649f526958
commit
43f92f2b7b
7 changed files with 108 additions and 65 deletions
|
|
@ -299,6 +299,27 @@ namespace GameCult.Aetheria.State.Verse
|
|||
: null;
|
||||
}
|
||||
|
||||
public AetheriaRuntimePlayerHudSession ObservePlayerHud(
|
||||
CultMeshReactiveDocumentOptions? options = null)
|
||||
{
|
||||
var catalog = ReactiveCatalog(options);
|
||||
CultMeshReactiveDocument<AetheriaRuntimePlayerSettingsDocument>? playerSettings = null;
|
||||
CultMeshReactiveDocument<AetheriaRuntimeCurrentEntityDocument>? currentEntity = null;
|
||||
try
|
||||
{
|
||||
playerSettings = Settings.ReactivePlayer(options);
|
||||
currentEntity = Current.ReactiveEntity(options);
|
||||
return new AetheriaRuntimePlayerHudSession(catalog, playerSettings, currentEntity);
|
||||
}
|
||||
catch
|
||||
{
|
||||
catalog.Dispose();
|
||||
playerSettings?.Dispose();
|
||||
currentEntity?.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private CultMeshReactiveDocument<AetheriaRuntimeDaemonSoaViewDocument>? TryReactiveDaemonSoaView(
|
||||
CultMeshReactiveDocumentOptions? options)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
using GameCult.Mesh;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Verse
|
||||
{
|
||||
public sealed class AetheriaRuntimePlayerHudSession : IDisposable
|
||||
{
|
||||
private readonly CultMeshReactiveDocument<AetheriaRuntimeCatalogSnapshot> _catalog;
|
||||
private readonly CultMeshReactiveDocument<AetheriaRuntimePlayerSettingsDocument> _playerSettings;
|
||||
private readonly CultMeshReactiveDocument<AetheriaRuntimeCurrentEntityDocument> _currentEntity;
|
||||
|
||||
public AetheriaRuntimePlayerHudSession(
|
||||
CultMeshReactiveDocument<AetheriaRuntimeCatalogSnapshot> catalog,
|
||||
CultMeshReactiveDocument<AetheriaRuntimePlayerSettingsDocument> playerSettings,
|
||||
CultMeshReactiveDocument<AetheriaRuntimeCurrentEntityDocument> currentEntity)
|
||||
{
|
||||
_catalog = catalog ?? throw new ArgumentNullException(nameof(catalog));
|
||||
_playerSettings = playerSettings ?? throw new ArgumentNullException(nameof(playerSettings));
|
||||
_currentEntity = currentEntity ?? throw new ArgumentNullException(nameof(currentEntity));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogSnapshot? Catalog => _catalog.Current;
|
||||
public AetheriaRuntimePlayerSettingsDocument? PlayerSettings => _playerSettings.Current;
|
||||
public AetheriaRuntimeCurrentEntityDocument? CurrentEntity => _currentEntity.Current;
|
||||
public AetheriaRuntimeCurrentEntityHudStatus Hud =>
|
||||
CurrentEntity?.Hud ?? new AetheriaRuntimeCurrentEntityHudStatus();
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_catalog.Dispose();
|
||||
_playerSettings.Dispose();
|
||||
_currentEntity.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0525c14d10a54fd2b92fbf9984a41dc0
|
||||
Loading…
Reference in a new issue