Build typed Aetheria client surfaces
This commit is contained in:
parent
74b3b3d72a
commit
2e96660d48
246 changed files with 37893 additions and 6728 deletions
106
Assets/Scripts/Gameplay/AetheriaUnityObservedDockingIndex.cs
Normal file
106
Assets/Scripts/Gameplay/AetheriaUnityObservedDockingIndex.cs
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
|
||||
public sealed class AetheriaUnityObservedDockingIndex
|
||||
{
|
||||
private readonly Func<AetheriaClient> _resolveClient;
|
||||
private readonly AetheriaUnityObservedFacadeIndex _observedFacadeIndex;
|
||||
|
||||
public AetheriaUnityObservedDockingIndex(
|
||||
Func<AetheriaClient> resolveClient,
|
||||
AetheriaUnityObservedFacadeIndex observedFacadeIndex)
|
||||
{
|
||||
_resolveClient = resolveClient ?? throw new ArgumentNullException(nameof(resolveClient));
|
||||
_observedFacadeIndex = observedFacadeIndex ?? throw new ArgumentNullException(nameof(observedFacadeIndex));
|
||||
}
|
||||
|
||||
public int ResolveEntityZoneIndex(Entity entity)
|
||||
{
|
||||
return TryResolveCurrentDocking(entity, out var docking)
|
||||
? docking.ZoneIndex
|
||||
: -1;
|
||||
}
|
||||
|
||||
public bool IsEntityUndocked(Entity entity)
|
||||
{
|
||||
return TryResolveCurrentDocking(entity, out var docking) &&
|
||||
!docking.IsDocked;
|
||||
}
|
||||
|
||||
public bool TryResolveDockingBay(
|
||||
Entity child,
|
||||
out Entity dockParent,
|
||||
out EquippedDockingBay dockingBay)
|
||||
{
|
||||
return TryResolveDockingBay(child, out dockParent, out dockingBay, out _);
|
||||
}
|
||||
|
||||
public bool TryResolveDockingBay(
|
||||
Entity child,
|
||||
out Entity dockParent,
|
||||
out EquippedDockingBay dockingBay,
|
||||
out AetheriaRuntimeCurrentDockingDocument docking)
|
||||
{
|
||||
dockParent = null;
|
||||
dockingBay = null;
|
||||
docking = null;
|
||||
if (!TryResolveCurrentDocking(child, out docking) || !docking.IsDocked)
|
||||
return false;
|
||||
|
||||
if (!_observedFacadeIndex.TryResolveEntityByRecordKey(docking.DockParentEntityKey, out var parent) ||
|
||||
!(parent is OrbitalEntity))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (parent.DockingBays == null ||
|
||||
docking.DockingBayIndex < 0 ||
|
||||
docking.DockingBayIndex >= parent.DockingBays.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dockParent = parent;
|
||||
dockingBay = parent.DockingBays[docking.DockingBayIndex];
|
||||
return dockingBay != null;
|
||||
}
|
||||
|
||||
private bool TryResolveCurrentDocking(
|
||||
Entity entity,
|
||||
out AetheriaRuntimeCurrentDockingDocument docking)
|
||||
{
|
||||
docking = ReadCurrentDocking();
|
||||
if (entity == null ||
|
||||
docking == null ||
|
||||
docking.CurrentEntityIndex != entity.DaemonEntityIndex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_observedFacadeIndex.TryResolveEntityRecordKey(entity, out var entityKey) &&
|
||||
!string.IsNullOrWhiteSpace(docking.CurrentEntityKey) &&
|
||||
!string.Equals(docking.CurrentEntityKey, entityKey, StringComparison.Ordinal))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private AetheriaRuntimeCurrentDockingDocument ReadCurrentDocking()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _resolveClient()?.CurrentDockingAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue