Centralize observed docking document resolution

This commit is contained in:
Meta Vens 2026-06-27 16:07:46 +01:00
commit c6e75ef4b8
3 changed files with 136 additions and 144 deletions

View file

@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
using System;
using System.Linq;
using GameCult.Aetheria.State.Verse;
public sealed class AetheriaUnityObservedDockingIndex
@ -31,6 +32,66 @@ public sealed class AetheriaUnityObservedDockingIndex
!docking.IsDocked;
}
public bool TryResolveCurrentEntity(out Entity entity)
{
entity = null;
return TryResolveCurrentEntityKey(out var currentEntityKey) &&
_observedFacadeIndex.TryResolveEntityByRecordKey(currentEntityKey, out entity);
}
public bool TryResolveCurrentEntityKey(out string currentEntityKey)
{
currentEntityKey = ReadCurrentEntity()?.EntityKey ?? "";
return !string.IsNullOrWhiteSpace(currentEntityKey);
}
public bool TryResolveCurrentEntityDocument(out AetheriaRuntimeCurrentEntityDocument currentEntity)
{
currentEntity = ReadCurrentEntity();
return currentEntity != null;
}
public AetheriaRuntimeStationRefitDocument ResolveStationRefit()
{
return ReadStationRefit();
}
public bool TryResolveCurrentDockingBayRow(out AetheriaRuntimeStationDockingBayRow dockingBay)
{
dockingBay = null;
var stationRefit = ReadStationRefit();
if (stationRefit?.IsDocked != true || stationRefit.DockingBayIndex < 0)
return false;
dockingBay = (stationRefit.DockingBays ?? Array.Empty<AetheriaRuntimeStationDockingBayRow>())
.FirstOrDefault(row => row != null && row.DockingBayIndex == stationRefit.DockingBayIndex);
return dockingBay != null;
}
public bool TryResolveCurrentDockingBay(out EquippedDockingBay dockingBay)
{
dockingBay = null;
var stationRefit = ReadStationRefit();
var dockParentEntityKey = stationRefit?.DockParentEntityKey ?? "";
if (!TryResolveCurrentDockingBayRow(out var dockingBayRow) ||
string.IsNullOrWhiteSpace(dockParentEntityKey) ||
!_observedFacadeIndex.TryResolveDockingBayByRecordKey(
dockParentEntityKey,
dockingBayRow.DockingBayIndex,
out dockingBay))
{
return false;
}
return dockingBay != null;
}
public bool TryResolveCurrentDocking(out AetheriaRuntimeCurrentDockingDocument docking)
{
docking = ReadCurrentDocking();
return docking != null;
}
public bool TryResolveDockingBay(
Entity child,
out Entity dockParent,
@ -99,9 +160,38 @@ public sealed class AetheriaUnityObservedDockingIndex
?.Aetheria()
.Current
.Docking
.LatestAsync()
.GetAwaiter()
.GetResult();
.Latest();
}
catch
{
return null;
}
}
private AetheriaRuntimeCurrentEntityDocument ReadCurrentEntity()
{
try
{
return _resolveClient()
?.Aetheria()
.Current
.Entity
.Latest();
}
catch
{
return null;
}
}
private AetheriaRuntimeStationRefitDocument ReadStationRefit()
{
try
{
return _resolveClient()
?.Aetheria()
.StationRefit
.Latest();
}
catch
{

View file

@ -726,113 +726,60 @@ public class InventoryMenu : MonoBehaviour
private bool TryGetTypedCurrentEntityFacade(out Entity entity)
{
entity = null;
if (_observedFacadeIndex == null ||
!TryResolveCurrentEntityKey(out var currentEntityKey))
{
return false;
}
return _observedFacadeIndex.TryResolveEntityByRecordKey(currentEntityKey, out entity);
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentEntity(out entity);
}
private bool TryGetTypedCurrentDockingBayFacade(out EquippedDockingBay dockingBay)
{
dockingBay = null;
var stationRefit = ResolveStationRefit();
var dockParentEntityKey = stationRefit?.DockParentEntityKey ?? "";
if (_observedFacadeIndex == null ||
!TryResolveCurrentDockingBayRow(out var dockingBayRow) ||
string.IsNullOrWhiteSpace(dockParentEntityKey) ||
!_observedFacadeIndex.TryResolveDockingBayByRecordKey(
dockParentEntityKey,
dockingBayRow.DockingBayIndex,
out dockingBay))
{
return false;
}
return dockingBay != null;
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentDockingBay(out dockingBay);
}
private bool TryResolveCurrentDockingBayRow(out AetheriaRuntimeStationDockingBayRow dockingBay)
{
dockingBay = null;
var stationRefit = ResolveStationRefit();
if (stationRefit?.IsDocked != true || stationRefit.DockingBayIndex < 0)
return false;
dockingBay = (stationRefit.DockingBays ?? Array.Empty<AetheriaRuntimeStationDockingBayRow>())
.FirstOrDefault(row => row != null && row.DockingBayIndex == stationRefit.DockingBayIndex);
return dockingBay != null;
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentDockingBayRow(out dockingBay);
}
private bool TryResolveCurrentEntityKey(out string currentEntityKey)
{
currentEntityKey = "";
if (!TryResolveCurrentEntityDocument(out var currentEntity))
return false;
currentEntityKey = currentEntity?.EntityKey ?? "";
return !string.IsNullOrWhiteSpace(currentEntityKey);
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentEntityKey(out currentEntityKey);
}
private bool TryResolveCurrentEntityDocument(out AetheriaRuntimeCurrentEntityDocument currentEntity)
{
currentEntity = null;
try
{
currentEntity = ResolveClient()
.Aetheria()
.Current
.Entity
.Latest();
}
catch (Exception ex)
{
Debug.LogWarning($"Failed to read Aetheria current entity for inventory menu: {ex.Message}");
return false;
}
return currentEntity != null;
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentEntityDocument(out currentEntity);
}
private AetheriaRuntimeStationRefitDocument ResolveStationRefit()
{
try
{
return ResolveClient()
.Aetheria()
.StationRefit
.Latest();
}
catch (Exception ex)
{
Debug.LogWarning($"Failed to read Aetheria station refit projection for inventory menu: {ex.Message}");
return null;
}
return TryResolveObservedDockingIndex(out var dockingIndex)
? dockingIndex.ResolveStationRefit()
: null;
}
private bool TryResolveCurrentDocking(out AetheriaRuntimeCurrentDockingDocument docking)
{
docking = null;
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentDocking(out docking);
}
try
{
docking = ResolveClient()
.Aetheria()
.Current
.Docking
.Latest();
}
catch (Exception ex)
{
Debug.LogWarning($"Failed to read Aetheria current docking for inventory menu: {ex.Message}");
private bool TryResolveObservedDockingIndex(out AetheriaUnityObservedDockingIndex dockingIndex)
{
dockingIndex = null;
if (_observedFacadeIndex == null)
return false;
}
return docking != null;
dockingIndex = new AetheriaUnityObservedDockingIndex(ResolveClient, _observedFacadeIndex);
return true;
}
private bool TryResolveCargoBay(EquippedCargoBay cargoBay, out string entityKey, out int cargoIndex)

View file

@ -1132,91 +1132,46 @@ private void Update()
private bool TryResolveCurrentEntityKey(out string currentEntityKey)
{
currentEntityKey = "";
try
{
currentEntityKey = ResolveClient()
.Aetheria()
.Current
.Entity
.Latest()
?.EntityKey ?? "";
}
catch (Exception ex)
{
Debug.LogWarning($"Failed to read Aetheria current entity for inventory panel: {ex.Message}");
return false;
}
return !string.IsNullOrWhiteSpace(currentEntityKey);
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentEntityKey(out currentEntityKey);
}
private bool TryGetTypedCurrentDockingBayFacade(out EquippedDockingBay dockingBay)
{
dockingBay = null;
var stationRefit = ResolveStationRefit();
var dockParentEntityKey = stationRefit?.DockParentEntityKey ?? "";
if (_observedFacadeIndex == null ||
!TryResolveCurrentDockingBayRow(out var dockingBayRow) ||
string.IsNullOrWhiteSpace(dockParentEntityKey) ||
!_observedFacadeIndex.TryResolveDockingBayByRecordKey(
dockParentEntityKey,
dockingBayRow.DockingBayIndex,
out dockingBay))
{
return false;
}
return dockingBay != null;
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentDockingBay(out dockingBay);
}
private bool TryResolveCurrentDockingBayRow(out AetheriaRuntimeStationDockingBayRow dockingBay)
{
dockingBay = null;
var stationRefit = ResolveStationRefit();
if (stationRefit?.IsDocked != true || stationRefit.DockingBayIndex < 0)
return false;
dockingBay = (stationRefit.DockingBays ?? Array.Empty<AetheriaRuntimeStationDockingBayRow>())
.FirstOrDefault(row => row != null && row.DockingBayIndex == stationRefit.DockingBayIndex);
return dockingBay != null;
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentDockingBayRow(out dockingBay);
}
private bool TryResolveCurrentDocking(out AetheriaRuntimeCurrentDockingDocument docking)
{
docking = null;
try
{
docking = ResolveClient()
.Aetheria()
.Current
.Docking
.Latest();
}
catch (Exception ex)
{
Debug.LogWarning($"Failed to read Aetheria current docking for inventory panel: {ex.Message}");
return false;
}
return docking != null;
return TryResolveObservedDockingIndex(out var dockingIndex) &&
dockingIndex.TryResolveCurrentDocking(out docking);
}
private AetheriaRuntimeStationRefitDocument ResolveStationRefit()
{
try
{
return ResolveClient()
.Aetheria()
.StationRefit
.Latest();
}
catch (Exception ex)
{
Debug.LogWarning($"Failed to read Aetheria station refit projection for inventory panel: {ex.Message}");
return null;
}
return TryResolveObservedDockingIndex(out var dockingIndex)
? dockingIndex.ResolveStationRefit()
: null;
}
private bool TryResolveObservedDockingIndex(out AetheriaUnityObservedDockingIndex dockingIndex)
{
dockingIndex = null;
if (_observedFacadeIndex == null)
return false;
dockingIndex = new AetheriaUnityObservedDockingIndex(ResolveClient, _observedFacadeIndex);
return true;
}
private bool TryResolveStationRefitEntity(string entityKey, int optionIndex, out Entity entity)