diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 3c102d163..0ecf920dd 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -4773,8 +4773,8 @@ static void RequireRuntimeMenuTabsUseEveSurface(string root) "private bool TryResolveDockedLocalStory(out LocationStory story)", "SetObservedFacadeIndex(AetheriaUnityObservedFacadeIndex observedFacadeIndex)", "_observedFacadeIndex.TryResolveDockingBayByRecordKey(", - "dockingState.CurrentDocking.DockParentEntityKey", - "dockingState.CurrentDocking.DockingBayIndex", + "dockingState.DockParentEntityKey", + "dockingState.DockingBayIndex", "dockingBay?.Entity is not OrbitalEntity { Story: { } dockedStory }", "AetheriaRuntimeLocalStorySurfaceBuilder.Build(ProjectStorySurface())", "AetheriaRuntimeLocalStorySurfaceBuilder.Project(", diff --git a/Assets/Scripts/Gameplay/AetheriaUnityObservedDockingIndex.cs b/Assets/Scripts/Gameplay/AetheriaUnityObservedDockingIndex.cs index 887d11a8f..e79359372 100644 --- a/Assets/Scripts/Gameplay/AetheriaUnityObservedDockingIndex.cs +++ b/Assets/Scripts/Gameplay/AetheriaUnityObservedDockingIndex.cs @@ -75,11 +75,11 @@ public sealed class AetheriaUnityObservedDockingIndex dockingBay = null; if (!TryResolveCurrentDockingSnapshot(out var snapshot) || snapshot.CurrentDockingBay == null || - snapshot.StationRefit == null || - string.IsNullOrWhiteSpace(snapshot.StationRefit.DockParentEntityKey) || + string.IsNullOrWhiteSpace(snapshot.DockParentEntityKey) || + snapshot.DockingBayIndex < 0 || !_observedFacadeIndex.TryResolveDockingBayByRecordKey( - snapshot.StationRefit.DockParentEntityKey, - snapshot.CurrentDockingBay.DockingBayIndex, + snapshot.DockParentEntityKey, + snapshot.DockingBayIndex, out dockingBay)) { return false; diff --git a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs index b6b766b80..3cedc0e69 100644 --- a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs +++ b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs @@ -215,6 +215,11 @@ public class DaemonRuntimeDocumentTests using var zoneRenderReactive = client.State .Reactive(); var legacyCurrentEntity = client.CurrentEntityAsync().GetAwaiter().GetResult(); + var dockingState = client.Aetheria() + .DockingState + .LatestAsync() + .GetAwaiter() + .GetResult(); Assert.AreEqual("aetheria.current.entity", client.State.Current.Entity.DocumentId); Assert.AreSame(client.State.Current.Entity, client.State.Document()); @@ -260,6 +265,9 @@ public class DaemonRuntimeDocumentTests Assert.AreEqual(currentEntity.EntityKey, currentEntityByType.EntityKey); Assert.AreEqual(currentEntity.EntityKey, currentEntityFromClientType.EntityKey); Assert.AreEqual(legacyCurrentEntity.EntityKey, currentEntity.EntityKey); + Assert.AreEqual(currentEntity.EntityKey, dockingState.CurrentEntityKey); + Assert.AreEqual("", dockingState.DockParentEntityKey); + Assert.AreEqual(-1, dockingState.DockingBayIndex); Assert.IsTrue(client.State.Current.Entity.Sources.Any(source => source.SourceId == AetheriaRuntimeVerseRecordKeys.DaemonFrameLatest.ToString())); Assert.IsTrue(client.State.StationRefit.Sources.Any(source => diff --git a/Assets/Scripts/UI/Menu/LocalMenu.cs b/Assets/Scripts/UI/Menu/LocalMenu.cs index d2cc5f06a..ad564b18a 100644 --- a/Assets/Scripts/UI/Menu/LocalMenu.cs +++ b/Assets/Scripts/UI/Menu/LocalMenu.cs @@ -231,10 +231,11 @@ public class LocalMenu : MonoBehaviour if (_observedFacadeIndex == null || !TryResolveDockingState(out var dockingState) || dockingState?.IsDocked != true || - dockingState.CurrentDocking == null || + string.IsNullOrWhiteSpace(dockingState.DockParentEntityKey) || + dockingState.DockingBayIndex < 0 || !_observedFacadeIndex.TryResolveDockingBayByRecordKey( - dockingState.CurrentDocking.DockParentEntityKey, - dockingState.CurrentDocking.DockingBayIndex, + dockingState.DockParentEntityKey, + dockingState.DockingBayIndex, out var dockingBay) || dockingBay?.Entity is not OrbitalEntity { Story: { } dockedStory }) { diff --git a/Assets/Scripts/UI/Menu/TradeMenu.cs b/Assets/Scripts/UI/Menu/TradeMenu.cs index fcf2bf1cf..cdb67a41a 100644 --- a/Assets/Scripts/UI/Menu/TradeMenu.cs +++ b/Assets/Scripts/UI/Menu/TradeMenu.cs @@ -58,16 +58,14 @@ public class TradeMenu : MonoBehaviour private void OnEnable() { var dockingState = ResolveDockingState(); - var docking = dockingState?.CurrentDocking; if (dockingState?.IsDocked != true || - docking == null || - string.IsNullOrWhiteSpace(docking.DockParentEntityKey) || - docking.DockingBayIndex < 0) + string.IsNullOrWhiteSpace(dockingState.DockParentEntityKey) || + dockingState.DockingBayIndex < 0) { return; } - SetTargetCargo(docking.DockParentEntityKey, docking.DockingBayIndex, "Docking Bay"); + SetTargetCargo(dockingState.DockParentEntityKey, dockingState.DockingBayIndex, "Docking Bay"); HideCargoSelectorSurface(); HideFilterSurface(); HideRowActionSurface(); @@ -517,15 +515,14 @@ public class TradeMenu : MonoBehaviour private bool TryResolveCurrentDockingTargetEntityKey(out string targetEntityKey) { targetEntityKey = ""; - var docking = ResolveDockingState()?.CurrentDocking; - if (docking == null || - !docking.IsDocked || - string.IsNullOrWhiteSpace(docking.DockParentEntityKey)) + var dockingState = ResolveDockingState(); + if (dockingState?.IsDocked != true || + string.IsNullOrWhiteSpace(dockingState.DockParentEntityKey)) { return false; } - targetEntityKey = docking.DockParentEntityKey; + targetEntityKey = dockingState.DockParentEntityKey; return true; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs index 8984138f8..b6bd98dff 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaClientState.cs @@ -278,6 +278,10 @@ namespace GameCult.Aetheria.State.Verse public string CurrentEntityKey => CurrentEntity?.EntityKey ?? CurrentDocking?.CurrentEntityKey ?? ""; + public string DockParentEntityKey => StationRefit?.DockParentEntityKey ?? CurrentDocking?.DockParentEntityKey ?? ""; + + public int DockingBayIndex => CurrentDockingBay?.DockingBayIndex ?? StationRefit?.DockingBayIndex ?? CurrentDocking?.DockingBayIndex ?? -1; + public bool IsDocked => StationRefit?.IsDocked == true && CurrentDockingBay != null; }