Build typed Aetheria client surfaces
This commit is contained in:
parent
74b3b3d72a
commit
2e96660d48
246 changed files with 37893 additions and 6728 deletions
|
|
@ -45,14 +45,54 @@ public class ActionBarSlot : MonoBehaviour
|
|||
public abstract class ActionBarBinding
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
protected AetheriaClient Client { get; }
|
||||
protected ActionBarSlot Slot { get; }
|
||||
protected GameSettings Settings { get; }
|
||||
private AetheriaRuntimeCatalogSnapshot _catalog;
|
||||
public abstract void Activate();
|
||||
public abstract void Deactivate();
|
||||
public abstract void Update();
|
||||
public ActionBarBinding(Entity entity, ActionBarSlot slot)
|
||||
|
||||
protected ActionBarBinding(Entity entity, ActionBarSlot slot, AetheriaClient client, GameSettings settings)
|
||||
{
|
||||
Entity = entity;
|
||||
Slot = slot;
|
||||
Client = client;
|
||||
Settings = settings;
|
||||
}
|
||||
|
||||
protected bool TrySubmit(Action<AetheriaControl> submit, string label)
|
||||
{
|
||||
if (Client == null || submit == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
submit(Client.Control);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to send Aetheria daemon action-bar {label} operation; operation not submitted: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected AetheriaRuntimeCatalogItem FindCatalogItem(ItemInstance item)
|
||||
{
|
||||
if (item == null || string.IsNullOrWhiteSpace(item.ItemKey) || Client == null)
|
||||
return null;
|
||||
|
||||
try
|
||||
{
|
||||
_catalog ??= Client.OpenRuntimeCatalog();
|
||||
return _catalog?.FindItem(item.ItemKey);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to read Aetheria runtime catalog for action-bar binding: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +103,9 @@ public class ActionBarConsumableBinding : ActionBarBinding
|
|||
public ActionBarConsumableBinding(
|
||||
Entity entity,
|
||||
ActionBarSlot slot,
|
||||
AetheriaRuntimeCatalogItem target) : base(entity, slot)
|
||||
AetheriaClient client,
|
||||
GameSettings settings,
|
||||
AetheriaRuntimeCatalogItem target) : base(entity, slot, client, settings)
|
||||
{
|
||||
Target = target;
|
||||
Slot.QuantityRemaining.gameObject.SetActive(true);
|
||||
|
|
@ -73,7 +115,9 @@ public class ActionBarConsumableBinding : ActionBarBinding
|
|||
|
||||
public override void Activate()
|
||||
{
|
||||
ActionGameManager.Instance.RequestActionBarConsumable(TargetItemKey);
|
||||
TrySubmit(
|
||||
operations => operations.ActivateConsumable(TargetItemKey),
|
||||
"consumable");
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
|
|
@ -111,7 +155,13 @@ public class ActionBarGearBinding : ActionBarBinding
|
|||
|
||||
public string TargetItemKey => Item?.EquippableItem?.ItemKey ?? "";
|
||||
|
||||
public ActionBarGearBinding(Entity entity, ActionBarSlot slot, EquippedItem item, IActivatedBehavior behavior) : base(entity, slot)
|
||||
public ActionBarGearBinding(
|
||||
Entity entity,
|
||||
ActionBarSlot slot,
|
||||
AetheriaClient client,
|
||||
GameSettings settings,
|
||||
EquippedItem item,
|
||||
IActivatedBehavior behavior) : base(entity, slot, client, settings)
|
||||
{
|
||||
Item = item;
|
||||
Behavior = behavior;
|
||||
|
|
@ -123,7 +173,7 @@ public class ActionBarGearBinding : ActionBarBinding
|
|||
|
||||
private Texture2D ResolveIconTexture()
|
||||
{
|
||||
var typedItem = FindTypedGearItem(Item.EquippableItem);
|
||||
var typedItem = FindCatalogItem(Item.EquippableItem);
|
||||
if (typedItem != null)
|
||||
{
|
||||
var actionBarIcon = LoadActionBarIcon(typedItem.ActionBarIcon);
|
||||
|
|
@ -131,13 +181,13 @@ public class ActionBarGearBinding : ActionBarBinding
|
|||
return actionBarIcon;
|
||||
|
||||
if (Enum.TryParse<WeaponType>(typedItem.WeaponType, out var weaponType))
|
||||
return ActionGameManager.Instance.Settings.GetIcon(weaponType).texture;
|
||||
return Settings.GetIcon(weaponType).texture;
|
||||
|
||||
if (Enum.TryParse<HardpointType>(typedItem.HardpointType, out var hardpointType))
|
||||
return ActionGameManager.Instance.Settings.GetIcon(hardpointType).texture;
|
||||
return Settings.GetIcon(hardpointType).texture;
|
||||
}
|
||||
|
||||
return ActionGameManager.Instance.Settings.GetIcon(HardpointType.Tool).texture;
|
||||
return Settings.GetIcon(HardpointType.Tool).texture;
|
||||
}
|
||||
|
||||
private static Texture2D LoadActionBarIcon(string path)
|
||||
|
|
@ -154,21 +204,20 @@ public class ActionBarGearBinding : ActionBarBinding
|
|||
return Resources.Load<Texture2D>(resourcePath);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCatalogItem FindTypedGearItem(ItemInstance item)
|
||||
{
|
||||
return ActionGameManager.RuntimeCatalog?.FindItem(item?.ItemKey ?? "");
|
||||
}
|
||||
|
||||
public override void Activate()
|
||||
{
|
||||
Active = true;
|
||||
ActionGameManager.Instance.RequestActionBarBehavior(EquipmentIndex, BehaviorIndex, true);
|
||||
TrySubmit(
|
||||
operations => operations.SetBehaviorActive(EquipmentIndex, BehaviorIndex, true),
|
||||
"behavior activation");
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
{
|
||||
Active = false;
|
||||
ActionGameManager.Instance.RequestActionBarBehavior(EquipmentIndex, BehaviorIndex, false);
|
||||
TrySubmit(
|
||||
operations => operations.SetBehaviorActive(EquipmentIndex, BehaviorIndex, false),
|
||||
"behavior activation");
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
|
|
@ -181,7 +230,12 @@ public class ActionBarWeaponGroupBinding : ActionBarBinding
|
|||
{
|
||||
public int Group;
|
||||
|
||||
public ActionBarWeaponGroupBinding(Entity entity, ActionBarSlot slot, int group) : base(entity, slot)
|
||||
public ActionBarWeaponGroupBinding(
|
||||
Entity entity,
|
||||
ActionBarSlot slot,
|
||||
AetheriaClient client,
|
||||
GameSettings settings,
|
||||
int group) : base(entity, slot, client, settings)
|
||||
{
|
||||
Group = group;
|
||||
slot.Label.gameObject.SetActive(true);
|
||||
|
|
@ -191,12 +245,16 @@ public class ActionBarWeaponGroupBinding : ActionBarBinding
|
|||
|
||||
public override void Activate()
|
||||
{
|
||||
ActionGameManager.Instance.RequestActionBarWeaponGroup(Group, true);
|
||||
TrySubmit(
|
||||
operations => operations.SetWeaponGroupActive(Group, true),
|
||||
"weapon-group");
|
||||
}
|
||||
|
||||
public override void Deactivate()
|
||||
{
|
||||
ActionGameManager.Instance.RequestActionBarWeaponGroup(Group, false);
|
||||
TrySubmit(
|
||||
operations => operations.SetWeaponGroupActive(Group, false),
|
||||
"weapon-group");
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -18,10 +18,8 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
|
|||
|
||||
private readonly AetheriaRuntimeDaemonObservationCursor _cursor = new AetheriaRuntimeDaemonObservationCursor();
|
||||
private float _nextPollTime;
|
||||
private AetheriaRuntimeDaemonOperationClient _operationClient;
|
||||
private AetheriaRuntimeDaemonOperationsClient _operations;
|
||||
private AetheriaRuntimeVerseClient _verseClient;
|
||||
private string _verseClientStatePath;
|
||||
private AetheriaClient _client;
|
||||
private string _clientStatePath;
|
||||
private AetheriaDaemonSoaMemoryMap _soaMemoryMap;
|
||||
private AetheriaDaemonRenderNativeView _renderNativeView;
|
||||
|
||||
|
|
@ -36,34 +34,11 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
|
|||
public AetheriaDaemonSoaMemoryMap LastSoaMemoryMap => _soaMemoryMap;
|
||||
public AetheriaDaemonRenderNativeView LastRenderNativeView => _renderNativeView;
|
||||
public bool HasRenderNativeView => _renderNativeView.IsCreated;
|
||||
public AetheriaRuntimeDaemonOperationsClient Operations =>
|
||||
_operations ??= new AetheriaRuntimeDaemonOperationsClient(SendOperation);
|
||||
public AetheriaClient Client => ResolveClient();
|
||||
public AetheriaControl Control => Client.Control;
|
||||
|
||||
public event Action<AetheriaRuntimeObservedDaemonState, AetheriaRuntimeDaemonObservationResult> ObservedDaemonStateChanged;
|
||||
|
||||
internal AetheriaRuntimeDaemonCommandEnvelope SendOperation(
|
||||
Func<AetheriaRuntimeDaemonOperationClient, AetheriaRuntimeObservedDaemonState, AetheriaRuntimeDaemonCommandEnvelope> submit)
|
||||
{
|
||||
if (submit == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(submit));
|
||||
}
|
||||
|
||||
_operationClient ??= new AetheriaRuntimeDaemonOperationClient(
|
||||
ActionGameManager.RuntimeStateFilePath,
|
||||
clientId,
|
||||
LastObservedState?.Frame.SessionId ?? "local");
|
||||
|
||||
var envelope = submit(_operationClient, LastObservedState);
|
||||
|
||||
if (logChanges)
|
||||
{
|
||||
Debug.Log($"Submitted Aetheria daemon operation {envelope.Kind}: {envelope.CommandId}");
|
||||
}
|
||||
|
||||
return envelope;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!pollInUpdate || Time.unscaledTime < _nextPollTime)
|
||||
|
|
@ -117,38 +92,42 @@ public sealed class AetheriaDaemonObserver : MonoBehaviour
|
|||
|
||||
private void OnDisable()
|
||||
{
|
||||
DisposeVerseClient();
|
||||
DisposeClient();
|
||||
DisposeSoaMemoryMap();
|
||||
}
|
||||
|
||||
private AetheriaRuntimeObservedDaemonState ReadObservedDaemonState()
|
||||
{
|
||||
var client = ResolveVerseClient();
|
||||
return client.GetObservedDaemonStateAsync().GetAwaiter().GetResult();
|
||||
return ResolveClient().ObserveAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
private AetheriaRuntimeVerseClient ResolveVerseClient()
|
||||
private AetheriaClient ResolveClient()
|
||||
{
|
||||
var statePath = ActionGameManager.RuntimeStateFilePath;
|
||||
if (_verseClient != null && string.Equals(_verseClientStatePath, statePath, StringComparison.Ordinal))
|
||||
var statePath = AetheriaUnityRuntimePaths.RuntimeStateFilePath;
|
||||
if (_client != null && string.Equals(_clientStatePath, statePath, StringComparison.Ordinal))
|
||||
{
|
||||
return _verseClient;
|
||||
return _client;
|
||||
}
|
||||
|
||||
DisposeVerseClient();
|
||||
_verseClient = AetheriaRuntimeVerseClient
|
||||
.OpenAsync(statePath, clientId, startServer: false, pullOnOpen: true)
|
||||
DisposeClient();
|
||||
_client = AetheriaClient
|
||||
.OpenAsync(
|
||||
statePath,
|
||||
clientId,
|
||||
LastObservedState?.Frame.SessionId ?? "local",
|
||||
startServer: false,
|
||||
pullOnOpen: true)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
_verseClientStatePath = statePath;
|
||||
return _verseClient;
|
||||
_clientStatePath = statePath;
|
||||
return _client;
|
||||
}
|
||||
|
||||
private void DisposeVerseClient()
|
||||
private void DisposeClient()
|
||||
{
|
||||
_verseClient?.Dispose();
|
||||
_verseClient = null;
|
||||
_verseClientStatePath = null;
|
||||
_client?.Dispose();
|
||||
_client = null;
|
||||
_clientStatePath = null;
|
||||
}
|
||||
|
||||
private void RemapSoaView(AetheriaRuntimeObservedDaemonState observed)
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c70095f8b49f42446aa3b0b9cb76356f
|
||||
|
|
@ -140,9 +140,7 @@ public sealed class AetheriaDaemonRenderBuffer : MonoBehaviour
|
|||
using var writtenCount = new NativeArray<int>(1, Allocator.TempJob);
|
||||
var job = new AetheriaDaemonRenderGroupMatrixJob
|
||||
{
|
||||
PositionX = view.PositionX,
|
||||
PositionY = view.PositionY,
|
||||
PositionZ = view.PositionZ,
|
||||
Position = view.Position,
|
||||
RotationRadians = view.RotationRadians,
|
||||
PhysicsBodyRadius = view.PhysicsBodyRadius,
|
||||
RenderScale = view.RenderScale,
|
||||
|
|
|
|||
|
|
@ -104,9 +104,7 @@ public sealed class AetheriaDaemonRenderGroupBatch : IDisposable
|
|||
using var writtenCount = new NativeArray<int>(1, Allocator.TempJob);
|
||||
var job = new AetheriaDaemonRenderGroupMatrixJob
|
||||
{
|
||||
PositionX = view.PositionX,
|
||||
PositionY = view.PositionY,
|
||||
PositionZ = view.PositionZ,
|
||||
Position = view.Position,
|
||||
RotationRadians = view.RotationRadians,
|
||||
PhysicsBodyRadius = view.PhysicsBodyRadius,
|
||||
RenderScale = view.RenderScale,
|
||||
|
|
|
|||
|
|
@ -7,13 +7,7 @@ using Unity.Mathematics;
|
|||
public struct AetheriaDaemonRenderGroupMatrixJob : IJob
|
||||
{
|
||||
[ReadOnly]
|
||||
public NativeArray<float> PositionX;
|
||||
|
||||
[ReadOnly]
|
||||
public NativeArray<float> PositionY;
|
||||
|
||||
[ReadOnly]
|
||||
public NativeArray<float> PositionZ;
|
||||
public NativeArray<float3> Position;
|
||||
|
||||
[ReadOnly]
|
||||
public NativeArray<float> RotationRadians;
|
||||
|
|
@ -51,7 +45,7 @@ public struct AetheriaDaemonRenderGroupMatrixJob : IJob
|
|||
public void Execute()
|
||||
{
|
||||
var written = 0;
|
||||
for (var index = 0; index < PositionX.Length; index++)
|
||||
for (var index = 0; index < Position.Length; index++)
|
||||
{
|
||||
if (HasRenderGroupFilter && RenderGroupId[index] != TargetRenderGroupId)
|
||||
{
|
||||
|
|
@ -73,7 +67,7 @@ public struct AetheriaDaemonRenderGroupMatrixJob : IJob
|
|||
break;
|
||||
}
|
||||
|
||||
var position = new float3(PositionX[index], PositionY[index], PositionZ[index]);
|
||||
var position = Position[index];
|
||||
var rotation = HasRotation
|
||||
? quaternion.RotateY(RotationRadians[index])
|
||||
: quaternion.identity;
|
||||
|
|
|
|||
|
|
@ -7,13 +7,7 @@ using Unity.Mathematics;
|
|||
public struct AetheriaDaemonRenderMatrixJob : IJobParallelFor
|
||||
{
|
||||
[ReadOnly]
|
||||
public NativeArray<float> PositionX;
|
||||
|
||||
[ReadOnly]
|
||||
public NativeArray<float> PositionY;
|
||||
|
||||
[ReadOnly]
|
||||
public NativeArray<float> PositionZ;
|
||||
public NativeArray<float3> Position;
|
||||
|
||||
[ReadOnly]
|
||||
public NativeArray<float> RotationRadians;
|
||||
|
|
@ -34,7 +28,7 @@ public struct AetheriaDaemonRenderMatrixJob : IJobParallelFor
|
|||
|
||||
public void Execute(int index)
|
||||
{
|
||||
var position = new float3(PositionX[index], PositionY[index], PositionZ[index]);
|
||||
var position = Position[index];
|
||||
var rotation = HasRotation
|
||||
? quaternion.RotateY(RotationRadians[index])
|
||||
: quaternion.identity;
|
||||
|
|
|
|||
|
|
@ -9,13 +9,9 @@ public struct AetheriaDaemonRenderNativeView
|
|||
public long Generation;
|
||||
public int Count;
|
||||
public NativeArray<int> EntityIndex;
|
||||
public NativeArray<float> PositionX;
|
||||
public NativeArray<float> PositionY;
|
||||
public NativeArray<float> PositionZ;
|
||||
public NativeArray<float3> Position;
|
||||
public NativeArray<float> RotationRadians;
|
||||
public NativeArray<float> VelocityX;
|
||||
public NativeArray<float> VelocityY;
|
||||
public NativeArray<float> VelocityZ;
|
||||
public NativeArray<float3> Velocity;
|
||||
public NativeArray<float> PhysicsBodyRadius;
|
||||
public NativeArray<float> PhysicsBodyMass;
|
||||
public NativeArray<float> PhysicsBodyInverseMass;
|
||||
|
|
@ -26,13 +22,11 @@ public struct AetheriaDaemonRenderNativeView
|
|||
|
||||
public bool IsCreated =>
|
||||
Count > 0 &&
|
||||
PositionX.IsCreated &&
|
||||
PositionY.IsCreated &&
|
||||
PositionZ.IsCreated;
|
||||
Position.IsCreated;
|
||||
|
||||
public bool HasRotation => RotationRadians.IsCreated;
|
||||
public bool HasEntityIndex => EntityIndex.IsCreated;
|
||||
public bool HasVelocity => VelocityX.IsCreated && VelocityY.IsCreated && VelocityZ.IsCreated;
|
||||
public bool HasVelocity => Velocity.IsCreated;
|
||||
public bool HasPhysicsRadius => PhysicsBodyRadius.IsCreated;
|
||||
public bool HasPhysicsMass => PhysicsBodyMass.IsCreated;
|
||||
public bool HasPhysicsInverseMass => PhysicsBodyInverseMass.IsCreated;
|
||||
|
|
@ -60,9 +54,7 @@ public struct AetheriaDaemonRenderNativeView
|
|||
|
||||
var job = new AetheriaDaemonRenderMatrixJob
|
||||
{
|
||||
PositionX = PositionX,
|
||||
PositionY = PositionY,
|
||||
PositionZ = PositionZ,
|
||||
Position = Position,
|
||||
RotationRadians = RotationRadians,
|
||||
PhysicsBodyRadius = PhysicsBodyRadius,
|
||||
RenderScale = RenderScale,
|
||||
|
|
@ -89,33 +81,18 @@ public struct AetheriaDaemonRenderNativeView
|
|||
|
||||
if (!map.TryCreateFirstNativeArrayOfKind(
|
||||
index,
|
||||
AetheriaRuntimeDaemonSoaColumnKinds.PositionX,
|
||||
out view.PositionX) ||
|
||||
!map.TryCreateFirstNativeArrayOfKind(
|
||||
index,
|
||||
AetheriaRuntimeDaemonSoaColumnKinds.PositionY,
|
||||
out view.PositionY) ||
|
||||
!map.TryCreateFirstNativeArrayOfKind(
|
||||
index,
|
||||
AetheriaRuntimeDaemonSoaColumnKinds.PositionZ,
|
||||
out view.PositionZ))
|
||||
AetheriaRuntimeDaemonSoaColumnKinds.Position,
|
||||
out view.Position))
|
||||
{
|
||||
view = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
view.Count = view.PositionX.Length;
|
||||
if (view.PositionY.Length != view.Count || view.PositionZ.Length != view.Count)
|
||||
{
|
||||
view = default;
|
||||
return false;
|
||||
}
|
||||
view.Count = view.Position.Length;
|
||||
|
||||
TryAssignOptionalIntColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.EntityIndex, view.Count, out view.EntityIndex);
|
||||
TryAssignOptionalColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.RotationRadians, view.Count, out view.RotationRadians);
|
||||
TryAssignOptionalColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.VelocityX, view.Count, out view.VelocityX);
|
||||
TryAssignOptionalColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.VelocityY, view.Count, out view.VelocityY);
|
||||
TryAssignOptionalColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.VelocityZ, view.Count, out view.VelocityZ);
|
||||
TryAssignOptionalFloat3Column(index, map, AetheriaRuntimeDaemonSoaColumnKinds.Velocity, view.Count, out view.Velocity);
|
||||
TryAssignOptionalColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.PhysicsBodyRadius, view.Count, out view.PhysicsBodyRadius);
|
||||
TryAssignOptionalColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.PhysicsBodyMass, view.Count, out view.PhysicsBodyMass);
|
||||
TryAssignOptionalColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.PhysicsBodyInverseMass, view.Count, out view.PhysicsBodyInverseMass);
|
||||
|
|
@ -124,19 +101,39 @@ public struct AetheriaDaemonRenderNativeView
|
|||
TryAssignOptionalIntColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.RenderLod, view.Count, out view.RenderLod);
|
||||
TryAssignOptionalUIntColumn(index, map, AetheriaRuntimeDaemonSoaColumnKinds.RenderGroupId, view.Count, out view.RenderGroupId);
|
||||
|
||||
if ((view.VelocityX.IsCreated || view.VelocityY.IsCreated || view.VelocityZ.IsCreated) &&
|
||||
!view.HasVelocity)
|
||||
{
|
||||
view.VelocityX = default;
|
||||
view.VelocityY = default;
|
||||
view.VelocityZ = default;
|
||||
}
|
||||
|
||||
view.FrameId = index.View.FrameId;
|
||||
view.Generation = index.View.Generation;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryAssignOptionalFloat3Column(
|
||||
AetheriaRuntimeDaemonSoaViewIndex index,
|
||||
AetheriaDaemonSoaMemoryMap map,
|
||||
string kind,
|
||||
int expectedCount,
|
||||
out NativeArray<float3> array)
|
||||
{
|
||||
array = default;
|
||||
if (!index.TryGetFirstColumnOfKind(kind, out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!map.TryCreateFirstNativeArrayOfKind(index, kind, out array))
|
||||
{
|
||||
array = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (array.Length == expectedCount)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
array = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryAssignOptionalColumn(
|
||||
AetheriaRuntimeDaemonSoaViewIndex index,
|
||||
AetheriaDaemonSoaMemoryMap map,
|
||||
|
|
|
|||
13
Assets/Scripts/Gameplay/AetheriaUnityActionBarBinding.cs
Normal file
13
Assets/Scripts/Gameplay/AetheriaUnityActionBarBinding.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* 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/. */
|
||||
|
||||
public sealed class AetheriaUnityActionBarBinding
|
||||
{
|
||||
public string ControlPath { get; set; } = "";
|
||||
public string Kind { get; set; } = "";
|
||||
public string ItemKey { get; set; } = "";
|
||||
public int EquipmentIndex { get; set; } = -1;
|
||||
public int BehaviorIndex { get; set; } = -1;
|
||||
public int WeaponGroup { get; set; } = -1;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: af36b057bd1c2ba46adad018b02fd568
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
|
||||
public sealed class AetheriaUnityActionBarBindingAdapter
|
||||
{
|
||||
private readonly AetheriaUnityActionBarPresentation _presentation;
|
||||
|
||||
public AetheriaUnityActionBarBindingAdapter(
|
||||
AetheriaUnityActionBarPresentation presentation)
|
||||
{
|
||||
_presentation = presentation ?? throw new ArgumentNullException(nameof(presentation));
|
||||
}
|
||||
|
||||
public void ApplyBindings(IReadOnlyList<AetheriaUnityActionBarBinding> bindings)
|
||||
{
|
||||
_presentation.ApplyLocalBindings();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c70aab770e351924eb213421f9096e22
|
||||
275
Assets/Scripts/Gameplay/AetheriaUnityActionBarPresentation.cs
Normal file
275
Assets/Scripts/Gameplay/AetheriaUnityActionBarPresentation.cs
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class AetheriaUnityActionBarPresentation
|
||||
{
|
||||
private IReadOnlyList<ActionBarSlot> _slots = Array.Empty<ActionBarSlot>();
|
||||
private AetheriaRuntimeCatalogSnapshot _catalog;
|
||||
private GameSettings _settings;
|
||||
private Func<Entity> _resolveEntity = () => null;
|
||||
private Func<AetheriaClient> _resolveClient = () => null;
|
||||
private IReadOnlyList<AetheriaUnityActionBarBinding> _localBindings =
|
||||
Array.Empty<AetheriaUnityActionBarBinding>();
|
||||
|
||||
public void Bind(
|
||||
IReadOnlyList<ActionBarSlot> slots,
|
||||
AetheriaRuntimeCatalogSnapshot catalog,
|
||||
GameSettings settings,
|
||||
Func<Entity> resolveEntity,
|
||||
Func<AetheriaClient> resolveClient)
|
||||
{
|
||||
_slots = slots ?? Array.Empty<ActionBarSlot>();
|
||||
_catalog = catalog;
|
||||
_settings = settings;
|
||||
_resolveEntity = resolveEntity ?? (() => null);
|
||||
_resolveClient = resolveClient ?? (() => null);
|
||||
}
|
||||
|
||||
public int SlotCount => _slots?.Count ?? 0;
|
||||
|
||||
public string SlotLabel(int slotIndex)
|
||||
{
|
||||
var slot = ResolveSlot(slotIndex);
|
||||
if (slot == null)
|
||||
return "";
|
||||
|
||||
var controlPath = slot.ControlPath ?? "";
|
||||
if (string.IsNullOrWhiteSpace(controlPath))
|
||||
return "Action Bar";
|
||||
|
||||
var slashIndex = controlPath.LastIndexOf('/');
|
||||
return slashIndex >= 0 && slashIndex < controlPath.Length - 1
|
||||
? controlPath.Substring(slashIndex + 1)
|
||||
: controlPath;
|
||||
}
|
||||
|
||||
public string BindingLabel(int slotIndex)
|
||||
{
|
||||
var slot = ResolveSlot(slotIndex);
|
||||
return slot?.Binding switch
|
||||
{
|
||||
ActionBarWeaponGroupBinding weaponGroup => $"G{weaponGroup.Group + 1}",
|
||||
ActionBarConsumableBinding consumable => consumable.Target?.Name ?? "Consumable",
|
||||
ActionBarGearBinding gear => _catalog?.FindItem(gear.Item?.EquippableItem?.ItemKey ?? "")?.Name ?? "Gear",
|
||||
_ => "Empty"
|
||||
};
|
||||
}
|
||||
|
||||
public bool TryResolveControlPath(int slotIndex, out string controlPath)
|
||||
{
|
||||
controlPath = ResolveSlot(slotIndex)?.ControlPath ?? "";
|
||||
return !string.IsNullOrWhiteSpace(controlPath);
|
||||
}
|
||||
|
||||
public void RequestBinding(ActionBarSlot slot, DragObject dragAction)
|
||||
{
|
||||
var entity = _resolveEntity();
|
||||
if (slot == null || dragAction == null || entity == null)
|
||||
return;
|
||||
|
||||
var binding = CreateBindingCommit(slot, entity, dragAction);
|
||||
if (binding == null ||
|
||||
string.IsNullOrWhiteSpace(binding.ControlPath) ||
|
||||
string.IsNullOrWhiteSpace(binding.Kind))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetLocalBinding(binding);
|
||||
ApplyLocalBindings();
|
||||
}
|
||||
|
||||
public bool RequestWeaponGroupBinding(int slotIndex, int groupIndex)
|
||||
{
|
||||
if (groupIndex < 0 || !TryResolveControlPath(slotIndex, out var controlPath))
|
||||
return false;
|
||||
|
||||
SetLocalBinding(new AetheriaUnityActionBarBinding
|
||||
{
|
||||
ControlPath = controlPath,
|
||||
Kind = "weapon_group",
|
||||
ItemKey = "",
|
||||
EquipmentIndex = -1,
|
||||
BehaviorIndex = -1,
|
||||
WeaponGroup = groupIndex
|
||||
});
|
||||
ApplyLocalBindings();
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ClearBinding(int slotIndex)
|
||||
{
|
||||
if (!TryResolveControlPath(slotIndex, out var controlPath))
|
||||
return false;
|
||||
|
||||
_localBindings = (_localBindings ?? Array.Empty<AetheriaUnityActionBarBinding>())
|
||||
.Where(binding => !string.Equals(binding?.ControlPath ?? "", controlPath, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
ApplyLocalBindings();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void ApplyLocalBindings()
|
||||
{
|
||||
ApplyBindings(_resolveEntity(), _localBindings);
|
||||
}
|
||||
|
||||
public void ApplyBindings(
|
||||
Entity entity,
|
||||
IReadOnlyList<AetheriaUnityActionBarBinding> bindings)
|
||||
{
|
||||
if (_slots == null || _slots.Count == 0)
|
||||
return;
|
||||
|
||||
foreach (var slot in _slots)
|
||||
slot.Binding = null;
|
||||
|
||||
if (entity == null || bindings == null || bindings.Count == 0)
|
||||
return;
|
||||
|
||||
var slotsByControlPath = _slots
|
||||
.Where(slot => !string.IsNullOrWhiteSpace(slot?.ControlPath))
|
||||
.GroupBy(slot => slot.ControlPath, StringComparer.Ordinal)
|
||||
.ToDictionary(group => group.Key, group => group.First(), StringComparer.Ordinal);
|
||||
|
||||
foreach (var binding in bindings)
|
||||
{
|
||||
if (binding == null ||
|
||||
string.IsNullOrWhiteSpace(binding.ControlPath) ||
|
||||
!slotsByControlPath.TryGetValue(binding.ControlPath, out var slot))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var slotBinding = CreateBinding(slot, entity, binding);
|
||||
if (slotBinding != null)
|
||||
slot.Binding = slotBinding;
|
||||
}
|
||||
}
|
||||
|
||||
public ActionBarBinding CreateBinding(ActionBarSlot slot, Entity entity, DragObject dragAction)
|
||||
{
|
||||
var binding = CreateBindingCommit(slot, entity, dragAction);
|
||||
return binding == null ? null : CreateBinding(slot, entity, binding);
|
||||
}
|
||||
|
||||
private AetheriaUnityActionBarBinding CreateBindingCommit(
|
||||
ActionBarSlot slot,
|
||||
Entity entity,
|
||||
DragObject dragAction)
|
||||
{
|
||||
if (slot == null || entity == null || dragAction == null)
|
||||
return null;
|
||||
|
||||
switch (dragAction)
|
||||
{
|
||||
case EquippedItemDragObject equippedItemDragAction:
|
||||
var equippedItem = equippedItemDragAction.EquippedItem;
|
||||
var trigger = equippedItem?.GetBehavior<IActivatedBehavior>();
|
||||
var equipmentIndex = equippedItem == null ? -1 : entity.Equipment.IndexOf(equippedItem);
|
||||
var behaviorIndex = equippedItem?.Behaviors == null ? -1 : Array.IndexOf(equippedItem.Behaviors, trigger);
|
||||
return trigger == null || equipmentIndex < 0 || behaviorIndex < 0
|
||||
? null
|
||||
: new AetheriaUnityActionBarBinding
|
||||
{
|
||||
ControlPath = slot.ControlPath ?? "",
|
||||
Kind = "gear",
|
||||
ItemKey = equippedItem.EquippableItem?.ItemKey ?? "",
|
||||
EquipmentIndex = equipmentIndex,
|
||||
BehaviorIndex = behaviorIndex
|
||||
};
|
||||
case ItemInstanceDragObject itemInstanceDragAction:
|
||||
var consumable = FindConsumable(itemInstanceDragAction.Item);
|
||||
return consumable == null
|
||||
? null
|
||||
: new AetheriaUnityActionBarBinding
|
||||
{
|
||||
ControlPath = slot.ControlPath ?? "",
|
||||
Kind = "consumable",
|
||||
ItemKey = consumable.ItemKey ?? ""
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetLocalBinding(AetheriaUnityActionBarBinding binding)
|
||||
{
|
||||
if (binding == null || string.IsNullOrWhiteSpace(binding.ControlPath))
|
||||
return;
|
||||
|
||||
_localBindings = (_localBindings ?? Array.Empty<AetheriaUnityActionBarBinding>())
|
||||
.Where(existing => !string.Equals(existing?.ControlPath ?? "", binding.ControlPath, StringComparison.Ordinal))
|
||||
.Concat(new[] { binding })
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private ActionBarBinding CreateBinding(
|
||||
ActionBarSlot slot,
|
||||
Entity entity,
|
||||
AetheriaUnityActionBarBinding binding)
|
||||
{
|
||||
if (slot == null || entity == null || binding == null)
|
||||
return null;
|
||||
|
||||
var client = _resolveClient();
|
||||
|
||||
switch (binding.Kind)
|
||||
{
|
||||
case "consumable":
|
||||
var consumable = _catalog?.FindItem(binding.ItemKey ?? "");
|
||||
return consumable != null &&
|
||||
string.Equals(consumable.Category, AetheriaRuntimeItemCategories.Consumable, StringComparison.Ordinal)
|
||||
? new ActionBarConsumableBinding(entity, slot, client, _settings, consumable)
|
||||
: null;
|
||||
case "gear":
|
||||
if (binding.EquipmentIndex < 0 || binding.EquipmentIndex >= entity.Equipment.Count)
|
||||
return null;
|
||||
|
||||
var equippedItem = entity.Equipment[binding.EquipmentIndex];
|
||||
var behaviors = equippedItem?.Behaviors;
|
||||
if (equippedItem == null ||
|
||||
!string.Equals(equippedItem.EquippableItem?.ItemKey ?? "", binding.ItemKey ?? "", StringComparison.Ordinal) ||
|
||||
behaviors == null ||
|
||||
binding.BehaviorIndex < 0 ||
|
||||
binding.BehaviorIndex >= behaviors.Length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!(behaviors[binding.BehaviorIndex] is IActivatedBehavior activatedBehavior))
|
||||
return null;
|
||||
|
||||
return new ActionBarGearBinding(entity, slot, client, _settings, equippedItem, activatedBehavior);
|
||||
case "weapon_group":
|
||||
return entity.WeaponGroups != null &&
|
||||
binding.WeaponGroup >= 0 &&
|
||||
binding.WeaponGroup < entity.WeaponGroups.Length
|
||||
? new ActionBarWeaponGroupBinding(entity, slot, client, _settings, binding.WeaponGroup)
|
||||
: null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private AetheriaRuntimeCatalogItem FindConsumable(ItemInstance item)
|
||||
{
|
||||
var typedItem = _catalog?.FindItem(item?.ItemKey ?? "");
|
||||
return typedItem != null &&
|
||||
string.Equals(typedItem.Category, AetheriaRuntimeItemCategories.Consumable, StringComparison.Ordinal)
|
||||
? typedItem
|
||||
: null;
|
||||
}
|
||||
|
||||
private ActionBarSlot ResolveSlot(int slotIndex)
|
||||
{
|
||||
return _slots != null &&
|
||||
slotIndex >= 0 &&
|
||||
slotIndex < _slots.Count
|
||||
? _slots[slotIndex]
|
||||
: null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0f239f607245e8143805587f4c34fbee
|
||||
38
Assets/Scripts/Gameplay/AetheriaUnityCockpitHudShell.cs
Normal file
38
Assets/Scripts/Gameplay/AetheriaUnityCockpitHudShell.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* 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/. */
|
||||
|
||||
public sealed class AetheriaUnityCockpitHudShell
|
||||
{
|
||||
public InventoryPanel ShipPanel { get; set; }
|
||||
public InventoryPanel TargetShipPanel { get; set; }
|
||||
public SchematicDisplay SchematicDisplay { get; set; }
|
||||
public SchematicDisplay TargetSchematicDisplay { get; set; }
|
||||
public PlaceUIElementWorldspace TargetIndicator { get; set; }
|
||||
|
||||
public void SetRenderSettings(AetheriaRuntimeDaemonRenderSettings renderSettings)
|
||||
{
|
||||
SchematicDisplay?.SetRenderSettings(renderSettings);
|
||||
TargetSchematicDisplay?.SetRenderSettings(renderSettings);
|
||||
}
|
||||
|
||||
public void UpdatePlayer(Entity currentEntity)
|
||||
{
|
||||
ShipPanel?.Display(currentEntity, true);
|
||||
SchematicDisplay?.ShowShip(currentEntity);
|
||||
}
|
||||
|
||||
public void UpdateTarget(Entity target, Entity currentEntity)
|
||||
{
|
||||
if (TargetIndicator != null)
|
||||
TargetIndicator.gameObject.SetActive(target != null);
|
||||
if (TargetShipPanel != null)
|
||||
TargetShipPanel.gameObject.SetActive(target != null);
|
||||
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
TargetShipPanel?.Display(target, true);
|
||||
TargetSchematicDisplay?.ShowShip(target, currentEntity);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 027535b4501541f4aa60df9ae50d9eed
|
||||
87
Assets/Scripts/Gameplay/AetheriaUnityCurrentEntityBinder.cs
Normal file
87
Assets/Scripts/Gameplay/AetheriaUnityCurrentEntityBinder.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
using float3 = Unity.Mathematics.float3;
|
||||
|
||||
public sealed class AetheriaUnityCurrentEntityBinder
|
||||
{
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public PostProcessVolume DeathPost { get; set; }
|
||||
public CanvasGroup GameplayUI { get; set; }
|
||||
public AetheriaUnityObservedDockingIndex ObservedDocking { get; set; }
|
||||
public AetheriaUnityCurrentEntityPresentation CurrentEntityPresentation { get; set; }
|
||||
public AetheriaUnityTargetPresentation TargetPresentation { get; set; }
|
||||
public Func<Entity> GetCurrentEntity { get; set; }
|
||||
public Action<Entity> SetCurrentEntity { get; set; }
|
||||
public Func<float3> GetViewDirection { get; set; }
|
||||
public Action<float3> SetViewDirection { get; set; }
|
||||
public Func<AetheriaRuntimeZoneRenderDocument> ResolveZoneRender { get; set; }
|
||||
public Action<IReadOnlyList<AetheriaUnityActionBarBinding>> ApplyActionBarBindings { get; set; }
|
||||
public Action EnablePlayerInput { get; set; }
|
||||
public Action DisablePlayerInput { get; set; }
|
||||
public Action<MusicType> PlayMusic { get; set; }
|
||||
public Action<Entity> UpdateTargetPanel { get; set; }
|
||||
|
||||
public void RestoreBinding(Entity currentEntity)
|
||||
{
|
||||
if (ObservedDocking != null &&
|
||||
ObservedDocking.TryResolveDockingBay(currentEntity, out var dockParent, out _))
|
||||
{
|
||||
SetCurrentEntity?.Invoke(currentEntity);
|
||||
ApplyActionBarBindings?.Invoke(Array.Empty<AetheriaUnityActionBarBinding>());
|
||||
CurrentEntityPresentation?.BindDocked(
|
||||
dockParent,
|
||||
null,
|
||||
ResolveZoneRender?.Invoke());
|
||||
return;
|
||||
}
|
||||
|
||||
BindUndocked(
|
||||
currentEntity);
|
||||
}
|
||||
|
||||
public void ClearBinding()
|
||||
{
|
||||
TargetPresentation?.ClearIndicators();
|
||||
CurrentEntityPresentation?.ClearBinding();
|
||||
DisablePlayerInput?.Invoke();
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
if (GameplayUI != null)
|
||||
GameplayUI.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void BindUndocked(Entity entity)
|
||||
{
|
||||
if (ZoneRenderer == null ||
|
||||
!ZoneRenderer.TryGetEntityInstance(entity, out var entityInstance))
|
||||
{
|
||||
Debug.LogError($"Attempted to bind to entity {entity?.Name}, but ZoneRenderer has no daemon-indexed instance.");
|
||||
return;
|
||||
}
|
||||
|
||||
SetCurrentEntity?.Invoke(entity);
|
||||
if (DeathPost != null)
|
||||
DeathPost.weight = 0;
|
||||
|
||||
if (CultMath.math.length(entity.CultDirection) > .1f)
|
||||
SetViewDirection?.Invoke((float3)AetheriaMath.ToUnityXZ(entity.CultDirection));
|
||||
|
||||
CurrentEntityPresentation?.BindUndocked(
|
||||
entity,
|
||||
entityInstance,
|
||||
Array.Empty<AetheriaUnityActionBarBinding>(),
|
||||
EnablePlayerInput,
|
||||
PlayMusic,
|
||||
SetCurrentEntity,
|
||||
UpdateTargetPanel,
|
||||
() => TargetPresentation?.ReconcileVisibleTargetIndicators(GetCurrentEntity?.Invoke()),
|
||||
ApplyActionBarBindings);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c599c7371ae28e249bcf132744d4e547
|
||||
|
|
@ -0,0 +1,228 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cinemachine;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class AetheriaUnityCurrentEntityPresentation
|
||||
{
|
||||
private readonly List<IDisposable> _shipSubscriptions = new List<IDisposable>();
|
||||
private readonly List<IDisposable> _targetSubscriptions = new List<IDisposable>();
|
||||
private float _hitMarkerTime;
|
||||
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public CinemachineVirtualCamera DockCamera { get; set; }
|
||||
public CinemachineVirtualCamera FollowCamera { get; set; }
|
||||
public MenuPanel Menu { get; set; }
|
||||
public TradeMenu TradeMenu { get; set; }
|
||||
public CanvasGroup GameplayUI { get; set; }
|
||||
public InventoryPanel ShipPanel { get; set; }
|
||||
public InventoryPanel TargetShipPanel { get; set; }
|
||||
public SchematicDisplay SchematicDisplay { get; set; }
|
||||
public SchematicDisplay TargetSchematicDisplay { get; set; }
|
||||
public ImageTargetPresentation TargetImages { get; set; }
|
||||
public AetheriaRuntimeCatalogSnapshot RuntimeCatalog { get; set; }
|
||||
public PlaceUIElementWorldspace[] Crosshairs { get; set; } = Array.Empty<PlaceUIElementWorldspace>();
|
||||
public Prototype LockIndicator { get; set; }
|
||||
public GameObject HitMarker { get; set; }
|
||||
public float HitMarkerDuration { get; set; }
|
||||
|
||||
public (HardpointData[] hardpoints, Transform[] barrels, PlaceUIElementWorldspace crosshair)[] ArticulationGroups { get; private set; } =
|
||||
Array.Empty<(HardpointData[] hardpoints, Transform[] barrels, PlaceUIElementWorldspace crosshair)>();
|
||||
|
||||
public (LockWeapon targetLock, PlaceUIElementWorldspace indicator, Rotate spin)[] LockingIndicators { get; private set; } =
|
||||
Array.Empty<(LockWeapon targetLock, PlaceUIElementWorldspace indicator, Rotate spin)>();
|
||||
|
||||
public void BindUndocked(
|
||||
Entity entity,
|
||||
EntityInstance entityInstance,
|
||||
IReadOnlyList<AetheriaUnityActionBarBinding> actionBarBindings,
|
||||
Action enablePlayerInput,
|
||||
Action<MusicType> playMusic,
|
||||
Action<Entity> updateCurrentEntity,
|
||||
Action<Entity> updateTargetPanel,
|
||||
Action reconcileVisibleTargetIndicators,
|
||||
Action<IReadOnlyList<AetheriaUnityActionBarBinding>> applyActionBarBindings)
|
||||
{
|
||||
if (entity == null || entityInstance == null)
|
||||
return;
|
||||
|
||||
updateCurrentEntity?.Invoke(entity);
|
||||
ZoneRenderer.PerspectiveEntity = entity;
|
||||
|
||||
Menu.gameObject.SetActive(false);
|
||||
DockCamera.enabled = false;
|
||||
FollowCamera.enabled = true;
|
||||
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
enablePlayerInput?.Invoke();
|
||||
GameplayUI.gameObject.SetActive(true);
|
||||
ShipPanel.Display(entity, true);
|
||||
SchematicDisplay.ShowShip(entity);
|
||||
|
||||
FollowCamera.LookAt = entityInstance.LookAtPoint;
|
||||
FollowCamera.Follow = entityInstance.transform;
|
||||
ArticulationGroups = entity.Equipment
|
||||
.Where(HasArticulatedWeaponBehavior)
|
||||
.GroupBy(item => entityInstance
|
||||
.GetBarrel(entity.Hardpoints[item.Position.x, item.Position.y])
|
||||
.GetComponentInParent<ArticulationPoint>()?.Group ?? -1)
|
||||
.Select((group, index) =>
|
||||
{
|
||||
return (
|
||||
group.Select(item => entity.Hardpoints[item.Position.x, item.Position.y]).ToArray(),
|
||||
group.Select(item => entityInstance.GetBarrel(entity.Hardpoints[item.Position.x, item.Position.y])).ToArray(),
|
||||
Crosshairs[index]
|
||||
);
|
||||
}).ToArray();
|
||||
|
||||
foreach (var crosshair in Crosshairs)
|
||||
crosshair.gameObject.SetActive(false);
|
||||
foreach (var group in ArticulationGroups)
|
||||
group.crosshair.gameObject.SetActive(true);
|
||||
|
||||
_shipSubscriptions.Add(entity.TargetedByCount.Subscribe(count =>
|
||||
{
|
||||
playMusic?.Invoke(count > 0 ? MusicType.Combat : MusicType.Overworld);
|
||||
}));
|
||||
|
||||
_shipSubscriptions.Add(entity.Target.Subscribe(target =>
|
||||
{
|
||||
ClearTargetSubscriptions();
|
||||
updateTargetPanel?.Invoke(target);
|
||||
ConfigureTargetShieldPresentation(target);
|
||||
if (target != null)
|
||||
{
|
||||
_targetSubscriptions.Add(target.IncomingHit.Where(e => e == entity).Subscribe(_ =>
|
||||
{
|
||||
HitMarker.SetActive(true);
|
||||
_hitMarkerTime = HitMarkerDuration;
|
||||
}));
|
||||
}
|
||||
}));
|
||||
|
||||
reconcileVisibleTargetIndicators?.Invoke();
|
||||
|
||||
LockingIndicators = entity.GetBehaviors<LockWeapon>()
|
||||
.Select(x =>
|
||||
{
|
||||
var indicator = LockIndicator.Instantiate<PlaceUIElementWorldspace>();
|
||||
return (x, indicator, indicator.GetComponent<Rotate>());
|
||||
}).ToArray();
|
||||
|
||||
applyActionBarBindings?.Invoke(actionBarBindings ?? Array.Empty<AetheriaUnityActionBarBinding>());
|
||||
}
|
||||
|
||||
public bool HasArticulatedWeaponBehavior(EquippedItem item)
|
||||
{
|
||||
return AetheriaUnityWeaponPresentationPolicy.HasArticulatedWeaponBehavior(RuntimeCatalog, item);
|
||||
}
|
||||
|
||||
public void BindDocked(
|
||||
Entity entity,
|
||||
AetheriaRuntimeCurrentDockingDocument docking,
|
||||
AetheriaRuntimeZoneRenderDocument zoneRender)
|
||||
{
|
||||
if (entity == null)
|
||||
return;
|
||||
|
||||
TradeMenu.Inventory = entity.CargoBays.First();
|
||||
ZoneRenderer.PerspectiveEntity = entity;
|
||||
DockCamera.enabled = true;
|
||||
FollowCamera.enabled = false;
|
||||
var orbital = entity as OrbitalEntity;
|
||||
if (orbital == null || !ZoneRenderer.TryGetEntityInstance(orbital, out var orbitalInstance))
|
||||
{
|
||||
Debug.LogError($"Attempted to dock at entity {entity.Name}, but ZoneRenderer has no daemon-indexed instance.");
|
||||
return;
|
||||
}
|
||||
|
||||
DockCamera.Follow = orbitalInstance.transform;
|
||||
var parentOrbitPlanetBodyKey = ResolveDockParentBodyKey(orbital, docking, zoneRender);
|
||||
if (ZoneRenderer.TryGetBodyView(parentOrbitPlanetBodyKey, out var parentBodyView))
|
||||
DockCamera.LookAt = parentBodyView.Body.transform;
|
||||
else DockCamera.LookAt = ZoneRenderer.ZoneRoot;
|
||||
Menu.ShowTab(MenuTab.Inventory);
|
||||
}
|
||||
|
||||
private static string ResolveDockParentBodyKey(
|
||||
OrbitalEntity orbital,
|
||||
AetheriaRuntimeCurrentDockingDocument docking,
|
||||
AetheriaRuntimeZoneRenderDocument zoneRender)
|
||||
{
|
||||
if (orbital == null)
|
||||
return "";
|
||||
|
||||
var bodyPoses = zoneRender?.BodyPoses ?? Array.Empty<AetheriaRuntimeZoneRenderBodyPose>();
|
||||
var parentOrbitKey = bodyPoses
|
||||
.FirstOrDefault(body => body != null &&
|
||||
string.Equals(body.OrbitKey ?? "", orbital.OrbitKey, StringComparison.Ordinal))
|
||||
?.ParentOrbitKey ?? docking?.DockParentParentOrbitKey ?? "";
|
||||
return bodyPoses
|
||||
.FirstOrDefault(body => body != null &&
|
||||
string.Equals(body.OrbitKey ?? "", parentOrbitKey, StringComparison.Ordinal))
|
||||
?.BodyKey ?? docking?.DockParentParentBodyKey ?? "";
|
||||
}
|
||||
|
||||
public void ClearBinding()
|
||||
{
|
||||
foreach (var (_, indicator, _) in LockingIndicators)
|
||||
indicator.GetComponent<Prototype>().ReturnToPool();
|
||||
LockingIndicators = Array.Empty<(LockWeapon targetLock, PlaceUIElementWorldspace indicator, Rotate spin)>();
|
||||
ArticulationGroups = Array.Empty<(HardpointData[] hardpoints, Transform[] barrels, PlaceUIElementWorldspace crosshair)>();
|
||||
|
||||
foreach (var subscription in _shipSubscriptions)
|
||||
subscription.Dispose();
|
||||
_shipSubscriptions.Clear();
|
||||
ClearTargetSubscriptions();
|
||||
}
|
||||
|
||||
public void Tick(float deltaTime)
|
||||
{
|
||||
_hitMarkerTime -= deltaTime;
|
||||
if (HitMarker.activeSelf && _hitMarkerTime < 0)
|
||||
HitMarker.SetActive(false);
|
||||
}
|
||||
|
||||
private void ClearTargetSubscriptions()
|
||||
{
|
||||
foreach (var subscription in _targetSubscriptions)
|
||||
subscription.Dispose();
|
||||
_targetSubscriptions.Clear();
|
||||
}
|
||||
|
||||
private void ConfigureTargetShieldPresentation(Entity target)
|
||||
{
|
||||
if (target == null || TargetImages == null)
|
||||
return;
|
||||
|
||||
if (target.Shield != null)
|
||||
{
|
||||
TargetImages.TargetShieldsBackground.color = new Color(TargetImages.ShieldColor.r, TargetImages.ShieldColor.g, TargetImages.ShieldColor.b, .4f);
|
||||
TargetImages.TargetShieldsIcon.color = TargetImages.ShieldColor;
|
||||
TargetImages.TargetShieldsIcon.sprite = TargetImages.ShieldIcon;
|
||||
}
|
||||
else
|
||||
{
|
||||
TargetImages.TargetShieldsBackground.color = new Color(TargetImages.NoShieldColor.r, TargetImages.NoShieldColor.g, TargetImages.NoShieldColor.b, .4f);
|
||||
TargetImages.TargetShieldsIcon.color = TargetImages.NoShieldColor;
|
||||
TargetImages.TargetShieldsIcon.sprite = TargetImages.NoShieldIcon;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ImageTargetPresentation
|
||||
{
|
||||
public UnityEngine.UI.Image TargetShieldsBackground { get; set; }
|
||||
public UnityEngine.UI.Image TargetShieldsIcon { get; set; }
|
||||
public Color ShieldColor { get; set; }
|
||||
public Color NoShieldColor { get; set; }
|
||||
public Sprite ShieldIcon { get; set; }
|
||||
public Sprite NoShieldIcon { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f5a7b36e50785fc45ab94ae5a03dd1d6
|
||||
|
|
@ -0,0 +1,263 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using Regex = System.Text.RegularExpressions.Regex;
|
||||
|
||||
public static class AetheriaUnityDaemonEntitySnapshotProjector
|
||||
{
|
||||
public static AetheriaRuntimeEntitySnapshot[] CreateSnapshots(
|
||||
string runId,
|
||||
AetheriaRuntimeZoneSnapshotCommit zone)
|
||||
{
|
||||
if (zone == null)
|
||||
return Array.Empty<AetheriaRuntimeEntitySnapshot>();
|
||||
|
||||
return CreateSnapshots(runId, zone.ZoneIndex, zone.Entities);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEntitySnapshot[] CreateSnapshots(
|
||||
string runId,
|
||||
int zoneIndex,
|
||||
IReadOnlyList<AetheriaRuntimeEntitySnapshotCommit> entities)
|
||||
{
|
||||
return (entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>())
|
||||
.Where(entity => entity != null)
|
||||
.Select(entity => CreateSnapshot(runId, zoneIndex, entity))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static int EntityIndexFromRecordKey(string recordKey)
|
||||
{
|
||||
var match = Regex.Match(recordKey ?? "", @"\.entity\.(\d+)\.v1$");
|
||||
return match.Success && int.TryParse(match.Groups[1].Value, out var index)
|
||||
? index
|
||||
: int.MaxValue;
|
||||
}
|
||||
|
||||
public static string DaemonEntityRecordKey(string runId, int zoneIndex, int entityIndex)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(runId)
|
||||
? ""
|
||||
: $"global:aetheria.run_state.{runId}.zone.{zoneIndex}.entity.{entityIndex}.v1";
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeEntitySnapshot CreateSnapshot(
|
||||
string runId,
|
||||
int zoneIndex,
|
||||
AetheriaRuntimeEntitySnapshotCommit entity)
|
||||
{
|
||||
return new AetheriaRuntimeEntitySnapshot(
|
||||
DaemonEntityRecordKey(runId, zoneIndex, entity.EntityIndex),
|
||||
entity.Name ?? "",
|
||||
entity.Kind ?? "",
|
||||
entity.PositionX,
|
||||
entity.PositionY,
|
||||
entity.PositionZ,
|
||||
entity.DirectionX,
|
||||
entity.DirectionY,
|
||||
entity.FactionKey ?? "",
|
||||
entity.HullItemKey ?? "",
|
||||
CreateItemSlots(entity.Equipment),
|
||||
CreateItemSlots(entity.CargoBays),
|
||||
CreateItemSlots(entity.DockingBays),
|
||||
(entity.ChildEntityIndices ?? Array.Empty<int>())
|
||||
.Where(index => index >= 0)
|
||||
.Select(index => DaemonEntityRecordKey(runId, zoneIndex, index))
|
||||
.ToArray(),
|
||||
(entity.WeaponGroups ?? Array.Empty<IReadOnlyList<int>>())
|
||||
.Select(group => (IReadOnlyList<int>)(group ?? Array.Empty<int>()).ToArray())
|
||||
.ToArray(),
|
||||
(entity.StatGrids ?? Array.Empty<AetheriaRuntimeEntityStatGridCommit>())
|
||||
.Select(grid => new AetheriaRuntimeEntityStatGridSnapshot(
|
||||
grid.Name ?? "",
|
||||
grid.Width,
|
||||
grid.Height,
|
||||
(grid.Values ?? Array.Empty<double>()).ToArray()))
|
||||
.ToArray(),
|
||||
entity.VelocityX,
|
||||
entity.VelocityY,
|
||||
entity.TargetEntityIndex < 0 ? "" : DaemonEntityRecordKey(runId, zoneIndex, entity.TargetEntityIndex),
|
||||
entity.IsActive,
|
||||
entity.HeatsinksEnabled,
|
||||
entity.OverrideShutdown,
|
||||
entity.TractorPower,
|
||||
entity.Heatstroke,
|
||||
entity.Hypothermia,
|
||||
(entity.ActiveConsumables ?? Array.Empty<AetheriaRuntimeActiveConsumableCommit>())
|
||||
.Select(consumable => new AetheriaRuntimeActiveConsumableSnapshot(
|
||||
consumable.ItemKey ?? "",
|
||||
consumable.Quality,
|
||||
consumable.RemainingDuration,
|
||||
consumable.Duration))
|
||||
.ToArray(),
|
||||
(entity.BehaviorProgress ?? Array.Empty<AetheriaRuntimeBehaviorProgressCommit>())
|
||||
.Select(progress => new AetheriaRuntimeBehaviorProgressSnapshot(
|
||||
progress.OwnerKind ?? "",
|
||||
progress.OwnerIndex,
|
||||
progress.BehaviorIndex,
|
||||
progress.BehaviorKind ?? "",
|
||||
progress.Progress))
|
||||
.ToArray(),
|
||||
CreateWeaponStates(runId, zoneIndex, entity.WeaponStates),
|
||||
CreateBehaviorStates(entity.BehaviorStates),
|
||||
CreateCargoBays(entity.CargoContents),
|
||||
CreateCargoBays(entity.DockingBayContents),
|
||||
(entity.DockingBayAssignments ?? Array.Empty<int>()).ToArray(),
|
||||
entity.Visibility,
|
||||
entity.VisibilitySourceCount,
|
||||
(entity.Contacts ?? Array.Empty<AetheriaRuntimeEntityContactCommit>())
|
||||
.Where(contact => contact != null && contact.TargetEntityIndex >= 0)
|
||||
.Select(contact => new AetheriaRuntimeEntityContactSnapshot(
|
||||
DaemonEntityRecordKey(runId, zoneIndex, contact.TargetEntityIndex),
|
||||
contact.InfoGathered,
|
||||
contact.Hostile,
|
||||
contact.Visible))
|
||||
.ToArray(),
|
||||
entity.ShutdownPerformance);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeEntityItemSlotSnapshot[] CreateItemSlots(
|
||||
IReadOnlyList<AetheriaRuntimeLoadoutItemSlotCommit> slots)
|
||||
{
|
||||
return (slots ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>())
|
||||
.Where(slot => slot?.Item != null)
|
||||
.Select(slot => new AetheriaRuntimeEntityItemSlotSnapshot(
|
||||
slot.X,
|
||||
slot.Y,
|
||||
slot.Item.ItemKey ?? "",
|
||||
slot.Item.Quality,
|
||||
slot.Item.Durability,
|
||||
slot.Item.Quantity,
|
||||
slot.Item.Enabled,
|
||||
slot.Item.OverrideShutdown,
|
||||
slot.Item.Temperature))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCargoBayLoadoutSnapshot[] CreateCargoBays(
|
||||
IReadOnlyList<AetheriaRuntimeCargoBayLoadoutCommit> cargoBays)
|
||||
{
|
||||
return (cargoBays ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>())
|
||||
.Select(bay => new AetheriaRuntimeCargoBayLoadoutSnapshot(
|
||||
CreateLoadoutSlots(bay?.Items)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemSlotSnapshot[] CreateLoadoutSlots(
|
||||
IReadOnlyList<AetheriaRuntimeLoadoutItemSlotCommit> slots)
|
||||
{
|
||||
return (slots ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>())
|
||||
.Where(slot => slot?.Item != null)
|
||||
.Select(slot => new AetheriaRuntimeLoadoutItemSlotSnapshot(
|
||||
slot.X,
|
||||
slot.Y,
|
||||
new AetheriaRuntimeLoadoutItemSnapshot(
|
||||
slot.Item.ItemKey ?? "",
|
||||
slot.Item.Quality,
|
||||
slot.Item.Durability,
|
||||
slot.Item.Quantity,
|
||||
slot.Item.Enabled,
|
||||
slot.Item.OverrideShutdown,
|
||||
slot.Item.Temperature)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeWeaponStateSnapshot[] CreateWeaponStates(
|
||||
string runId,
|
||||
int zoneIndex,
|
||||
IReadOnlyList<AetheriaRuntimeWeaponStateCommit> weaponStates)
|
||||
{
|
||||
return (weaponStates ?? Array.Empty<AetheriaRuntimeWeaponStateCommit>())
|
||||
.Where(state => state != null)
|
||||
.Select(state => new AetheriaRuntimeWeaponStateSnapshot(
|
||||
state.OwnerKind ?? "",
|
||||
state.OwnerIndex,
|
||||
state.BehaviorIndex,
|
||||
state.BehaviorKind ?? "",
|
||||
state.Firing,
|
||||
state.Ammo,
|
||||
state.BurstRemaining,
|
||||
state.BurstTimer,
|
||||
state.BurstInterval,
|
||||
state.CooldownProgress,
|
||||
state.CoolingDown,
|
||||
state.Charging,
|
||||
state.Charged,
|
||||
state.Charge,
|
||||
state.Reloading,
|
||||
state.ReloadProgress,
|
||||
state.AmmoIntervalProgress,
|
||||
state.LockProgress,
|
||||
state.LockTargetEntityIndex < 0 ? "" : DaemonEntityRecordKey(runId, zoneIndex, state.LockTargetEntityIndex)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorStateSnapshot[] CreateBehaviorStates(
|
||||
IReadOnlyList<AetheriaRuntimeBehaviorStateCommit> behaviorStates)
|
||||
{
|
||||
return (behaviorStates ?? Array.Empty<AetheriaRuntimeBehaviorStateCommit>())
|
||||
.Where(state => state != null)
|
||||
.Select(state => new AetheriaRuntimeBehaviorStateSnapshot(
|
||||
state.OwnerKind ?? "",
|
||||
state.OwnerIndex,
|
||||
state.BehaviorIndex,
|
||||
state.BehaviorKind ?? "",
|
||||
state.Pinging,
|
||||
state.PingCooldown,
|
||||
state.PingLerp,
|
||||
state.PingRadius,
|
||||
state.PingedEntityCount,
|
||||
state.RadiatorTemperature,
|
||||
state.Emissivity,
|
||||
state.PumpedHeat,
|
||||
state.WasteHeat,
|
||||
state.EnergyUsage,
|
||||
state.ReactorDraw,
|
||||
state.ReactorLoadRatio,
|
||||
state.CapacitorCharge,
|
||||
state.CapacitorCapacity,
|
||||
state.CapacitorEfficiency,
|
||||
state.AetherDriveAxisX,
|
||||
state.AetherDriveAxisY,
|
||||
state.AetherDriveAxisZ,
|
||||
state.AetherDriveThrustX,
|
||||
state.AetherDriveThrustY,
|
||||
state.AetherDriveThrustZ,
|
||||
state.AetherDriveRpmX,
|
||||
state.AetherDriveRpmY,
|
||||
state.AetherDriveRpmZ,
|
||||
state.AetherDriveMaximumRpm,
|
||||
state.AetherDriveThrustDirectionX,
|
||||
state.AetherDriveThrustDirectionY,
|
||||
state.ResourceScannerTargetBodyKey ?? "",
|
||||
state.ResourceScannerAsteroidIndex,
|
||||
state.ResourceScannerScanTime,
|
||||
state.ResourceScannerRange,
|
||||
state.ResourceScannerMinimumDensity,
|
||||
state.ResourceScannerScanDuration,
|
||||
state.MiningToolAsteroidBeltKey ?? "",
|
||||
state.MiningToolAsteroidIndex,
|
||||
state.MiningToolRange,
|
||||
state.ThrusterAxis,
|
||||
state.ThrusterThrust,
|
||||
state.ThrusterTorque,
|
||||
state.ShieldEfficiency,
|
||||
state.ShieldEnergyUsage,
|
||||
state.VelocityLimit,
|
||||
state.ThermotoggleTargetTemperature,
|
||||
state.SwitchActivated,
|
||||
state.TriggerPulled,
|
||||
state.StatModifierApplied,
|
||||
state.StatModifierExecuted,
|
||||
state.StatModifierTargetStatCount,
|
||||
state.TurretControllerWeaponCount,
|
||||
state.TurretControllerShotSpeed,
|
||||
state.TurretControllerPredictShots))
|
||||
.ToArray();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e81930c7560adfe48b4f959791ab3572
|
||||
45
Assets/Scripts/Gameplay/AetheriaUnityDragObjects.cs
Normal file
45
Assets/Scripts/Gameplay/AetheriaUnityDragObjects.cs
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* 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 int2 = Unity.Mathematics.int2;
|
||||
|
||||
public abstract class DragObject
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class ItemDragObject : DragObject
|
||||
{
|
||||
protected ItemDragObject(int2 originCellOffset, ItemInstance item)
|
||||
{
|
||||
OriginCellOffset = originCellOffset;
|
||||
Item = item;
|
||||
}
|
||||
|
||||
public ItemInstance Item { get; }
|
||||
public int2 OriginCellOffset { get; }
|
||||
}
|
||||
|
||||
public class ItemInstanceDragObject : ItemDragObject
|
||||
{
|
||||
public ItemInstanceDragObject(ItemInstance item, EquippedCargoBay originInventory, int2 originCellOffset)
|
||||
: base(originCellOffset, item)
|
||||
{
|
||||
OriginInventory = originInventory;
|
||||
}
|
||||
|
||||
public EquippedCargoBay OriginInventory { get; }
|
||||
}
|
||||
|
||||
public class EquippedItemDragObject : ItemDragObject
|
||||
{
|
||||
public EquippedItemDragObject(EquippedItem item, Entity originEntity, int2 originCellOffset)
|
||||
: base(originCellOffset, item.EquippableItem)
|
||||
{
|
||||
EquippedItem = item;
|
||||
OriginEntity = originEntity;
|
||||
}
|
||||
|
||||
public EquippedItem EquippedItem { get; }
|
||||
public Entity OriginEntity { get; }
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/AetheriaUnityDragObjects.cs.meta
Normal file
2
Assets/Scripts/Gameplay/AetheriaUnityDragObjects.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f70b0c04a804c349915b07ef0fd9b13
|
||||
37
Assets/Scripts/Gameplay/AetheriaUnityDragSession.cs
Normal file
37
Assets/Scripts/Gameplay/AetheriaUnityDragSession.cs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
using System;
|
||||
|
||||
public sealed class AetheriaUnityDragSession
|
||||
{
|
||||
private DragObject _dragObject;
|
||||
private Action<DragObject> _endDragCallback;
|
||||
|
||||
public void Begin(DragObject dragObject)
|
||||
{
|
||||
_dragObject = dragObject;
|
||||
}
|
||||
|
||||
public bool TryGetDraggedItem(out ItemDragObject itemDragObject)
|
||||
{
|
||||
itemDragObject = _dragObject as ItemDragObject;
|
||||
return itemDragObject != null;
|
||||
}
|
||||
|
||||
public void RegisterTarget(Action<DragObject> onEndDrag)
|
||||
{
|
||||
_endDragCallback = onEndDrag;
|
||||
}
|
||||
|
||||
public void UnregisterTarget()
|
||||
{
|
||||
_endDragCallback = null;
|
||||
}
|
||||
|
||||
public bool End()
|
||||
{
|
||||
var hadTarget = _endDragCallback != null;
|
||||
_endDragCallback?.Invoke(_dragObject);
|
||||
_dragObject = null;
|
||||
_endDragCallback = null;
|
||||
return hadTarget;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/AetheriaUnityDragSession.cs.meta
Normal file
2
Assets/Scripts/Gameplay/AetheriaUnityDragSession.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6454eeaf62eadb44abbe5d54bf497312
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using Unity.Mathematics;
|
||||
|
||||
public sealed class AetheriaUnityEntityConstructionBlueprintProjector
|
||||
{
|
||||
private readonly AetheriaUnityLoadoutItemProjector _loadoutItemProjector;
|
||||
|
||||
public AetheriaUnityEntityConstructionBlueprintProjector(
|
||||
AetheriaUnityLoadoutItemProjector loadoutItemProjector)
|
||||
{
|
||||
_loadoutItemProjector = loadoutItemProjector ?? throw new ArgumentNullException(nameof(loadoutItemProjector));
|
||||
}
|
||||
|
||||
public EntityConstructionBlueprint ProjectTemplate(AetheriaRuntimeLoadoutTemplateSnapshot template)
|
||||
{
|
||||
if (template == null)
|
||||
return null;
|
||||
|
||||
var blueprint = ProjectLoadoutEntity(template.RootEntity);
|
||||
if (blueprint != null && string.IsNullOrWhiteSpace(blueprint.Name))
|
||||
blueprint.Name = template.Name;
|
||||
return blueprint;
|
||||
}
|
||||
|
||||
public EntityConstructionBlueprint ProjectLoadoutEntity(AetheriaRuntimeEntityLoadoutSnapshot entity)
|
||||
{
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
var hull = CreateEquippableItem(entity.Hull);
|
||||
if (hull == null)
|
||||
return null;
|
||||
|
||||
var blueprint = CreateBlueprint(entity.Kind);
|
||||
if (blueprint is ShipConstructionBlueprint shipBlueprint)
|
||||
{
|
||||
shipBlueprint.Direction = new float2(0, 1);
|
||||
}
|
||||
|
||||
blueprint.Name = entity.Name;
|
||||
blueprint.FactionKey = entity.FactionKey ?? "";
|
||||
blueprint.Hull = hull;
|
||||
blueprint.Equipment = CreateEquippableSlots(entity.Equipment);
|
||||
blueprint.CargoBays = CreateEquippableSlots(entity.CargoBays);
|
||||
blueprint.DockingBays = CreateEquippableSlots(entity.DockingBays);
|
||||
blueprint.CargoContents = CreateCargoBayContents(entity.CargoContents);
|
||||
blueprint.DockingBayContents = CreateCargoBayContents(entity.DockingBayContents);
|
||||
blueprint.DockingBayAssignments = entity.DockingBayAssignments.ToArray();
|
||||
blueprint.WeaponGroups = entity.WeaponGroups.Select(group => group.ToArray()).ToArray();
|
||||
blueprint.Children = entity.Children
|
||||
.Select(ProjectLoadoutEntity)
|
||||
.Where(child => child != null)
|
||||
.ToArray();
|
||||
return blueprint;
|
||||
}
|
||||
|
||||
public EntityConstructionBlueprint ProjectObservedEntity(
|
||||
AetheriaRuntimeEntitySnapshot entity,
|
||||
bool isCurrentEntity)
|
||||
{
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
var hull = CreateEquippableItem(new AetheriaRuntimeLoadoutItemSnapshot(
|
||||
entity.HullItemKey,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
true,
|
||||
false));
|
||||
if (hull == null)
|
||||
return null;
|
||||
|
||||
var blueprint = CreateBlueprint(entity.Kind);
|
||||
if (blueprint is ShipConstructionBlueprint shipBlueprint)
|
||||
{
|
||||
shipBlueprint.Position = new float3((float)entity.PositionX, (float)entity.PositionY, (float)entity.PositionZ);
|
||||
shipBlueprint.Direction = new float2((float)entity.DirectionX, (float)entity.DirectionY);
|
||||
shipBlueprint.IsPlayerShip = isCurrentEntity;
|
||||
}
|
||||
|
||||
blueprint.Name = entity.Name ?? "";
|
||||
blueprint.FactionKey = entity.FactionKey ?? "";
|
||||
blueprint.Hull = hull;
|
||||
blueprint.Equipment = CreateEquippableSlots(entity.Equipment);
|
||||
blueprint.CargoBays = CreateEquippableSlots(entity.CargoBays);
|
||||
blueprint.DockingBays = CreateEquippableSlots(entity.DockingBays);
|
||||
blueprint.CargoContents = CreateCargoBayContents(entity.CargoContents);
|
||||
blueprint.DockingBayContents = CreateCargoBayContents(entity.DockingBayContents);
|
||||
blueprint.DockingBayAssignments = entity.DockingBayAssignments.ToArray();
|
||||
blueprint.WeaponGroups = entity.WeaponGroups.Select(group => group.ToArray()).ToArray();
|
||||
blueprint.Children = Array.Empty<EntityConstructionBlueprint>();
|
||||
return blueprint;
|
||||
}
|
||||
|
||||
private static EntityConstructionBlueprint CreateBlueprint(string kind)
|
||||
{
|
||||
return string.Equals(kind, "orbital", StringComparison.OrdinalIgnoreCase)
|
||||
? new OrbitalEntityConstructionBlueprint()
|
||||
: new ShipConstructionBlueprint();
|
||||
}
|
||||
|
||||
private (int2 position, EquippableItem item)[] CreateEquippableSlots(
|
||||
IReadOnlyList<AetheriaRuntimeLoadoutItemSlotSnapshot> slots)
|
||||
{
|
||||
return (slots ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotSnapshot>())
|
||||
.Select(slot => (position: new int2(slot.X, slot.Y), item: CreateEquippableItem(slot.Item)))
|
||||
.Where(slot => slot.item != null)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private (int2 position, EquippableItem item)[] CreateEquippableSlots(
|
||||
IReadOnlyList<AetheriaRuntimeEntityItemSlotSnapshot> slots)
|
||||
{
|
||||
return (slots ?? Array.Empty<AetheriaRuntimeEntityItemSlotSnapshot>())
|
||||
.Select(slot => (position: new int2(slot.X, slot.Y), item: CreateEquippableItem(new AetheriaRuntimeLoadoutItemSnapshot(
|
||||
slot.ItemKey,
|
||||
slot.Quality,
|
||||
slot.Durability,
|
||||
slot.Quantity,
|
||||
slot.Enabled,
|
||||
slot.OverrideShutdown,
|
||||
slot.Temperature))))
|
||||
.Where(slot => slot.item != null)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private (int2 position, ItemInstance item)[][] CreateCargoBayContents(
|
||||
IReadOnlyList<AetheriaRuntimeCargoBayLoadoutSnapshot> bays)
|
||||
{
|
||||
return (bays ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutSnapshot>())
|
||||
.Select(bay => (bay.Items ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotSnapshot>())
|
||||
.Select(slot => (position: new int2(slot.X, slot.Y), item: _loadoutItemProjector.CreateLoadoutItem(slot.Item)))
|
||||
.Where(slot => slot.item != null)
|
||||
.ToArray())
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private EquippableItem CreateEquippableItem(AetheriaRuntimeLoadoutItemSnapshot item)
|
||||
{
|
||||
var instance = _loadoutItemProjector.CreateLoadoutItem(item) as EquippableItem;
|
||||
if (instance != null && item.Durability > 0)
|
||||
instance.Durability = (float)item.Durability;
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 88f0588c14c7a1d4c87095a96585c957
|
||||
117
Assets/Scripts/Gameplay/AetheriaUnityGameplayBootShell.cs
Normal file
117
Assets/Scripts/Gameplay/AetheriaUnityGameplayBootShell.cs
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/* 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 AetheriaUnityGameplayBootShell
|
||||
{
|
||||
public GameSettings Settings { get; set; }
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public AetheriaUnityCockpitHudShell CockpitHudShell { get; set; }
|
||||
public float TargetSpottedBlinkFrequency { get; set; }
|
||||
public float TargetSpottedBlinkOffset { get; set; }
|
||||
public Action<string> Log { get; set; }
|
||||
|
||||
public AetheriaUnityGameplayBootResult Boot()
|
||||
{
|
||||
var stateBoot = AetheriaRuntimeStateBoot.Inspect(AetheriaUnityRuntimePaths.GameDataDirectory);
|
||||
Log?.Invoke($"Aetheria runtime target: {stateBoot.TargetLabel} via {stateBoot.TargetKind} ({stateBoot.TargetSource})");
|
||||
Log?.Invoke($"Aetheria runtime id: {stateBoot.RuntimeId}");
|
||||
Log?.Invoke($"Aetheria runtime state file: {stateBoot.StateFilePath}");
|
||||
stateBoot = SyncRemoteReplicaBeforeBoot(stateBoot);
|
||||
|
||||
if (!stateBoot.SupportsLocalStateFileRead)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Aetheria runtime target cannot read the daemon mirror state required for gameplay boot: {stateBoot.FailureMessage}");
|
||||
}
|
||||
|
||||
if (!stateBoot.StateFileExists)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Aetheria runtime state file is missing at {stateBoot.StateFilePath}; gameplay requires an authoritative daemon mirror.");
|
||||
}
|
||||
|
||||
var runtimeCatalog = AetheriaUnityRuntimeClientProvider.ResolveClient(stateBoot.StateFilePath, stateBoot.RuntimeId)
|
||||
.OpenRuntimeCatalog();
|
||||
if (runtimeCatalog == null)
|
||||
throw new InvalidOperationException("Aetheria typed runtime catalog is required before gameplay boot.");
|
||||
|
||||
Log?.Invoke($"Aetheria runtime catalog: {runtimeCatalog.Items.Count} items, {runtimeCatalog.Corporations.Count} corporations, {runtimeCatalog.NameFiles.Count} name files");
|
||||
|
||||
var itemManager = new ItemManager(
|
||||
runtimeCatalog,
|
||||
Settings.GameplaySettings,
|
||||
message => Log?.Invoke(message));
|
||||
var loadoutItemProjector = new AetheriaUnityLoadoutItemProjector(itemManager, runtimeCatalog);
|
||||
ZoneRenderer.SetDroppedPickupItemProjector(loadoutItemProjector.CreateLoadoutItem);
|
||||
ZoneRenderer.BodySettingsCollections = Settings.BodySettingsCollections;
|
||||
ZoneRenderer.RenderSettings = AetheriaUnityRenderSettingsBridge.Build(
|
||||
Settings,
|
||||
TargetSpottedBlinkFrequency,
|
||||
TargetSpottedBlinkOffset);
|
||||
CockpitHudShell.SetRenderSettings(ZoneRenderer.RenderSettings);
|
||||
|
||||
if (!AetheriaUnityRuntimeClientProvider.PlayerSettings.GraphicsSettings.ShowAsteroidsInMinimap)
|
||||
ZoneRenderer.ShowAsteroidUI = false;
|
||||
|
||||
return new AetheriaUnityGameplayBootResult(
|
||||
runtimeCatalog,
|
||||
itemManager,
|
||||
loadoutItemProjector);
|
||||
}
|
||||
|
||||
private AetheriaRuntimeStateBootReport SyncRemoteReplicaBeforeBoot(AetheriaRuntimeStateBootReport stateBoot)
|
||||
{
|
||||
if (!ShouldSyncRemoteReplicaBeforeBoot(stateBoot))
|
||||
return stateBoot;
|
||||
|
||||
Log?.Invoke($"Aetheria remote Verse replica missing; syncing {stateBoot.TargetLabel} from {stateBoot.CultMeshAddress}");
|
||||
try
|
||||
{
|
||||
var target = AetheriaState.At(AetheriaUnityRuntimePaths.GameDataDirectory)
|
||||
.ClientTarget
|
||||
.SyncReplica();
|
||||
AetheriaUnityRuntimePaths.ClearRuntimeStateFilePathCache();
|
||||
|
||||
var refreshed = AetheriaRuntimeStateBoot.Inspect(AetheriaUnityRuntimePaths.GameDataDirectory);
|
||||
Log?.Invoke($"Aetheria remote Verse replica synced: {refreshed.StateFilePath}");
|
||||
if (!string.IsNullOrWhiteSpace(target.LastReplicaSyncAtUtc))
|
||||
Log?.Invoke($"Aetheria remote Verse replica sync time: {target.LastReplicaSyncAtUtc}");
|
||||
return refreshed;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AetheriaUnityRuntimePaths.ClearRuntimeStateFilePathCache();
|
||||
throw new InvalidOperationException(
|
||||
$"Aetheria remote Verse replica sync failed before gameplay boot: {ex.Message}",
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ShouldSyncRemoteReplicaBeforeBoot(AetheriaRuntimeStateBootReport stateBoot)
|
||||
{
|
||||
return string.Equals(stateBoot.TargetSource, "client-target", StringComparison.Ordinal)
|
||||
&& string.Equals(stateBoot.TargetKind, AetheriaRuntimeClientTargetKinds.CultMeshVerse, StringComparison.Ordinal)
|
||||
&& (!stateBoot.SupportsLocalStateFileRead || !stateBoot.StateFileExists);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct AetheriaUnityGameplayBootResult
|
||||
{
|
||||
public AetheriaUnityGameplayBootResult(
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
ItemManager itemManager,
|
||||
AetheriaUnityLoadoutItemProjector loadoutItemProjector)
|
||||
{
|
||||
RuntimeCatalog = runtimeCatalog;
|
||||
ItemManager = itemManager;
|
||||
LoadoutItemProjector = loadoutItemProjector;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCatalogSnapshot RuntimeCatalog { get; }
|
||||
public ItemManager ItemManager { get; }
|
||||
public AetheriaUnityLoadoutItemProjector LoadoutItemProjector { get; }
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 70318b35e2014bdfad48683869bfc04d
|
||||
218
Assets/Scripts/Gameplay/AetheriaUnityGameplayInputShell.cs
Normal file
218
Assets/Scripts/Gameplay/AetheriaUnityGameplayInputShell.cs
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
public sealed class AetheriaUnityGameplayInputShell : IDisposable
|
||||
{
|
||||
private readonly List<ActionBarSlot> _actionBarSlots = new List<ActionBarSlot>();
|
||||
private readonly List<InputAction> _actionBarActions = new List<InputAction>();
|
||||
private bool _uiHidden;
|
||||
private int _zoomLevelIndex;
|
||||
|
||||
public AetheriaInput Input { get; private set; }
|
||||
public RuntimePlayerSettings RuntimePlayerSettings { get; set; }
|
||||
public InputDisplayLayout InputDisplayLayout { get; set; }
|
||||
public ConfirmationDialog Dialog { get; set; }
|
||||
public MainMenu MainMenu { get; set; }
|
||||
public MenuPanel Menu { get; set; }
|
||||
public MapRenderer MenuMap { get; set; }
|
||||
public CanvasGroup GameplayUI { get; set; }
|
||||
public Transform ActionBar { get; set; }
|
||||
public ActionBarSlot ActionBarSlot { get; set; }
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public AetheriaUnityMenuShell MenuShell { get; set; }
|
||||
public AetheriaUnityDragSession DragSession { get; set; }
|
||||
public AetheriaUnityActionBarPresentation ActionBarPresentation { get; set; }
|
||||
public AetheriaUnityPilotOperationAdapter PilotOperationAdapter { get; set; }
|
||||
public Func<Entity> ResolveCurrentEntity { get; set; }
|
||||
public Action<AetheriaInput> SetInput { get; set; }
|
||||
|
||||
public IReadOnlyList<ActionBarSlot> ActionBarSlots => _actionBarSlots;
|
||||
|
||||
public void Bootstrap()
|
||||
{
|
||||
Input = new AetheriaInput();
|
||||
SetInput?.Invoke(Input);
|
||||
|
||||
if (RuntimePlayerSettings?.InputSettings != null)
|
||||
{
|
||||
foreach (var binding in RuntimePlayerSettings.InputSettings.InputActionMap)
|
||||
Input.asset[binding.Key.action].ApplyBindingOverride(binding.Key.binding, binding.Value);
|
||||
}
|
||||
|
||||
if (InputDisplayLayout != null)
|
||||
InputDisplayLayout.Input = Input.asset;
|
||||
|
||||
Dialog?.SetInputGate(
|
||||
() => Input.Global.Enable(),
|
||||
() => Input.Global.Disable());
|
||||
Input.Global.Enable();
|
||||
|
||||
_zoomLevelIndex = ZoneRenderer.RenderSettings.ResolveDefaultMinimapZoomIndex();
|
||||
ZoneRenderer.MinimapDistance = (float)ZoneRenderer.RenderSettings.ResolveMinimapDistance(_zoomLevelIndex);
|
||||
|
||||
RegisterGlobalInput();
|
||||
RegisterPlayerInput();
|
||||
RegisterActionBarInput();
|
||||
}
|
||||
|
||||
public void EnablePlayerInput()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
Input.Player.Enable();
|
||||
foreach (var action in _actionBarActions)
|
||||
action.Enable();
|
||||
}
|
||||
|
||||
public void DisablePlayerInput()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.None;
|
||||
Input.Player.Disable();
|
||||
foreach (var action in _actionBarActions)
|
||||
action.Disable();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var action in _actionBarActions)
|
||||
action.Dispose();
|
||||
_actionBarActions.Clear();
|
||||
_actionBarSlots.Clear();
|
||||
Input?.Dispose();
|
||||
Input = null;
|
||||
}
|
||||
|
||||
private void RegisterGlobalInput()
|
||||
{
|
||||
Input.Global.ZoneMap.performed += context =>
|
||||
{
|
||||
MenuShell.ToggleMenuTab(MenuTab.Map);
|
||||
var currentEntity = ResolveCurrentEntity?.Invoke();
|
||||
if (currentEntity == null)
|
||||
return;
|
||||
|
||||
MenuMap.Position = AetheriaMath.ToUnity(currentEntity.CultPositionXZ);
|
||||
};
|
||||
|
||||
Input.Global.Inventory.performed += context => MenuShell.ToggleMenuTab(MenuTab.Inventory);
|
||||
Input.Global.GalaxyMap.performed += context => MenuShell.ToggleMenuTab(MenuTab.Galaxy);
|
||||
|
||||
Input.Global.Interact.performed += context =>
|
||||
{
|
||||
if (IsTextInputFocused() || MainMenu.gameObject.activeSelf)
|
||||
return;
|
||||
|
||||
if (ResolveCurrentEntity?.Invoke() == null)
|
||||
{
|
||||
Dialog.Clear();
|
||||
Dialog.Title.text = "Can't undock. You dont have a ship!";
|
||||
Dialog.Show();
|
||||
Dialog.MoveToCursor();
|
||||
return;
|
||||
}
|
||||
|
||||
PilotOperationAdapter.RequestInteract();
|
||||
};
|
||||
|
||||
Input.Global.MainMenu.performed += context =>
|
||||
{
|
||||
if (Menu.gameObject.activeSelf)
|
||||
MenuShell.ToggleMenuTab(Menu.CurrentTab);
|
||||
else
|
||||
MenuShell.ToggleFullscreenMenu(MainMenu.gameObject);
|
||||
};
|
||||
|
||||
Input.Global.InputScreen.performed += context => MenuShell.ToggleFullscreenMenu(MenuShell.HelpScreen);
|
||||
}
|
||||
|
||||
private void RegisterPlayerInput()
|
||||
{
|
||||
Input.Player.MinimapZoom.performed += context =>
|
||||
{
|
||||
_zoomLevelIndex = ZoneRenderer.RenderSettings.ResolveNextMinimapZoomIndex(_zoomLevelIndex);
|
||||
ZoneRenderer.MinimapDistance = (float)ZoneRenderer.RenderSettings.ResolveMinimapDistance(_zoomLevelIndex);
|
||||
};
|
||||
|
||||
Input.Player.HideUI.performed += context =>
|
||||
{
|
||||
_uiHidden = !_uiHidden;
|
||||
GameplayUI.alpha = _uiHidden ? 0 : 1;
|
||||
ActionBar.gameObject.SetActive(!_uiHidden);
|
||||
};
|
||||
|
||||
Input.Player.OverrideShutdown.performed += context =>
|
||||
{
|
||||
var currentEntity = ResolveCurrentEntity?.Invoke();
|
||||
if (currentEntity != null)
|
||||
PilotOperationAdapter.RequestOverrideShutdown(!currentEntity.OverrideShutdown);
|
||||
};
|
||||
|
||||
Input.Player.Ping.performed += context => PilotOperationAdapter.RequestSensorPing();
|
||||
Input.Player.ToggleHeatsinks.performed += context =>
|
||||
{
|
||||
var currentEntity = ResolveCurrentEntity?.Invoke();
|
||||
if (currentEntity != null)
|
||||
PilotOperationAdapter.RequestHeatsinksEnabled(!currentEntity.HeatsinksEnabled);
|
||||
};
|
||||
Input.Player.ToggleShield.performed += context => PilotOperationAdapter.RequestShieldToggle();
|
||||
Input.Player.TargetReticle.performed += context => PilotOperationAdapter.RequestTargetReticle();
|
||||
Input.Player.TargetNearest.performed += context => PilotOperationAdapter.RequestTargetNearest();
|
||||
Input.Player.TargetNext.performed += context => PilotOperationAdapter.RequestTargetNext();
|
||||
Input.Player.TargetPrevious.performed += context => PilotOperationAdapter.RequestTargetPrevious();
|
||||
}
|
||||
|
||||
private void RegisterActionBarInput()
|
||||
{
|
||||
foreach (var controlPath in (RuntimePlayerSettings?.InputSettings?.ActionBarInputs ?? Enumerable.Empty<string>()).OrderBy(input => input))
|
||||
CreateActionBarSlot(controlPath);
|
||||
}
|
||||
|
||||
private void CreateActionBarSlot(string controlPath)
|
||||
{
|
||||
var action = new InputAction(binding: controlPath);
|
||||
_actionBarActions.Add(action);
|
||||
|
||||
var slot = UnityEngine.Object.Instantiate(ActionBarSlot, ActionBar);
|
||||
slot.ControlPath = controlPath;
|
||||
slot.Binding = null;
|
||||
_actionBarSlots.Add(slot);
|
||||
|
||||
action.started += context => slot.Binding?.Activate();
|
||||
action.canceled += context => slot.Binding?.Deactivate();
|
||||
|
||||
var shortName = controlPath.Substring(controlPath.LastIndexOf('/') + 1);
|
||||
var sprite = Resources.Load<Sprite>($"Sprites/Input/{shortName}");
|
||||
if (sprite != null)
|
||||
{
|
||||
slot.InputIcon.sprite = sprite;
|
||||
slot.InputLabel.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
slot.InputLabel.text = shortName;
|
||||
slot.InputIcon.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
slot.PointerEnterTrigger.OnPointerEnterAsObservable().Subscribe(_ =>
|
||||
{
|
||||
DragSession.RegisterTarget(dragAction => ActionBarPresentation.RequestBinding(slot, dragAction));
|
||||
});
|
||||
slot.PointerExitTrigger.OnPointerExitAsObservable().Subscribe(_ => DragSession.UnregisterTarget());
|
||||
}
|
||||
|
||||
private static bool IsTextInputFocused()
|
||||
{
|
||||
return EventSystem.current != null &&
|
||||
EventSystem.current.currentSelectedGameObject != null &&
|
||||
EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 055f68d70b7c7634991717c468672f15
|
||||
35
Assets/Scripts/Gameplay/AetheriaUnityGameplayLoopShell.cs
Normal file
35
Assets/Scripts/Gameplay/AetheriaUnityGameplayLoopShell.cs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/* 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;
|
||||
|
||||
public sealed class AetheriaUnityGameplayLoopShell
|
||||
{
|
||||
public bool Paused { get; set; }
|
||||
public Func<Entity> ResolveCurrentEntity { get; set; }
|
||||
public Func<bool> IsCurrentEntityUndocked { get; set; }
|
||||
public Action ApplyLatestZoneRender { get; set; }
|
||||
public AetheriaUnityCurrentEntityPresentation CurrentEntityPresentation { get; set; }
|
||||
public AetheriaUnityPilotFrameAdapter PilotFrameAdapter { get; set; }
|
||||
public AetheriaUnityTargetPresentation TargetPresentation { get; set; }
|
||||
|
||||
public void Tick(float deltaTime, float time)
|
||||
{
|
||||
if (Paused)
|
||||
return;
|
||||
|
||||
ApplyLatestZoneRender?.Invoke();
|
||||
CurrentEntityPresentation?.Tick(deltaTime);
|
||||
if (IsCurrentEntityUndocked?.Invoke() == true)
|
||||
PilotFrameAdapter?.Tick(ResolveCurrentEntity?.Invoke(), deltaTime, time);
|
||||
}
|
||||
|
||||
public void LateTick()
|
||||
{
|
||||
TargetPresentation?.UpdateTargetIndicators(
|
||||
ResolveCurrentEntity?.Invoke(),
|
||||
IsCurrentEntityUndocked?.Invoke() == true,
|
||||
CurrentEntityPresentation);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f4705e6dd36d4d89add3f3751008bf82
|
||||
147
Assets/Scripts/Gameplay/AetheriaUnityGameplaySceneWiring.cs
Normal file
147
Assets/Scripts/Gameplay/AetheriaUnityGameplaySceneWiring.cs
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
/* 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 Cinemachine;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public sealed class AetheriaUnityGameplaySceneWiring
|
||||
{
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public CinemachineVirtualCamera DockCamera { get; set; }
|
||||
public CinemachineVirtualCamera FollowCamera { get; set; }
|
||||
public MenuPanel Menu { get; set; }
|
||||
public TradeMenu TradeMenu { get; set; }
|
||||
public CanvasGroup GameplayUI { get; set; }
|
||||
public InventoryMenu Inventory { get; set; }
|
||||
public InventoryPanel ShipPanel { get; set; }
|
||||
public InventoryPanel TargetShipPanel { get; set; }
|
||||
public SchematicDisplay SchematicDisplay { get; set; }
|
||||
public SchematicDisplay TargetSchematicDisplay { get; set; }
|
||||
public PlaceUIElementWorldspace[] Crosshairs { get; set; } = Array.Empty<PlaceUIElementWorldspace>();
|
||||
public Prototype LockIndicator { get; set; }
|
||||
public GameObject HitMarker { get; set; }
|
||||
public float HitMarkerDuration { get; set; }
|
||||
public Image TargetShieldsBackground { get; set; }
|
||||
public Image TargetShieldsIcon { get; set; }
|
||||
public Color ShieldColor { get; set; }
|
||||
public Color NoShieldColor { get; set; }
|
||||
public Sprite ShieldIcon { get; set; }
|
||||
public Sprite NoShieldIcon { get; set; }
|
||||
public Prototype HostileTargetIndicator { get; set; }
|
||||
public Prototype FriendlyTargetIndicator { get; set; }
|
||||
public PlaceUIElementWorldspace ViewDot { get; set; }
|
||||
public PlaceUIElementWorldspace TargetIndicator { get; set; }
|
||||
public Image TargetHitpointsFill { get; set; }
|
||||
public Image TargetVisibilityFill { get; set; }
|
||||
public Image VisibilityToTargetFill { get; set; }
|
||||
public Image TargetShieldsFill { get; set; }
|
||||
public MainMenu MainMenu { get; set; }
|
||||
|
||||
public void ConfigureCurrentEntityPresentation(
|
||||
AetheriaUnityCurrentEntityPresentation presentation,
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog)
|
||||
{
|
||||
if (presentation == null)
|
||||
return;
|
||||
|
||||
presentation.ZoneRenderer = ZoneRenderer;
|
||||
presentation.RuntimeCatalog = runtimeCatalog;
|
||||
presentation.DockCamera = DockCamera;
|
||||
presentation.FollowCamera = FollowCamera;
|
||||
presentation.Menu = Menu;
|
||||
presentation.TradeMenu = TradeMenu;
|
||||
presentation.GameplayUI = GameplayUI;
|
||||
presentation.ShipPanel = ShipPanel;
|
||||
presentation.TargetShipPanel = TargetShipPanel;
|
||||
presentation.SchematicDisplay = SchematicDisplay;
|
||||
presentation.TargetSchematicDisplay = TargetSchematicDisplay;
|
||||
presentation.Crosshairs = Crosshairs;
|
||||
presentation.LockIndicator = LockIndicator;
|
||||
presentation.HitMarker = HitMarker;
|
||||
presentation.HitMarkerDuration = HitMarkerDuration;
|
||||
presentation.TargetImages = new ImageTargetPresentation
|
||||
{
|
||||
TargetShieldsBackground = TargetShieldsBackground,
|
||||
TargetShieldsIcon = TargetShieldsIcon,
|
||||
ShieldColor = ShieldColor,
|
||||
NoShieldColor = NoShieldColor,
|
||||
ShieldIcon = ShieldIcon,
|
||||
NoShieldIcon = NoShieldIcon
|
||||
};
|
||||
}
|
||||
|
||||
public void ConfigureTargetPresentation(
|
||||
AetheriaUnityTargetPresentation presentation,
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
AetheriaUnityObservedFacadeIndex observedFacadeIndex,
|
||||
AetheriaUnityObservedTargetQuery observedTargetQuery,
|
||||
Func<AetheriaClient> resolveClient)
|
||||
{
|
||||
if (presentation == null)
|
||||
return;
|
||||
|
||||
presentation.ZoneRenderer = ZoneRenderer;
|
||||
presentation.RuntimeCatalog = runtimeCatalog;
|
||||
presentation.HostileTargetIndicator = HostileTargetIndicator;
|
||||
presentation.FriendlyTargetIndicator = FriendlyTargetIndicator;
|
||||
presentation.ViewDot = ViewDot;
|
||||
presentation.TargetIndicator = TargetIndicator;
|
||||
presentation.TargetHitpointsFill = TargetHitpointsFill;
|
||||
presentation.TargetVisibilityFill = TargetVisibilityFill;
|
||||
presentation.VisibilityToTargetFill = VisibilityToTargetFill;
|
||||
presentation.TargetShieldsFill = TargetShieldsFill;
|
||||
presentation.ResolveClient = resolveClient;
|
||||
presentation.ResolveEntity = daemonEntityIndex =>
|
||||
observedFacadeIndex != null &&
|
||||
observedFacadeIndex.TryResolveEntityByDaemonIndex(daemonEntityIndex, out var entity)
|
||||
? entity
|
||||
: null;
|
||||
presentation.ResolveTarget = observedTargetQuery.GetObservedTarget;
|
||||
presentation.ResolveInfoGathered = observedTargetQuery.GetObservedInfoGathered;
|
||||
presentation.ResolveHostileContact = observedTargetQuery.IsObservedHostileContact;
|
||||
presentation.ResolveVisibleContacts = observedTargetQuery.GetObservedVisibleContacts;
|
||||
}
|
||||
|
||||
public void ConfigureInventoryDragSession(AetheriaUnityDragSession dragSession)
|
||||
{
|
||||
Inventory?.SetDragSession(dragSession);
|
||||
ShipPanel?.SetDragSession(dragSession);
|
||||
TargetShipPanel?.SetDragSession(dragSession);
|
||||
}
|
||||
|
||||
public void ConfigureActionBarPresentation(
|
||||
AetheriaUnityActionBarPresentation actionBarPresentation,
|
||||
AetheriaUnityGameplayInputShell gameplayInputShell,
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
GameSettings settings,
|
||||
Func<Entity> resolveCurrentEntity,
|
||||
Func<AetheriaClient> resolveActionBarClient)
|
||||
{
|
||||
actionBarPresentation?.Bind(
|
||||
gameplayInputShell?.ActionBarSlots ?? Array.Empty<ActionBarSlot>(),
|
||||
runtimeCatalog,
|
||||
settings,
|
||||
resolveCurrentEntity,
|
||||
resolveActionBarClient);
|
||||
Inventory?.SetActionBarPresentation(actionBarPresentation);
|
||||
}
|
||||
|
||||
public void ConfigureRuntimeInputScreenShell(AetheriaUnityMenuShell menuShell)
|
||||
{
|
||||
MainMenu?.SetRuntimeInputScreenShell(menuShell.CanOpenRuntimeInputScreen, menuShell.ShowRuntimeInputScreen);
|
||||
}
|
||||
|
||||
public void ConfigureObservedFacadeIndex(AetheriaUnityObservedFacadeIndex observedFacadeIndex)
|
||||
{
|
||||
Inventory?.SetObservedFacadeIndex(observedFacadeIndex);
|
||||
ShipPanel?.SetObservedFacadeIndex(observedFacadeIndex);
|
||||
TargetShipPanel?.SetObservedFacadeIndex(observedFacadeIndex);
|
||||
foreach (var localMenu in UnityEngine.Object.FindObjectsByType<LocalMenu>(FindObjectsSortMode.None))
|
||||
localMenu.SetObservedFacadeIndex(observedFacadeIndex);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e78937590444255a8c972a3d4f69130
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
63
Assets/Scripts/Gameplay/AetheriaUnityLoadoutItemProjector.cs
Normal file
63
Assets/Scripts/Gameplay/AetheriaUnityLoadoutItemProjector.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* 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 AetheriaUnityLoadoutItemProjector
|
||||
{
|
||||
private readonly ItemManager _itemManager;
|
||||
private readonly AetheriaRuntimeCatalogSnapshot _catalog;
|
||||
|
||||
public AetheriaUnityLoadoutItemProjector(
|
||||
ItemManager itemManager,
|
||||
AetheriaRuntimeCatalogSnapshot catalog)
|
||||
{
|
||||
_itemManager = itemManager ?? throw new ArgumentNullException(nameof(itemManager));
|
||||
_catalog = catalog ?? throw new ArgumentNullException(nameof(catalog));
|
||||
}
|
||||
|
||||
public ItemInstance CreateLoadoutItem(AetheriaRuntimeLoadoutItemCommit item)
|
||||
{
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return CreateLoadoutItem(
|
||||
item.ItemKey,
|
||||
item.Quality,
|
||||
item.Durability,
|
||||
Math.Max(1, item.Quantity));
|
||||
}
|
||||
|
||||
public ItemInstance CreateLoadoutItem(AetheriaRuntimeLoadoutItemSnapshot item)
|
||||
{
|
||||
if (item == null)
|
||||
return null;
|
||||
|
||||
return CreateLoadoutItem(
|
||||
item.ItemKey,
|
||||
item.Quality,
|
||||
item.Durability,
|
||||
Math.Max(1, item.Quantity));
|
||||
}
|
||||
|
||||
private ItemInstance CreateLoadoutItem(
|
||||
string itemKey,
|
||||
double quality,
|
||||
double durability,
|
||||
int quantity)
|
||||
{
|
||||
var typedItem = _catalog.FindItem(itemKey ?? "");
|
||||
if (typedItem == null)
|
||||
return null;
|
||||
|
||||
if (typedItem.Stackable)
|
||||
return _itemManager.CreateSimpleCommodityInstance(typedItem, Math.Max(1, quantity));
|
||||
|
||||
var instance = _itemManager.CreateCraftedInstance(typedItem, (float)quality);
|
||||
if (instance is EquippableItem equippable && durability > 0)
|
||||
equippable.Durability = (float)durability;
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f14a61accda77214798bd71817fa2dcb
|
||||
129
Assets/Scripts/Gameplay/AetheriaUnityMenuShell.cs
Normal file
129
Assets/Scripts/Gameplay/AetheriaUnityMenuShell.cs
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
/* 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 TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
public sealed class AetheriaUnityMenuShell
|
||||
{
|
||||
public MainMenu MainMenu { get; set; }
|
||||
public GameObject HelpScreen { get; set; }
|
||||
public InputDisplayLayout InputDisplayLayout { get; set; }
|
||||
public GameObject UiRoot { get; set; }
|
||||
public MenuPanel Menu { get; set; }
|
||||
public CanvasGroup GameplayUI { get; set; }
|
||||
public Func<Entity> ResolveCurrentEntity { get; set; }
|
||||
public Func<bool> IsCurrentEntityUndocked { get; set; }
|
||||
public Func<Entity, Entity> ResolveObservedTarget { get; set; }
|
||||
public Action<bool> SetPaused { get; set; }
|
||||
public Action EnablePlayerInput { get; set; }
|
||||
public Action DisablePlayerInput { get; set; }
|
||||
public Action UpdatePlayerPanel { get; set; }
|
||||
public Action<Entity> UpdateTargetPanel { get; set; }
|
||||
|
||||
private bool _menuShownBeforeFullscreen;
|
||||
|
||||
public bool CanOpenRuntimeInputScreen()
|
||||
{
|
||||
return ResolveCurrentEntity?.Invoke() != null &&
|
||||
HelpScreen != null &&
|
||||
InputDisplayLayout != null;
|
||||
}
|
||||
|
||||
public void ShowRuntimeInputScreen()
|
||||
{
|
||||
ShowFullscreenMenu(HelpScreen);
|
||||
}
|
||||
|
||||
public void ToggleFullscreenMenu(GameObject menu)
|
||||
{
|
||||
if (IsTextInputFocused() || menu == null || ResolveCurrentEntity?.Invoke() == null)
|
||||
return;
|
||||
|
||||
if (menu.activeSelf)
|
||||
HideFullscreenMenu(menu);
|
||||
else
|
||||
ShowFullscreenMenu(menu);
|
||||
}
|
||||
|
||||
public void ToggleMenuTab(MenuTab tab)
|
||||
{
|
||||
if (IsTextInputFocused() || MainMenu == null || Menu == null)
|
||||
return;
|
||||
if (MainMenu.gameObject.activeSelf)
|
||||
return;
|
||||
|
||||
if (Menu.gameObject.activeSelf && Menu.CurrentTab == tab)
|
||||
{
|
||||
Menu.gameObject.SetActive(false);
|
||||
if (IsCurrentEntityUndocked?.Invoke() == true)
|
||||
{
|
||||
EnablePlayerInput?.Invoke();
|
||||
RefreshCurrentPanels();
|
||||
if (GameplayUI != null)
|
||||
GameplayUI.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
DisablePlayerInput?.Invoke();
|
||||
Menu.ShowTab(tab);
|
||||
if (GameplayUI != null)
|
||||
GameplayUI.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void ShowFullscreenMenu(GameObject menu)
|
||||
{
|
||||
if (IsTextInputFocused() || menu == null || ResolveCurrentEntity?.Invoke() == null)
|
||||
return;
|
||||
|
||||
if (MainMenu != null && MainMenu.gameObject != menu)
|
||||
MainMenu.gameObject.SetActive(false);
|
||||
if (HelpScreen != null && HelpScreen != menu)
|
||||
HelpScreen.SetActive(false);
|
||||
|
||||
SetPaused?.Invoke(true);
|
||||
menu.SetActive(true);
|
||||
if (UiRoot != null)
|
||||
UiRoot.SetActive(false);
|
||||
|
||||
_menuShownBeforeFullscreen = Menu != null && Menu.gameObject.activeSelf;
|
||||
if (!_menuShownBeforeFullscreen)
|
||||
DisablePlayerInput?.Invoke();
|
||||
}
|
||||
|
||||
private void HideFullscreenMenu(GameObject menu)
|
||||
{
|
||||
if (menu == null || ResolveCurrentEntity?.Invoke() == null)
|
||||
return;
|
||||
|
||||
SetPaused?.Invoke(false);
|
||||
menu.SetActive(false);
|
||||
if (UiRoot != null)
|
||||
UiRoot.SetActive(true);
|
||||
|
||||
if (!_menuShownBeforeFullscreen)
|
||||
{
|
||||
EnablePlayerInput?.Invoke();
|
||||
RefreshCurrentPanels();
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshCurrentPanels()
|
||||
{
|
||||
var currentEntity = ResolveCurrentEntity?.Invoke();
|
||||
UpdatePlayerPanel?.Invoke();
|
||||
UpdateTargetPanel?.Invoke(ResolveObservedTarget?.Invoke(currentEntity));
|
||||
}
|
||||
|
||||
private static bool IsTextInputFocused()
|
||||
{
|
||||
return EventSystem.current != null &&
|
||||
EventSystem.current.currentSelectedGameObject != null &&
|
||||
EventSystem.current.currentSelectedGameObject.GetComponent<TMP_InputField>() != null;
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/AetheriaUnityMenuShell.cs.meta
Normal file
2
Assets/Scripts/Gameplay/AetheriaUnityMenuShell.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1a95f06d9ca2ddb47a07fdc47791f5af
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3131bc989a39393489b141a3d040e186
|
||||
98
Assets/Scripts/Gameplay/AetheriaUnityObservedFacadeIndex.cs
Normal file
98
Assets/Scripts/Gameplay/AetheriaUnityObservedFacadeIndex.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public sealed class AetheriaUnityObservedFacadeIndex
|
||||
{
|
||||
private readonly Dictionary<string, Entity> _entitiesByRecordKey = new Dictionary<string, Entity>(StringComparer.Ordinal);
|
||||
private readonly Dictionary<int, Entity> _entitiesByDaemonIndex = new Dictionary<int, Entity>();
|
||||
|
||||
public IReadOnlyDictionary<string, Entity> EntitiesByRecordKey => _entitiesByRecordKey;
|
||||
|
||||
public IReadOnlyDictionary<int, Entity> EntitiesByDaemonIndex => _entitiesByDaemonIndex;
|
||||
|
||||
public int Count => _entitiesByRecordKey.Count;
|
||||
|
||||
public bool ContainsRecordKey(string recordKey)
|
||||
{
|
||||
return !string.IsNullOrWhiteSpace(recordKey) &&
|
||||
_entitiesByRecordKey.ContainsKey(recordKey);
|
||||
}
|
||||
|
||||
public void Replace(IReadOnlyDictionary<string, Entity> entitiesByRecordKey)
|
||||
{
|
||||
_entitiesByRecordKey.Clear();
|
||||
if (entitiesByRecordKey != null)
|
||||
{
|
||||
foreach (var pair in entitiesByRecordKey)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(pair.Key) && pair.Value != null)
|
||||
_entitiesByRecordKey[pair.Key] = pair.Value;
|
||||
}
|
||||
}
|
||||
|
||||
RebuildDaemonIndex();
|
||||
}
|
||||
|
||||
public void RefreshDaemonIndex()
|
||||
{
|
||||
RebuildDaemonIndex();
|
||||
}
|
||||
|
||||
public bool TryResolveEntityRecordKey(Entity entity, out string recordKey)
|
||||
{
|
||||
recordKey = "";
|
||||
if (entity == null)
|
||||
return false;
|
||||
|
||||
foreach (var pair in _entitiesByRecordKey)
|
||||
{
|
||||
if (ReferenceEquals(pair.Value, entity))
|
||||
{
|
||||
recordKey = pair.Key;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryResolveEntityByRecordKey(string recordKey, out Entity entity)
|
||||
{
|
||||
entity = null;
|
||||
return !string.IsNullOrWhiteSpace(recordKey) &&
|
||||
_entitiesByRecordKey.TryGetValue(recordKey, out entity);
|
||||
}
|
||||
|
||||
public bool TryResolveEntityByDaemonIndex(int daemonEntityIndex, out Entity entity)
|
||||
{
|
||||
return _entitiesByDaemonIndex.TryGetValue(daemonEntityIndex, out entity);
|
||||
}
|
||||
|
||||
public bool TryResolveDockingBayByRecordKey(
|
||||
string parentRecordKey,
|
||||
int dockingBayIndex,
|
||||
out EquippedDockingBay dockingBay)
|
||||
{
|
||||
dockingBay = null;
|
||||
if (dockingBayIndex < 0 ||
|
||||
!TryResolveEntityByRecordKey(parentRecordKey, out var parent) ||
|
||||
parent?.DockingBays == null ||
|
||||
dockingBayIndex >= parent.DockingBays.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
dockingBay = parent.DockingBays[dockingBayIndex];
|
||||
return dockingBay != null;
|
||||
}
|
||||
|
||||
private void RebuildDaemonIndex()
|
||||
{
|
||||
_entitiesByDaemonIndex.Clear();
|
||||
foreach (var entity in _entitiesByRecordKey.Values)
|
||||
{
|
||||
if (entity != null && entity.DaemonEntityIndex >= 0)
|
||||
_entitiesByDaemonIndex[entity.DaemonEntityIndex] = entity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1561fad48f5f1aa43a9070d788f6eaa7
|
||||
337
Assets/Scripts/Gameplay/AetheriaUnityObservedFacadeProjector.cs
Normal file
337
Assets/Scripts/Gameplay/AetheriaUnityObservedFacadeProjector.cs
Normal file
|
|
@ -0,0 +1,337 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
|
||||
public sealed class AetheriaUnityObservedFacadeProjector
|
||||
{
|
||||
private readonly AetheriaUnityObservedFacadeIndex _facadeIndex;
|
||||
private readonly ItemManager _itemManager;
|
||||
private readonly Func<AetheriaRuntimeEntitySnapshot, bool, EntityConstructionBlueprint> _createBlueprint;
|
||||
private readonly Func<AetheriaRuntimeLoadoutItemSnapshot, ItemInstance> _createLoadoutItem;
|
||||
private readonly Action<string> _logWarning;
|
||||
|
||||
public AetheriaUnityObservedFacadeProjector(
|
||||
AetheriaUnityObservedFacadeIndex facadeIndex,
|
||||
ItemManager itemManager,
|
||||
Func<AetheriaRuntimeEntitySnapshot, bool, EntityConstructionBlueprint> createBlueprint,
|
||||
Func<AetheriaRuntimeLoadoutItemSnapshot, ItemInstance> createLoadoutItem,
|
||||
Action<string> logWarning)
|
||||
{
|
||||
_facadeIndex = facadeIndex ?? throw new ArgumentNullException(nameof(facadeIndex));
|
||||
_itemManager = itemManager ?? throw new ArgumentNullException(nameof(itemManager));
|
||||
_createBlueprint = createBlueprint ?? throw new ArgumentNullException(nameof(createBlueprint));
|
||||
_createLoadoutItem = createLoadoutItem ?? throw new ArgumentNullException(nameof(createLoadoutItem));
|
||||
_logWarning = logWarning ?? (_ => { });
|
||||
}
|
||||
|
||||
public bool TryApplyInPlace(
|
||||
string lastRunId,
|
||||
int lastZoneIndex,
|
||||
string runId,
|
||||
int zoneIndex,
|
||||
IReadOnlyList<AetheriaRuntimeEntitySnapshot> entitySnapshots,
|
||||
string currentEntityKey,
|
||||
Entity currentEntity,
|
||||
out Entity reboundCurrentEntity)
|
||||
{
|
||||
reboundCurrentEntity = null;
|
||||
if (!string.Equals(lastRunId, runId, StringComparison.Ordinal) ||
|
||||
lastZoneIndex != zoneIndex ||
|
||||
_facadeIndex.Count != entitySnapshots.Count)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var snapshot in entitySnapshots)
|
||||
{
|
||||
if (!_facadeIndex.ContainsRecordKey(snapshot.RecordKey))
|
||||
return false;
|
||||
}
|
||||
|
||||
ApplyInPlace(entitySnapshots);
|
||||
if (_facadeIndex.TryResolveEntityByRecordKey(currentEntityKey, out var resolvedCurrentEntity) &&
|
||||
currentEntity != resolvedCurrentEntity)
|
||||
{
|
||||
reboundCurrentEntity = resolvedCurrentEntity;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Replace(
|
||||
IReadOnlyList<AetheriaRuntimeEntitySnapshot> entitySnapshots,
|
||||
string currentEntityKey,
|
||||
Zone zone)
|
||||
{
|
||||
var restoredEntities = new Dictionary<string, Entity>();
|
||||
foreach (var entitySnapshot in entitySnapshots)
|
||||
{
|
||||
var blueprint = _createBlueprint(
|
||||
entitySnapshot,
|
||||
string.Equals(entitySnapshot.RecordKey, currentEntityKey, StringComparison.Ordinal));
|
||||
if (blueprint == null)
|
||||
{
|
||||
_logWarning($"Typed entity snapshot {entitySnapshot.RecordKey} could not be lowered into a runtime entity.");
|
||||
continue;
|
||||
}
|
||||
|
||||
var entity = EntityConstructionBlueprintProjector.ProjectObservedFromBlueprint(_itemManager, zone, blueprint);
|
||||
if (entity == null)
|
||||
continue;
|
||||
|
||||
ApplyPoseAndSimpleRuntimeState(entity, entitySnapshot);
|
||||
entity.RestoreActiveState(entitySnapshot.IsActive);
|
||||
restoredEntities[entitySnapshot.RecordKey] = entity;
|
||||
}
|
||||
|
||||
foreach (var entitySnapshot in entitySnapshots)
|
||||
{
|
||||
if (!restoredEntities.TryGetValue(entitySnapshot.RecordKey, out var entity))
|
||||
continue;
|
||||
|
||||
entity.HeatsinksEnabled = entitySnapshot.HeatsinksEnabled;
|
||||
entity.RestoreStatGrids(entitySnapshot.StatGrids);
|
||||
entity.RestoreThermalExposure((float)entitySnapshot.Heatstroke, (float)entitySnapshot.Hypothermia);
|
||||
RestoreActiveConsumables(entity, entitySnapshot);
|
||||
RestoreRuntimeBehaviorState(entity, entitySnapshot, restoredEntities);
|
||||
}
|
||||
|
||||
_facadeIndex.Replace(restoredEntities);
|
||||
}
|
||||
|
||||
private void ApplyInPlace(IReadOnlyList<AetheriaRuntimeEntitySnapshot> entitySnapshots)
|
||||
{
|
||||
foreach (var entitySnapshot in entitySnapshots)
|
||||
{
|
||||
if (!_facadeIndex.TryResolveEntityByRecordKey(entitySnapshot.RecordKey, out var entity))
|
||||
continue;
|
||||
|
||||
ApplyPoseAndSimpleRuntimeState(entity, entitySnapshot);
|
||||
entity.HeatsinksEnabled = entitySnapshot.HeatsinksEnabled;
|
||||
if (entity.Settings != null)
|
||||
entity.Settings.ShutdownPerformance = (float)entitySnapshot.ShutdownPerformance;
|
||||
entity.RestoreThermalExposure((float)entitySnapshot.Heatstroke, (float)entitySnapshot.Hypothermia);
|
||||
RestoreRuntimeBehaviorState(entity, entitySnapshot, _facadeIndex.EntitiesByRecordKey);
|
||||
}
|
||||
|
||||
_facadeIndex.RefreshDaemonIndex();
|
||||
}
|
||||
|
||||
private static void ApplyPoseAndSimpleRuntimeState(Entity entity, AetheriaRuntimeEntitySnapshot entitySnapshot)
|
||||
{
|
||||
entity.DaemonEntityIndex =
|
||||
AetheriaUnityDaemonEntitySnapshotProjector.EntityIndexFromRecordKey(entitySnapshot.RecordKey);
|
||||
entity.Name = entitySnapshot.Name ?? "";
|
||||
entity.CultPosition = new CultMath.float3((float)entitySnapshot.PositionX, (float)entitySnapshot.PositionY, (float)entitySnapshot.PositionZ);
|
||||
entity.CultDirection = new CultMath.float2((float)entitySnapshot.DirectionX, (float)entitySnapshot.DirectionY);
|
||||
entity.CultVelocity = new CultMath.float2((float)entitySnapshot.VelocityX, (float)entitySnapshot.VelocityY);
|
||||
entity.OverrideShutdown = entitySnapshot.OverrideShutdown;
|
||||
entity.TractorPower = (float)entitySnapshot.TractorPower;
|
||||
}
|
||||
|
||||
private void RestoreActiveConsumables(Entity entity, AetheriaRuntimeEntitySnapshot snapshot)
|
||||
{
|
||||
foreach (var activeConsumable in snapshot.ActiveConsumables)
|
||||
{
|
||||
var item = _createLoadoutItem(new AetheriaRuntimeLoadoutItemSnapshot(
|
||||
activeConsumable.ItemKey,
|
||||
activeConsumable.Quality,
|
||||
1,
|
||||
1,
|
||||
true,
|
||||
false)) as ConsumableItem;
|
||||
if (item == null)
|
||||
{
|
||||
_logWarning($"Typed active consumable {activeConsumable.ItemKey} could not be lowered for restored entity {snapshot.RecordKey}.");
|
||||
continue;
|
||||
}
|
||||
|
||||
entity.RestoreActiveConsumable(
|
||||
item,
|
||||
(float)activeConsumable.RemainingDuration,
|
||||
(float)activeConsumable.Duration);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RestoreRuntimeBehaviorState(
|
||||
Entity entity,
|
||||
AetheriaRuntimeEntitySnapshot snapshot,
|
||||
IReadOnlyDictionary<string, Entity> restoredEntities)
|
||||
{
|
||||
foreach (var weaponState in snapshot.WeaponStates)
|
||||
{
|
||||
if (!(ResolveRuntimeBehavior(entity, weaponState.OwnerKind, weaponState.OwnerIndex, weaponState.BehaviorIndex) is Weapon weapon))
|
||||
continue;
|
||||
|
||||
if (weapon is LockWeapon lockWeapon)
|
||||
{
|
||||
restoredEntities.TryGetValue(weaponState.LockTargetEntityKey, out var lockTarget);
|
||||
lockWeapon.RestoreRuntimeState(
|
||||
weaponState.Firing,
|
||||
weaponState.Ammo,
|
||||
weaponState.BurstRemaining,
|
||||
(float)weaponState.BurstTimer,
|
||||
(float)weaponState.BurstInterval,
|
||||
(float)weaponState.CooldownProgress,
|
||||
weaponState.CoolingDown,
|
||||
(float)weaponState.LockProgress,
|
||||
lockTarget);
|
||||
}
|
||||
else if (weapon is ChargedWeapon chargedWeapon)
|
||||
{
|
||||
chargedWeapon.RestoreRuntimeState(
|
||||
weaponState.Firing,
|
||||
weaponState.Ammo,
|
||||
weaponState.BurstRemaining,
|
||||
(float)weaponState.BurstTimer,
|
||||
(float)weaponState.BurstInterval,
|
||||
(float)weaponState.CooldownProgress,
|
||||
weaponState.CoolingDown,
|
||||
weaponState.Charging,
|
||||
weaponState.Charged,
|
||||
(float)weaponState.Charge);
|
||||
}
|
||||
else if (weapon is ConstantWeapon constantWeapon)
|
||||
{
|
||||
constantWeapon.RestoreRuntimeState(
|
||||
weaponState.Firing,
|
||||
weaponState.Ammo,
|
||||
(float)weaponState.AmmoIntervalProgress,
|
||||
(float)weaponState.ReloadProgress,
|
||||
weaponState.Reloading);
|
||||
}
|
||||
else if (weapon is InstantWeapon instantWeapon)
|
||||
{
|
||||
instantWeapon.RestoreRuntimeState(
|
||||
weaponState.Firing,
|
||||
weaponState.Ammo,
|
||||
weaponState.BurstRemaining,
|
||||
(float)weaponState.BurstTimer,
|
||||
(float)weaponState.BurstInterval,
|
||||
(float)weaponState.CooldownProgress,
|
||||
weaponState.CoolingDown);
|
||||
}
|
||||
else
|
||||
{
|
||||
weapon.RestoreRuntimeState(weaponState.Firing);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var behaviorState in snapshot.BehaviorStates)
|
||||
{
|
||||
var behavior = ResolveRuntimeBehavior(entity, behaviorState.OwnerKind, behaviorState.OwnerIndex, behaviorState.BehaviorIndex);
|
||||
switch (behavior)
|
||||
{
|
||||
case Sensor sensor:
|
||||
sensor.RestoreRuntimeState(
|
||||
behaviorState.Pinging,
|
||||
(float)behaviorState.PingCooldown,
|
||||
(float)behaviorState.PingLerp,
|
||||
(float)behaviorState.PingRadius);
|
||||
break;
|
||||
case Radiator radiator:
|
||||
radiator.RestoreRuntimeState(
|
||||
(float)behaviorState.RadiatorTemperature,
|
||||
(float)behaviorState.Emissivity,
|
||||
(float)behaviorState.PumpedHeat,
|
||||
(float)behaviorState.WasteHeat,
|
||||
(float)behaviorState.EnergyUsage);
|
||||
break;
|
||||
case Reactor reactor:
|
||||
reactor.RestoreRuntimeState(
|
||||
(float)behaviorState.ReactorDraw,
|
||||
(float)behaviorState.ReactorLoadRatio);
|
||||
break;
|
||||
case Capacitor capacitor:
|
||||
capacitor.RestoreRuntimeState(
|
||||
(float)behaviorState.CapacitorCharge,
|
||||
(float)behaviorState.CapacitorCapacity,
|
||||
(float)behaviorState.CapacitorEfficiency);
|
||||
break;
|
||||
case AetherDrive drive:
|
||||
drive.RestoreRuntimeState(
|
||||
new CultMath.float3((float)behaviorState.AetherDriveAxisX, (float)behaviorState.AetherDriveAxisY, (float)behaviorState.AetherDriveAxisZ),
|
||||
new CultMath.float3((float)behaviorState.AetherDriveThrustX, (float)behaviorState.AetherDriveThrustY, (float)behaviorState.AetherDriveThrustZ),
|
||||
new CultMath.float3((float)behaviorState.AetherDriveRpmX, (float)behaviorState.AetherDriveRpmY, (float)behaviorState.AetherDriveRpmZ),
|
||||
(float)behaviorState.AetherDriveMaximumRpm,
|
||||
new CultMath.float2((float)behaviorState.AetherDriveThrustDirectionX, (float)behaviorState.AetherDriveThrustDirectionY));
|
||||
break;
|
||||
case ResourceScanner resourceScanner:
|
||||
resourceScanner.RestoreRuntimeState(
|
||||
behaviorState.ResourceScannerTargetBodyKey,
|
||||
behaviorState.ResourceScannerAsteroidIndex,
|
||||
(float)behaviorState.ResourceScannerScanTime,
|
||||
(float)behaviorState.ResourceScannerRange,
|
||||
(float)behaviorState.ResourceScannerMinimumDensity,
|
||||
(float)behaviorState.ResourceScannerScanDuration);
|
||||
break;
|
||||
case MiningTool miningTool:
|
||||
miningTool.RestoreRuntimeState(
|
||||
behaviorState.MiningToolAsteroidBeltKey,
|
||||
behaviorState.MiningToolAsteroidIndex,
|
||||
(float)behaviorState.MiningToolRange);
|
||||
break;
|
||||
case Thruster thruster:
|
||||
thruster.RestoreRuntimeState(
|
||||
(float)behaviorState.ThrusterAxis,
|
||||
(float)behaviorState.ThrusterThrust);
|
||||
break;
|
||||
case Shield shield:
|
||||
shield.RestoreRuntimeState(
|
||||
(float)behaviorState.ShieldEfficiency,
|
||||
(float)behaviorState.ShieldEnergyUsage);
|
||||
break;
|
||||
case VelocityLimit velocityLimit:
|
||||
velocityLimit.RestoreRuntimeState((float)behaviorState.VelocityLimit);
|
||||
break;
|
||||
case Thermotoggle thermotoggle:
|
||||
thermotoggle.TargetTemperature = (float)behaviorState.ThermotoggleTargetTemperature;
|
||||
break;
|
||||
case Switch switchBehavior:
|
||||
switchBehavior.Activated = behaviorState.SwitchActivated;
|
||||
break;
|
||||
case Trigger trigger:
|
||||
trigger.RestoreRuntimeState(behaviorState.TriggerPulled);
|
||||
break;
|
||||
case StatModifier statModifier:
|
||||
statModifier.RestoreRuntimeState(
|
||||
behaviorState.StatModifierApplied,
|
||||
behaviorState.StatModifierExecuted);
|
||||
break;
|
||||
case TurretController turretController:
|
||||
turretController.RestoreRuntimeState(
|
||||
(float)behaviorState.TurretControllerShotSpeed,
|
||||
behaviorState.TurretControllerPredictShots);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Behavior ResolveRuntimeBehavior(Entity entity, string ownerKind, int ownerIndex, int behaviorIndex)
|
||||
{
|
||||
var behaviors = ResolveRuntimeBehaviorList(entity, ownerKind, ownerIndex);
|
||||
return behaviors != null && behaviorIndex >= 0 && behaviorIndex < behaviors.Count
|
||||
? behaviors[behaviorIndex]
|
||||
: null;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<Behavior> ResolveRuntimeBehaviorList(Entity entity, string ownerKind, int ownerIndex)
|
||||
{
|
||||
if (entity == null || ownerIndex < 0)
|
||||
return null;
|
||||
|
||||
switch (ownerKind)
|
||||
{
|
||||
case "equipment":
|
||||
return ownerIndex < entity.Equipment.Count ? entity.Equipment[ownerIndex].Behaviors : null;
|
||||
case "active_consumable":
|
||||
return ownerIndex < entity.ActiveConsumables.Count ? entity.ActiveConsumables[ownerIndex].Behaviors : null;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0a109bddc65c3d64bb233e11260276d5
|
||||
173
Assets/Scripts/Gameplay/AetheriaUnityObservedFrameApplier.cs
Normal file
173
Assets/Scripts/Gameplay/AetheriaUnityObservedFrameApplier.cs
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
|
||||
public sealed class AetheriaUnityObservedFrameApplier
|
||||
{
|
||||
private readonly Func<AetheriaDaemonObserver> _resolveObserver;
|
||||
private readonly Func<int, GalaxyZone> _resolveObservedZone;
|
||||
private readonly Func<Zone> _getZone;
|
||||
private readonly Action<Zone> _setZone;
|
||||
private readonly AetheriaUnityObservedFacadeIndex _facadeIndex;
|
||||
private readonly AetheriaUnityObservedFacadeProjector _facadeProjector;
|
||||
private readonly AetheriaUnityObservedZoneContextProjector _zoneContextProjector;
|
||||
private readonly Func<ZoneRenderer> _resolveZoneRenderer;
|
||||
private readonly Func<Entity> _getCurrentEntity;
|
||||
private readonly Action<Entity> _restoreCurrentEntityBinding;
|
||||
private readonly Action<string> _logWarning;
|
||||
|
||||
private long _lastAppliedZoneRenderFrameId = -1;
|
||||
private string _lastAppliedZoneRenderRunId = "";
|
||||
private int _lastAppliedZoneRenderZoneIndex = -1;
|
||||
private AetheriaRuntimeZoneRenderDocument _lastZoneRender;
|
||||
|
||||
public AetheriaUnityObservedFrameApplier(
|
||||
Func<AetheriaDaemonObserver> resolveObserver,
|
||||
Func<int, GalaxyZone> resolveObservedZone,
|
||||
Func<Zone> getZone,
|
||||
Action<Zone> setZone,
|
||||
AetheriaUnityObservedFacadeIndex facadeIndex,
|
||||
AetheriaUnityObservedFacadeProjector facadeProjector,
|
||||
AetheriaUnityObservedZoneContextProjector zoneContextProjector,
|
||||
Func<ZoneRenderer> resolveZoneRenderer,
|
||||
Func<Entity> getCurrentEntity,
|
||||
Action<Entity> restoreCurrentEntityBinding,
|
||||
Action<string> logWarning)
|
||||
{
|
||||
_resolveObserver = resolveObserver ?? (() => null);
|
||||
_resolveObservedZone = resolveObservedZone ?? (_ => null);
|
||||
_getZone = getZone ?? (() => null);
|
||||
_setZone = setZone ?? (_ => { });
|
||||
_facadeIndex = facadeIndex ?? throw new ArgumentNullException(nameof(facadeIndex));
|
||||
_facadeProjector = facadeProjector ?? throw new ArgumentNullException(nameof(facadeProjector));
|
||||
_zoneContextProjector = zoneContextProjector ?? throw new ArgumentNullException(nameof(zoneContextProjector));
|
||||
_resolveZoneRenderer = resolveZoneRenderer ?? (() => null);
|
||||
_getCurrentEntity = getCurrentEntity ?? (() => null);
|
||||
_restoreCurrentEntityBinding = restoreCurrentEntityBinding ?? (_ => { });
|
||||
_logWarning = logWarning ?? (_ => { });
|
||||
}
|
||||
|
||||
public bool ApplyLatestZoneRender()
|
||||
{
|
||||
var observer = _resolveObserver();
|
||||
if (observer == null || !observer.HasAuthoritativeState)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var render = ReadLatestZoneRender(observer);
|
||||
if (render == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return TryRestoreEntityGraphFromZoneRender(render);
|
||||
}
|
||||
|
||||
private AetheriaRuntimeZoneRenderDocument ReadLatestZoneRender(AetheriaDaemonObserver observer)
|
||||
{
|
||||
try
|
||||
{
|
||||
return observer.Client
|
||||
.ZoneRenderAsync()
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logWarning($"Failed to read Aetheria zone-render feed from local Verse state: {ex.Message}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryRestoreEntityGraphFromZoneRender(AetheriaRuntimeZoneRenderDocument render)
|
||||
{
|
||||
if (render == null || render.ZoneIndex < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(render.RunId))
|
||||
{
|
||||
_logWarning("Aetheria zone-render feed does not identify a run id.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var runId = render.RunId;
|
||||
var currentEntityKey = string.IsNullOrWhiteSpace(render.CurrentEntityKey) ? "" : render.CurrentEntityKey;
|
||||
if (string.IsNullOrWhiteSpace(currentEntityKey))
|
||||
{
|
||||
_logWarning($"Aetheria zone-render feed for run {runId} does not identify a current entity.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var entitySnapshots = AetheriaUnityDaemonEntitySnapshotProjector.CreateSnapshots(runId, render.ZoneIndex, render.EntityFacades)
|
||||
.OrderBy(entity => AetheriaUnityDaemonEntitySnapshotProjector.EntityIndexFromRecordKey(entity.RecordKey))
|
||||
.ToArray();
|
||||
|
||||
if (entitySnapshots.Length == 0)
|
||||
{
|
||||
_logWarning($"Aetheria zone-render feed has no entity facades for zone {render.ZoneIndex}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var targetZone = _resolveObservedZone(render.ZoneIndex);
|
||||
if (targetZone == null)
|
||||
{
|
||||
_logWarning($"Aetheria zone-render feed references missing zone index {render.ZoneIndex}.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (render.FrameId == _lastAppliedZoneRenderFrameId &&
|
||||
string.Equals(render.RunId, _lastAppliedZoneRenderRunId, StringComparison.Ordinal) &&
|
||||
render.ZoneIndex == _lastAppliedZoneRenderZoneIndex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var zoneRenderer = _resolveZoneRenderer();
|
||||
if (_facadeProjector.TryApplyInPlace(
|
||||
_lastAppliedZoneRenderRunId,
|
||||
_lastAppliedZoneRenderZoneIndex,
|
||||
runId,
|
||||
render.ZoneIndex,
|
||||
entitySnapshots,
|
||||
currentEntityKey,
|
||||
_getCurrentEntity(),
|
||||
out var reboundCurrentEntity))
|
||||
{
|
||||
if (reboundCurrentEntity != null)
|
||||
_restoreCurrentEntityBinding(reboundCurrentEntity);
|
||||
zoneRenderer?.ApplyZoneRender(render);
|
||||
zoneRenderer?.RestoreDroppedPickupsFromZoneRender(render);
|
||||
_lastAppliedZoneRenderFrameId = render.FrameId;
|
||||
_lastZoneRender = render;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (_getZone()?.GalaxyZone != targetZone)
|
||||
{
|
||||
var resolvedZone = _zoneContextProjector.ResolveContext(targetZone, render);
|
||||
if (resolvedZone == null)
|
||||
return false;
|
||||
|
||||
_setZone(resolvedZone);
|
||||
}
|
||||
|
||||
_facadeProjector.Replace(entitySnapshots, currentEntityKey, _getZone());
|
||||
zoneRenderer?.LoadDaemonZoneView(_facadeIndex.EntitiesByDaemonIndex, render);
|
||||
if (_facadeIndex.TryResolveEntityByRecordKey(currentEntityKey, out var currentEntity))
|
||||
_restoreCurrentEntityBinding(currentEntity);
|
||||
zoneRenderer?.RestoreDroppedPickupsFromZoneRender(render);
|
||||
_lastAppliedZoneRenderFrameId = render.FrameId;
|
||||
_lastAppliedZoneRenderRunId = runId;
|
||||
_lastAppliedZoneRenderZoneIndex = render.ZoneIndex;
|
||||
_lastZoneRender = render;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f83634c47d54bc4aa34f8c976a660ce
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
|
||||
public static class AetheriaUnityObservedRunProjection
|
||||
{
|
||||
public static Galaxy Galaxy { get; private set; }
|
||||
|
||||
public static void Project(
|
||||
AetheriaRuntimeSectorMapDocument sectorMap,
|
||||
SectorBackgroundSettings backgroundSettings,
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
Action<string> log)
|
||||
{
|
||||
Galaxy = global::Galaxy.ProjectObservedSectorMap(sectorMap, backgroundSettings, runtimeCatalog, log);
|
||||
}
|
||||
|
||||
public static void Project(
|
||||
AetheriaRuntimeDaemonFrameDocument frame,
|
||||
SectorBackgroundSettings backgroundSettings,
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
Action<string> log)
|
||||
{
|
||||
if (frame == null || frame.Run == null)
|
||||
throw new ArgumentNullException(nameof(frame));
|
||||
|
||||
Galaxy = global::Galaxy.ProjectObservedDaemonRun(frame.Run, backgroundSettings, runtimeCatalog, log);
|
||||
}
|
||||
|
||||
public static GalaxyZone FindZone(int daemonZoneIndex)
|
||||
{
|
||||
return daemonZoneIndex < 0
|
||||
? null
|
||||
: Galaxy?.Zones?.FirstOrDefault(zone => zone != null && zone.ZoneIndex == daemonZoneIndex);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeZoneSnapshotCommit FindZoneSnapshot(AetheriaRuntimeRunCheckpointCommit run)
|
||||
{
|
||||
if (run == null)
|
||||
return null;
|
||||
|
||||
return (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
|
||||
.FirstOrDefault(zone => zone != null && zone.ZoneIndex == run.CurrentZoneIndex)
|
||||
?? (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>())
|
||||
.FirstOrDefault(zone => zone != null);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5262d4719f1ec6647a465a9450b2787c
|
||||
103
Assets/Scripts/Gameplay/AetheriaUnityObservedTargetQuery.cs
Normal file
103
Assets/Scripts/Gameplay/AetheriaUnityObservedTargetQuery.cs
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
/* 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 System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
|
||||
public sealed class AetheriaUnityObservedTargetQuery
|
||||
{
|
||||
private readonly Func<AetheriaClient> _resolveClient;
|
||||
private readonly AetheriaUnityObservedFacadeIndex _facadeIndex;
|
||||
|
||||
public AetheriaUnityObservedTargetQuery(
|
||||
Func<AetheriaClient> resolveClient,
|
||||
AetheriaUnityObservedFacadeIndex facadeIndex)
|
||||
{
|
||||
_resolveClient = resolveClient ?? (() => null);
|
||||
_facadeIndex = facadeIndex ?? throw new ArgumentNullException(nameof(facadeIndex));
|
||||
}
|
||||
|
||||
public Entity GetObservedTarget(Entity observer)
|
||||
{
|
||||
if (TryQueryEntityTarget(observer, out var targetEntityIndex) &&
|
||||
_facadeIndex.TryResolveEntityByDaemonIndex(targetEntityIndex, out var targetEntity))
|
||||
{
|
||||
return targetEntity;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public float GetObservedInfoGathered(Entity observer, Entity target)
|
||||
{
|
||||
return TryQueryEntityContact(observer, target, out var contact)
|
||||
? (float)contact.InfoGathered
|
||||
: 0f;
|
||||
}
|
||||
|
||||
public bool IsObservedHostileContact(Entity observer, Entity target)
|
||||
{
|
||||
return TryQueryEntityContact(observer, target, out var contact) && contact.Hostile;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeZoneContactRow[] GetObservedVisibleContacts(
|
||||
Entity observer,
|
||||
double minimumInfoGathered,
|
||||
bool visibleOnly)
|
||||
{
|
||||
var contacts = ReadZoneContacts();
|
||||
if (observer == null || contacts == null)
|
||||
return Array.Empty<AetheriaRuntimeZoneContactRow>();
|
||||
|
||||
return (contacts.Contacts ?? Array.Empty<AetheriaRuntimeZoneContactRow>())
|
||||
.Where(contact =>
|
||||
contact.ObserverEntityIndex == observer.DaemonEntityIndex &&
|
||||
contact.InfoGathered > minimumInfoGathered &&
|
||||
(!visibleOnly || contact.Visible))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private bool TryQueryEntityContact(
|
||||
Entity observer,
|
||||
Entity target,
|
||||
out AetheriaRuntimeZoneContactRow contact)
|
||||
{
|
||||
contact = default;
|
||||
if (observer == null || target == null)
|
||||
return false;
|
||||
|
||||
contact = (ReadZoneContacts()?.Contacts ?? Array.Empty<AetheriaRuntimeZoneContactRow>())
|
||||
.FirstOrDefault(row =>
|
||||
row.ObserverEntityIndex == observer.DaemonEntityIndex &&
|
||||
row.TargetEntityIndex == target.DaemonEntityIndex);
|
||||
return contact != null;
|
||||
}
|
||||
|
||||
private bool TryQueryEntityTarget(
|
||||
Entity observer,
|
||||
out int targetEntityIndex)
|
||||
{
|
||||
targetEntityIndex = -1;
|
||||
if (observer == null)
|
||||
return false;
|
||||
|
||||
targetEntityIndex = (ReadZoneContacts()?.Targets ?? Array.Empty<AetheriaRuntimeZoneTargetRow>())
|
||||
.FirstOrDefault(row => row.EntityIndex == observer.DaemonEntityIndex)
|
||||
?.TargetEntityIndex ?? -1;
|
||||
return targetEntityIndex >= 0;
|
||||
}
|
||||
|
||||
private AetheriaRuntimeZoneContactsDocument ReadZoneContacts()
|
||||
{
|
||||
try
|
||||
{
|
||||
return _resolveClient()?.ZoneContactsAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 735b01f66e370d741bd3a5130eb166c7
|
||||
|
|
@ -0,0 +1,192 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
using float2 = Unity.Mathematics.float2;
|
||||
using float4 = Unity.Mathematics.float4;
|
||||
|
||||
public sealed class AetheriaUnityObservedZoneContextProjector
|
||||
{
|
||||
private readonly Dictionary<int, Zone> _observedZoneContextsByDaemonIndex = new Dictionary<int, Zone>();
|
||||
private readonly ItemManager _itemManager;
|
||||
private readonly PlanetSettings _planetSettings;
|
||||
private readonly Func<Galaxy> _resolveObservedGalaxy;
|
||||
private readonly Action<string> _logWarning;
|
||||
private readonly Action<MusicType> _playMusic;
|
||||
private Galaxy _observedGalaxy;
|
||||
|
||||
public AetheriaUnityObservedZoneContextProjector(
|
||||
ItemManager itemManager,
|
||||
PlanetSettings planetSettings,
|
||||
Func<Galaxy> resolveObservedGalaxy,
|
||||
Action<string> logWarning,
|
||||
Action<MusicType> playMusic)
|
||||
{
|
||||
_itemManager = itemManager ?? throw new ArgumentNullException(nameof(itemManager));
|
||||
_planetSettings = planetSettings ?? throw new ArgumentNullException(nameof(planetSettings));
|
||||
_resolveObservedGalaxy = resolveObservedGalaxy ?? (() => null);
|
||||
_logWarning = logWarning ?? (_ => { });
|
||||
_playMusic = playMusic ?? (_ => { });
|
||||
}
|
||||
|
||||
public Zone ResolveContext(
|
||||
GalaxyZone galaxyZone,
|
||||
AetheriaRuntimeZoneRenderDocument render)
|
||||
{
|
||||
if (galaxyZone == null)
|
||||
throw new ArgumentNullException(nameof(galaxyZone));
|
||||
|
||||
if (render == null)
|
||||
{
|
||||
_logWarning($"Daemon-authoritative zone population suppressed for {galaxyZone.Name}; no zone-render document was provided.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var zoneIndex = render.ZoneIndex;
|
||||
if (!_observedZoneContextsByDaemonIndex.TryGetValue(zoneIndex, out var observedZoneContext))
|
||||
{
|
||||
_observedGalaxy = _resolveObservedGalaxy();
|
||||
if (_observedGalaxy == null)
|
||||
{
|
||||
_logWarning($"Daemon-authoritative zone population suppressed for {galaxyZone.Name}; no observed sector projection is available.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var constructionBlueprint = CreateZoneConstructionBlueprint(render);
|
||||
observedZoneContext = new Zone(_itemManager, _planetSettings, constructionBlueprint, galaxyZone, _observedGalaxy);
|
||||
_observedZoneContextsByDaemonIndex[zoneIndex] = observedZoneContext;
|
||||
}
|
||||
|
||||
_playMusic(MusicType.Overworld);
|
||||
observedZoneContext.Log = s => Debug.Log($"Zone: {s}");
|
||||
return observedZoneContext;
|
||||
}
|
||||
|
||||
private static ZoneConstructionBlueprint CreateZoneConstructionBlueprint(AetheriaRuntimeZoneRenderDocument render)
|
||||
{
|
||||
var blueprint = new ZoneConstructionBlueprint
|
||||
{
|
||||
Radius = 2000,
|
||||
Mass = 10000,
|
||||
Time = (float)render.SimulationTimeSeconds
|
||||
};
|
||||
|
||||
foreach (var orbit in render.Orbits ?? Array.Empty<AetheriaRuntimeOrbitSnapshotCommit>())
|
||||
{
|
||||
if (orbit == null)
|
||||
continue;
|
||||
|
||||
blueprint.Orbits.Add(new OrbitConstructionData
|
||||
{
|
||||
OrbitKey = orbit.OrbitKey ?? "",
|
||||
ParentOrbitKey = orbit.ParentOrbitKey ?? "",
|
||||
Distance = (float)orbit.Distance,
|
||||
Phase = (float)orbit.Phase,
|
||||
FixedPosition = new float2((float)orbit.FixedPositionX, (float)orbit.FixedPositionY)
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var body in render.Bodies ?? Array.Empty<AetheriaRuntimeBodySnapshotCommit>())
|
||||
{
|
||||
if (body == null)
|
||||
continue;
|
||||
|
||||
blueprint.Bodies.Add(CreateBodyConstructionData(body));
|
||||
}
|
||||
|
||||
return blueprint;
|
||||
}
|
||||
|
||||
private static BodyConstructionData CreateBodyConstructionData(AetheriaRuntimeBodySnapshotCommit body)
|
||||
{
|
||||
BodyConstructionData data = (body.Kind ?? "").ToLowerInvariant() switch
|
||||
{
|
||||
"asteroid_belt" => new AsteroidBeltConstructionData
|
||||
{
|
||||
Asteroids = (body.Asteroids ?? Array.Empty<AetheriaRuntimeAsteroidCommit>())
|
||||
.Where(asteroid => asteroid != null)
|
||||
.Select(asteroid => new Asteroid
|
||||
{
|
||||
Distance = (float)asteroid.Distance,
|
||||
Phase = (float)asteroid.Phase,
|
||||
Size = (float)asteroid.Size,
|
||||
RotationSpeed = (float)asteroid.RotationSpeed
|
||||
})
|
||||
.ToArray()
|
||||
},
|
||||
"sun" => CreateSunConstructionData(body),
|
||||
"gas_giant" => CreateGasGiantConstructionData(body),
|
||||
_ => new PlanetConstructionData()
|
||||
};
|
||||
|
||||
PopulateBodyConstructionData(data, body);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static GasGiantConstructionData CreateGasGiantConstructionData(AetheriaRuntimeBodySnapshotCommit body)
|
||||
{
|
||||
var visual = body.GasGiantVisual ?? new AetheriaRuntimeGasGiantVisualCommit();
|
||||
return new GasGiantConstructionData
|
||||
{
|
||||
FirstOffsetDomainRotationSpeed = (float)visual.FirstOffsetDomainRotationSpeed,
|
||||
FirstOffsetRotationSpeed = (float)visual.FirstOffsetRotationSpeed,
|
||||
SecondOffsetDomainRotationSpeed = (float)visual.SecondOffsetDomainRotationSpeed,
|
||||
SecondOffsetRotationSpeed = (float)visual.SecondOffsetRotationSpeed,
|
||||
AlbedoRotationSpeed = (float)visual.AlbedoRotationSpeed,
|
||||
WaveRadiusMultiplier = (float)visual.WaveRadiusMultiplier,
|
||||
WaveDepthMultiplier = (float)visual.WaveDepthMultiplier,
|
||||
WaveDepthExponent = (float)visual.WaveDepthExponent,
|
||||
WaveSpeedMultiplier = (float)visual.WaveSpeedMultiplier,
|
||||
MaterialOverrides = (visual.MaterialOverrides ?? Array.Empty<string>()).ToList(),
|
||||
Colors = (visual.Colors ?? Array.Empty<AetheriaRuntimeColorCommit>())
|
||||
.Where(color => color != null)
|
||||
.Select(color => new float4((float)color.X, (float)color.Y, (float)color.Z, (float)color.W))
|
||||
.ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
private static SunConstructionData CreateSunConstructionData(AetheriaRuntimeBodySnapshotCommit body)
|
||||
{
|
||||
var gas = CreateGasGiantConstructionData(body);
|
||||
var visual = body.SunVisual ?? new AetheriaRuntimeSunVisualCommit();
|
||||
return new SunConstructionData
|
||||
{
|
||||
FirstOffsetDomainRotationSpeed = gas.FirstOffsetDomainRotationSpeed,
|
||||
FirstOffsetRotationSpeed = gas.FirstOffsetRotationSpeed,
|
||||
SecondOffsetDomainRotationSpeed = gas.SecondOffsetDomainRotationSpeed,
|
||||
SecondOffsetRotationSpeed = gas.SecondOffsetRotationSpeed,
|
||||
AlbedoRotationSpeed = gas.AlbedoRotationSpeed,
|
||||
WaveRadiusMultiplier = gas.WaveRadiusMultiplier,
|
||||
WaveDepthMultiplier = gas.WaveDepthMultiplier,
|
||||
WaveDepthExponent = gas.WaveDepthExponent,
|
||||
WaveSpeedMultiplier = gas.WaveSpeedMultiplier,
|
||||
MaterialOverrides = gas.MaterialOverrides,
|
||||
Colors = gas.Colors,
|
||||
LightColor = new CultMath.float3((float)visual.LightColorX, (float)visual.LightColorY, (float)visual.LightColorZ),
|
||||
FogTintColor = new CultMath.float3((float)visual.FogTintColorX, (float)visual.FogTintColorY, (float)visual.FogTintColorZ),
|
||||
LightRadiusMultiplier = (float)visual.LightRadiusMultiplier
|
||||
};
|
||||
}
|
||||
|
||||
private static void PopulateBodyConstructionData(
|
||||
BodyConstructionData data,
|
||||
AetheriaRuntimeBodySnapshotCommit body)
|
||||
{
|
||||
data.BodyKey = body.BodyKey ?? "";
|
||||
data.Name = body.Name ?? "";
|
||||
data.OrbitKey = body.OrbitKey ?? "";
|
||||
data.Mass = (float)body.Mass;
|
||||
data.BodyRadiusMultiplier = (float)body.BodyRadiusMultiplier;
|
||||
data.GravityRadiusMultiplier = (float)body.GravityRadiusMultiplier;
|
||||
data.GravityDepthMultiplier = (float)body.GravityDepthMultiplier;
|
||||
data.GravityDepthExponent = (float)body.GravityDepthExponent;
|
||||
data.Resources = (body.Resources ?? Array.Empty<AetheriaRuntimeBodyResourceCommit>())
|
||||
.Where(resource => resource != null && !string.IsNullOrWhiteSpace(resource.ItemKey))
|
||||
.ToDictionary(resource => resource.ItemKey, resource => (float)resource.Amount, StringComparer.Ordinal);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 585768cd246ecc249b1e49ee64a7def9
|
||||
120
Assets/Scripts/Gameplay/AetheriaUnityPilotCommandSender.cs
Normal file
120
Assets/Scripts/Gameplay/AetheriaUnityPilotCommandSender.cs
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/* 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;
|
||||
using UnityEngine;
|
||||
|
||||
public sealed class AetheriaUnityPilotCommandSender
|
||||
{
|
||||
private const float DaemonMoveCommandIntervalSeconds = 0.05f;
|
||||
private const float DaemonMoveCommandChangeThreshold = 0.001f;
|
||||
private const float DaemonLookCommandIntervalSeconds = 0.02f;
|
||||
private const float DaemonLookCommandChangeThreshold = 0.0001f;
|
||||
private const float DaemonTractorCommandIntervalSeconds = 0.05f;
|
||||
private const float DaemonTractorCommandChangeThreshold = 0.001f;
|
||||
|
||||
private readonly Func<AetheriaClient> _resolveClient;
|
||||
private readonly Func<float> _time;
|
||||
private Vector2 _lastSentDaemonMoveVector;
|
||||
private Vector3 _lastSentDaemonLookDirection;
|
||||
private float _lastSentDaemonTractorPower;
|
||||
private float _nextDaemonMoveCommandTime;
|
||||
private float _nextDaemonLookCommandTime;
|
||||
private float _nextDaemonTractorCommandTime;
|
||||
private bool _hasSentDaemonMoveVector;
|
||||
private bool _hasSentDaemonLookDirection;
|
||||
private bool _hasSentDaemonTractorPower;
|
||||
|
||||
public AetheriaUnityPilotCommandSender(
|
||||
Func<AetheriaClient> resolveClient,
|
||||
Func<float> time)
|
||||
{
|
||||
_resolveClient = resolveClient ?? throw new ArgumentNullException(nameof(resolveClient));
|
||||
_time = time ?? throw new ArgumentNullException(nameof(time));
|
||||
}
|
||||
|
||||
public void RequestMoveVector(Vector2 movement)
|
||||
{
|
||||
var changed = !_hasSentDaemonMoveVector ||
|
||||
(movement - _lastSentDaemonMoveVector).sqrMagnitude >
|
||||
DaemonMoveCommandChangeThreshold * DaemonMoveCommandChangeThreshold;
|
||||
if (!changed && _time() < _nextDaemonMoveCommandTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TrySubmit(
|
||||
operations => operations.SetMoveVector(movement.x, movement.y, movement.magnitude),
|
||||
"movement"))
|
||||
{
|
||||
_lastSentDaemonMoveVector = movement;
|
||||
_hasSentDaemonMoveVector = true;
|
||||
_nextDaemonMoveCommandTime = _time() + DaemonMoveCommandIntervalSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestLookDirection(Vector3 lookDirection)
|
||||
{
|
||||
var changed = !_hasSentDaemonLookDirection ||
|
||||
(lookDirection - _lastSentDaemonLookDirection).sqrMagnitude >
|
||||
DaemonLookCommandChangeThreshold * DaemonLookCommandChangeThreshold;
|
||||
if (!changed && _time() < _nextDaemonLookCommandTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TrySubmit(
|
||||
operations => operations.SetLookDirection(lookDirection.x, lookDirection.y, lookDirection.z),
|
||||
"look"))
|
||||
{
|
||||
_lastSentDaemonLookDirection = lookDirection;
|
||||
_hasSentDaemonLookDirection = true;
|
||||
_nextDaemonLookCommandTime = _time() + DaemonLookCommandIntervalSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestTractorPower(float power)
|
||||
{
|
||||
var changed = !_hasSentDaemonTractorPower ||
|
||||
Mathf.Abs(power - _lastSentDaemonTractorPower) >
|
||||
DaemonTractorCommandChangeThreshold;
|
||||
if (!changed && _time() < _nextDaemonTractorCommandTime)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (TrySubmit(
|
||||
operations => operations.SetTractorPower(power),
|
||||
"tractor-power"))
|
||||
{
|
||||
_lastSentDaemonTractorPower = power;
|
||||
_hasSentDaemonTractorPower = true;
|
||||
_nextDaemonTractorCommandTime = _time() + DaemonTractorCommandIntervalSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TrySubmit(
|
||||
Action<AetheriaControl> submit,
|
||||
string label)
|
||||
{
|
||||
var client = _resolveClient();
|
||||
if (client == null ||
|
||||
submit == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
submit(client.Control);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to send Aetheria daemon pilot {label} operation; operation not submitted: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c98d1a89797d6c4ba1034ac4d171e51
|
||||
75
Assets/Scripts/Gameplay/AetheriaUnityPilotFrameAdapter.cs
Normal file
75
Assets/Scripts/Gameplay/AetheriaUnityPilotFrameAdapter.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* 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 Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
using static Unity.Mathematics.math;
|
||||
|
||||
public sealed class AetheriaUnityPilotFrameAdapter
|
||||
{
|
||||
private float2 _entityYawPitch;
|
||||
private readonly Action<float3> _setViewDirection;
|
||||
|
||||
public AetheriaUnityPilotFrameAdapter(Action<float3> setViewDirection)
|
||||
{
|
||||
_setViewDirection = setViewDirection ?? (_ => { });
|
||||
}
|
||||
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public AetheriaInput Input { get; set; }
|
||||
public AetheriaUnityTargetPresentation TargetPresentation { get; set; }
|
||||
public AetheriaUnityPilotCommandSender PilotCommands { get; set; }
|
||||
public PostProcessVolume HeatstrokePost { get; set; }
|
||||
public PostProcessVolume SevereHeatstrokePost { get; set; }
|
||||
public float2 Sensitivity { get; set; }
|
||||
|
||||
public void Tick(Entity currentEntity, float deltaTime, float timeSeconds)
|
||||
{
|
||||
if (currentEntity == null ||
|
||||
Input == null ||
|
||||
PilotCommands == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var renderSettings = ZoneRenderer?.RenderSettings;
|
||||
TargetPresentation?.Tick(currentEntity, timeSeconds);
|
||||
|
||||
var look = Input.Player.Look.ReadValue<Vector2>();
|
||||
_entityYawPitch = new float2(
|
||||
_entityYawPitch.x + look.x * Sensitivity.x,
|
||||
Mathf.Clamp(_entityYawPitch.y + look.y * Sensitivity.y, -.45f * Mathf.PI, .45f * Mathf.PI));
|
||||
var viewDirection = (float3)(Quaternion.Euler(
|
||||
_entityYawPitch.y * Mathf.Rad2Deg,
|
||||
_entityYawPitch.x * Mathf.Rad2Deg,
|
||||
0) * Vector3.forward);
|
||||
_setViewDirection(viewDirection);
|
||||
PilotCommands.RequestLookDirection(viewDirection);
|
||||
|
||||
if (renderSettings != null)
|
||||
{
|
||||
if (HeatstrokePost != null)
|
||||
HeatstrokePost.weight = (float)renderSettings.NormalizeHeatstrokePost(currentEntity.Heatstroke);
|
||||
if (SevereHeatstrokePost != null)
|
||||
SevereHeatstrokePost.weight =
|
||||
(float)renderSettings.ResolveSevereHeatstrokePostWeight(currentEntity.Heatstroke, timeSeconds);
|
||||
}
|
||||
|
||||
if (currentEntity is Ship)
|
||||
{
|
||||
var movement = Input.Player.Move.ReadValue<Vector2>();
|
||||
PilotCommands.RequestMoveVector(movement);
|
||||
}
|
||||
|
||||
var tractorPowerInput = Input.Player.TractorBeam.ReadValue<float>();
|
||||
PilotCommands.RequestTractorPower(Saturate(
|
||||
currentEntity.TractorPower +
|
||||
Mathf.Sign(tractorPowerInput - currentEntity.TractorPower) * deltaTime * 2));
|
||||
}
|
||||
|
||||
private static float Saturate(float value) => Mathf.Clamp01(value);
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5dfa48356761f45408a1c1a7febd7438
|
||||
114
Assets/Scripts/Gameplay/AetheriaUnityPilotOperationAdapter.cs
Normal file
114
Assets/Scripts/Gameplay/AetheriaUnityPilotOperationAdapter.cs
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/* 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;
|
||||
using Unity.Mathematics;
|
||||
|
||||
public sealed class AetheriaUnityPilotOperationAdapter
|
||||
{
|
||||
private readonly Func<AetheriaUnityPilotCommandSender> _resolvePilotCommands;
|
||||
private readonly AetheriaUnityObservedFacadeIndex _observedFacadeIndex;
|
||||
private readonly Func<float3> _resolveViewDirection;
|
||||
private readonly Func<Entity> _resolveCurrentEntity;
|
||||
|
||||
public AetheriaUnityPilotOperationAdapter(
|
||||
Func<AetheriaUnityPilotCommandSender> resolvePilotCommands,
|
||||
AetheriaUnityObservedFacadeIndex observedFacadeIndex,
|
||||
Func<float3> resolveViewDirection,
|
||||
Func<Entity> resolveCurrentEntity)
|
||||
{
|
||||
_resolvePilotCommands = resolvePilotCommands ?? throw new ArgumentNullException(nameof(resolvePilotCommands));
|
||||
_observedFacadeIndex = observedFacadeIndex ?? throw new ArgumentNullException(nameof(observedFacadeIndex));
|
||||
_resolveViewDirection = resolveViewDirection ?? (() => default);
|
||||
_resolveCurrentEntity = resolveCurrentEntity ?? (() => null);
|
||||
}
|
||||
|
||||
public void RequestInteract()
|
||||
{
|
||||
Submit(operations => operations.Interact(), "interact");
|
||||
}
|
||||
|
||||
public void RequestTargetSelection(Entity target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
Submit(operations => operations.ClearTarget(), "target clear");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_observedFacadeIndex.TryResolveEntityRecordKey(target, out var targetEntityKey) ||
|
||||
string.IsNullOrWhiteSpace(targetEntityKey))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Submit(
|
||||
operations => operations.SetTarget(targetEntityKey),
|
||||
"target");
|
||||
}
|
||||
|
||||
public void RequestTargetNearest()
|
||||
{
|
||||
Submit(operations => operations.TargetNearest(), "target nearest");
|
||||
}
|
||||
|
||||
public void RequestTargetNext()
|
||||
{
|
||||
Submit(operations => operations.TargetNext(), "target next");
|
||||
}
|
||||
|
||||
public void RequestTargetPrevious()
|
||||
{
|
||||
Submit(operations => operations.TargetPrevious(), "target previous");
|
||||
}
|
||||
|
||||
public void RequestTargetReticle()
|
||||
{
|
||||
var lookDirection = _resolveViewDirection();
|
||||
Submit(
|
||||
operations => operations.TargetReticle(lookDirection.x, lookDirection.y, lookDirection.z),
|
||||
"reticle target");
|
||||
}
|
||||
|
||||
public void RequestOverrideShutdown(bool enabled)
|
||||
{
|
||||
Submit(operations => operations.SetOverrideShutdown(enabled), "override-shutdown");
|
||||
}
|
||||
|
||||
public void RequestSensorPing()
|
||||
{
|
||||
Submit(operations => operations.SensorPing(), "sensor-ping");
|
||||
}
|
||||
|
||||
public void RequestHeatsinksEnabled(bool enabled)
|
||||
{
|
||||
Submit(operations => operations.SetHeatsinksEnabled(enabled), "heatsinks");
|
||||
}
|
||||
|
||||
public void RequestShieldToggle()
|
||||
{
|
||||
Submit(operations => operations.ToggleShieldEnabled(), "shield enablement");
|
||||
}
|
||||
|
||||
public void RequestDock()
|
||||
{
|
||||
Submit(operations => operations.DockNearest(), "dock");
|
||||
}
|
||||
|
||||
public void RequestUndock()
|
||||
{
|
||||
if (_resolveCurrentEntity() == null)
|
||||
return;
|
||||
|
||||
Submit(operations => operations.Undock(), "undock");
|
||||
}
|
||||
|
||||
private void Submit(
|
||||
Action<AetheriaControl> submit,
|
||||
string label)
|
||||
{
|
||||
_resolvePilotCommands()?.TrySubmit(submit, label);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 65505a1513191d64fa99fd51d3508383
|
||||
71
Assets/Scripts/Gameplay/AetheriaUnityRenderSettingsBridge.cs
Normal file
71
Assets/Scripts/Gameplay/AetheriaUnityRenderSettingsBridge.cs
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* 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.Linq;
|
||||
|
||||
public static class AetheriaUnityRenderSettingsBridge
|
||||
{
|
||||
public static AetheriaRuntimeDaemonRenderSettings Build(
|
||||
GameSettings settings,
|
||||
float targetSpottedBlinkFrequency,
|
||||
float targetSpottedBlinkOffset)
|
||||
{
|
||||
var emissionCurve = settings.GameplaySettings.TemperatureEmissionCurve;
|
||||
var bodyIconSizeCurve = settings.IconSize;
|
||||
var bodyRadiusCurve = settings.PlanetSettings.BodyRadius;
|
||||
var lightRadiusCurve = settings.PlanetSettings.LightRadius;
|
||||
var gravityWaveFrequencyCurve = settings.PlanetSettings.WaveFrequency;
|
||||
return new AetheriaRuntimeDaemonRenderSettings(
|
||||
new AetheriaRuntimeExponentialCurve(
|
||||
emissionCurve.Exponent,
|
||||
emissionCurve.Multiplier,
|
||||
emissionCurve.Constant),
|
||||
new AetheriaRuntimeExponentialLerp(
|
||||
settings.GameplaySettings.LockIndicatorFrequency.Exponent,
|
||||
settings.GameplaySettings.LockIndicatorFrequency.Minimum,
|
||||
settings.GameplaySettings.LockIndicatorFrequency.Maximum),
|
||||
new AetheriaRuntimeExponentialLerp(
|
||||
settings.GameplaySettings.LockSpinSpeed.Exponent,
|
||||
settings.GameplaySettings.LockSpinSpeed.Minimum,
|
||||
settings.GameplaySettings.LockSpinSpeed.Maximum),
|
||||
settings.GameplaySettings.ConvergenceMinimumDistance,
|
||||
settings.GameplaySettings.HypothermiaTemperature,
|
||||
settings.GameplaySettings.HeatstrokeTemperature,
|
||||
settings.GameplaySettings.SevereHeatstrokeRiskThreshold,
|
||||
settings.GameplaySettings.TargetDetectionInfoThreshold,
|
||||
settings.GameplaySettings.LockIndicatorNoiseAmplitude,
|
||||
settings.HeatstrokePhasingFloor,
|
||||
settings.HeatstrokePhasingFrequency,
|
||||
targetSpottedBlinkFrequency,
|
||||
targetSpottedBlinkOffset,
|
||||
settings.MinimapZoomLevels?.Select(level => (double)level).ToArray(),
|
||||
settings.DefaultMinimapZoom,
|
||||
settings.WormholeDistanceRatio,
|
||||
settings.DefaultViewDistance,
|
||||
settings.MinimapIconSize,
|
||||
settings.MinimapAsteroidSize,
|
||||
new AetheriaRuntimeExponentialCurve(
|
||||
bodyIconSizeCurve.Exponent,
|
||||
bodyIconSizeCurve.Multiplier,
|
||||
bodyIconSizeCurve.Constant),
|
||||
settings.MinimapZoneGravityRange,
|
||||
settings.PlanetSettings.AsteroidVerticalOffset,
|
||||
settings.PlanetRotationSpeed,
|
||||
settings.PlanetSettings.ZoneDepthExponent,
|
||||
settings.PlanetSettings.ZoneDepth + settings.PlanetSettings.ZoneBoundaryFog,
|
||||
settings.AsteroidMeshCount,
|
||||
new AetheriaRuntimeExponentialCurve(
|
||||
bodyRadiusCurve.Exponent,
|
||||
bodyRadiusCurve.Multiplier,
|
||||
bodyRadiusCurve.Constant),
|
||||
new AetheriaRuntimeExponentialCurve(
|
||||
lightRadiusCurve.Exponent,
|
||||
lightRadiusCurve.Multiplier,
|
||||
lightRadiusCurve.Constant),
|
||||
new AetheriaRuntimeExponentialCurve(
|
||||
gravityWaveFrequencyCurve.Exponent,
|
||||
gravityWaveFrequencyCurve.Multiplier,
|
||||
gravityWaveFrequencyCurve.Constant));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0d5dc044370e0c340b28db46e4bfeca7
|
||||
144
Assets/Scripts/Gameplay/AetheriaUnityRuntimeClientProvider.cs
Normal file
144
Assets/Scripts/Gameplay/AetheriaUnityRuntimeClientProvider.cs
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
/* 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 System.IO;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
|
||||
public static class AetheriaUnityRuntimeClientProvider
|
||||
{
|
||||
private static AetheriaClient _runtimeClient;
|
||||
private static string _runtimeClientStatePath;
|
||||
private static string _runtimeClientRuntimeId;
|
||||
private static RuntimePlayerSettings _runtimePlayerSettings;
|
||||
|
||||
public static RuntimePlayerSettings PlayerSettings =>
|
||||
_runtimePlayerSettings ??= LoadPlayerSettings();
|
||||
|
||||
public static AetheriaClient ResolveClient(string stateFilePath, string runtimeId = "")
|
||||
{
|
||||
var effectiveRuntimeId = string.IsNullOrWhiteSpace(runtimeId) ? "raven-unity" : runtimeId;
|
||||
if (_runtimeClient != null &&
|
||||
string.Equals(_runtimeClientStatePath, stateFilePath, StringComparison.Ordinal) &&
|
||||
string.Equals(_runtimeClientRuntimeId, effectiveRuntimeId, StringComparison.Ordinal))
|
||||
{
|
||||
return _runtimeClient;
|
||||
}
|
||||
|
||||
Dispose();
|
||||
_runtimeClient = AetheriaClient
|
||||
.OpenAsync(
|
||||
stateFilePath,
|
||||
effectiveRuntimeId,
|
||||
"local",
|
||||
startServer: false,
|
||||
pullOnOpen: true)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
_runtimeClientStatePath = stateFilePath;
|
||||
_runtimeClientRuntimeId = effectiveRuntimeId;
|
||||
return _runtimeClient;
|
||||
}
|
||||
|
||||
public static AetheriaClient CurrentClientForStateFile(string stateFilePath)
|
||||
{
|
||||
return _runtimeClient != null &&
|
||||
string.Equals(_runtimeClientStatePath, stateFilePath, StringComparison.Ordinal)
|
||||
? _runtimeClient
|
||||
: null;
|
||||
}
|
||||
|
||||
public static void Dispose()
|
||||
{
|
||||
_runtimeClient?.Dispose();
|
||||
_runtimeClient = null;
|
||||
_runtimeClientStatePath = null;
|
||||
_runtimeClientRuntimeId = null;
|
||||
}
|
||||
|
||||
private static RuntimePlayerSettings LoadPlayerSettings()
|
||||
{
|
||||
var settings = CreateDefaultPlayerSettings();
|
||||
try
|
||||
{
|
||||
var stored = ResolveClient(AetheriaUnityRuntimePaths.RuntimeStateFilePath)
|
||||
.PlayerSettingsAsync()
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
if (stored == null)
|
||||
return settings;
|
||||
|
||||
ApplyPlayerSettings(settings, stored);
|
||||
Debug.Log("Loaded Aetheria Verse player settings from typed state.");
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to load Aetheria Verse player settings from typed state; using defaults: {ex}");
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
private static RuntimePlayerSettings CreateDefaultPlayerSettings()
|
||||
{
|
||||
var settings = new RuntimePlayerSettings();
|
||||
settings.Name = Environment.UserName;
|
||||
settings.InputSettings.SetActionBarInputEnabled("<Keyboard>/leftShift", true);
|
||||
settings.InputSettings.SetActionBarInputEnabled("<Mouse>/leftButton", true);
|
||||
settings.InputSettings.SetActionBarInputEnabled("<Mouse>/rightButton", true);
|
||||
settings.InputSettings.SetActionBarInputEnabled("<Mouse>/middleButton", true);
|
||||
for (var i = 1; i < 6; i++)
|
||||
settings.InputSettings.SetActionBarInputEnabled($"<Keyboard>/{i}", true);
|
||||
return settings;
|
||||
}
|
||||
|
||||
private static void ApplyPlayerSettings(
|
||||
RuntimePlayerSettings settings,
|
||||
AetheriaRuntimePlayerSettingsSnapshot stored)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(stored.PlayerName))
|
||||
settings.Name = stored.PlayerName;
|
||||
|
||||
settings.TutorialPassed = stored.TutorialPassed;
|
||||
|
||||
settings.HashedStoryFiles.Clear();
|
||||
foreach (var storyFileHash in stored.StoryFileHashes)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(storyFileHash.StoryPath))
|
||||
settings.HashedStoryFiles[storyFileHash.StoryPath] = storyFileHash.Hash;
|
||||
}
|
||||
|
||||
if (Enum.TryParse(stored.TemperatureUnit, out TemperatureUnit temperatureUnit))
|
||||
settings.GameplaySettings.TemperatureUnit = temperatureUnit;
|
||||
settings.GameplaySettings.SignificantDigits = Math.Max(0, stored.SignificantDigits);
|
||||
|
||||
if (Enum.TryParse(stored.NebulaQuality, out Quality nebulaQuality))
|
||||
settings.GraphicsSettings.NebulaQuality = nebulaQuality;
|
||||
settings.GraphicsSettings.ShowAsteroidsInMinimap = stored.ShowAsteroidsInMinimap;
|
||||
|
||||
settings.InputSettings.InputActionMap.Clear();
|
||||
foreach (var binding in stored.BindingOverrides)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(binding.ActionName) ||
|
||||
string.IsNullOrWhiteSpace(binding.BindingPath) ||
|
||||
binding.BindingIndex < 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
settings.InputSettings.SetBindingOverride(binding.ActionName, binding.BindingIndex, binding.BindingPath);
|
||||
}
|
||||
|
||||
settings.InputSettings.ActionBarInputs.Clear();
|
||||
foreach (var input in stored.ActionBarInputs)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(input))
|
||||
settings.InputSettings.SetActionBarInputEnabled(input, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 95ae2790dbb68864a954847834215f2f
|
||||
20
Assets/Scripts/Gameplay/AetheriaUnityRuntimePaths.cs
Normal file
20
Assets/Scripts/Gameplay/AetheriaUnityRuntimePaths.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
using System.IO;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
|
||||
public static class AetheriaUnityRuntimePaths
|
||||
{
|
||||
private static DirectoryInfo _gameDataDirectory;
|
||||
private static string _runtimeStateFilePath;
|
||||
|
||||
public static DirectoryInfo GameDataDirectory =>
|
||||
_gameDataDirectory ??= new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
|
||||
|
||||
public static string RuntimeStateFilePath =>
|
||||
_runtimeStateFilePath ??= AetheriaRuntimeStateBoot.Inspect(GameDataDirectory).StateFilePath;
|
||||
|
||||
public static void ClearRuntimeStateFilePathCache()
|
||||
{
|
||||
_runtimeStateFilePath = null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 36e68ebb69d4af84cb7f485e11fd6e6c
|
||||
232
Assets/Scripts/Gameplay/AetheriaUnityTargetPresentation.cs
Normal file
232
Assets/Scripts/Gameplay/AetheriaUnityTargetPresentation.cs
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using float3 = Unity.Mathematics.float3;
|
||||
|
||||
public sealed class AetheriaUnityTargetPresentation
|
||||
{
|
||||
private readonly Dictionary<Entity, VisibleTargetIndicator> _visibleHostileIndicators =
|
||||
new Dictionary<Entity, VisibleTargetIndicator>();
|
||||
private readonly Dictionary<Entity, VisibleTargetIndicator> _visibleFriendlyIndicators =
|
||||
new Dictionary<Entity, VisibleTargetIndicator>();
|
||||
private readonly HashSet<Entity> _observedHostileIndicatorTargets = new HashSet<Entity>();
|
||||
private readonly HashSet<Entity> _observedFriendlyIndicatorTargets = new HashSet<Entity>();
|
||||
private readonly List<Entity> _staleIndicatorTargets = new List<Entity>();
|
||||
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public Prototype HostileTargetIndicator { get; set; }
|
||||
public Prototype FriendlyTargetIndicator { get; set; }
|
||||
public PlaceUIElementWorldspace ViewDot { get; set; }
|
||||
public PlaceUIElementWorldspace TargetIndicator { get; set; }
|
||||
public Image TargetHitpointsFill { get; set; }
|
||||
public Image TargetVisibilityFill { get; set; }
|
||||
public Image VisibilityToTargetFill { get; set; }
|
||||
public Image TargetShieldsFill { get; set; }
|
||||
public AetheriaRuntimeCatalogSnapshot RuntimeCatalog { get; set; }
|
||||
public Func<AetheriaClient> ResolveClient { get; set; }
|
||||
public Func<int, Entity> ResolveEntity { get; set; }
|
||||
public Func<Entity, Entity> ResolveTarget { get; set; }
|
||||
public Func<Entity, Entity, float> ResolveInfoGathered { get; set; }
|
||||
public Func<Entity, Entity, bool> ResolveHostileContact { get; set; }
|
||||
public Func<Entity, double, bool, AetheriaRuntimeZoneContactRow[]> ResolveVisibleContacts { get; set; }
|
||||
|
||||
public Entity Tick(Entity currentEntity, float time)
|
||||
{
|
||||
var observedTarget = ResolveTarget?.Invoke(currentEntity);
|
||||
ReconcileVisibleTargetIndicators(currentEntity);
|
||||
UpdateVisibleIndicatorPresentation(
|
||||
_visibleHostileIndicators,
|
||||
currentEntity,
|
||||
observedTarget,
|
||||
time,
|
||||
blinkSpottedTargets: true);
|
||||
UpdateVisibleIndicatorPresentation(
|
||||
_visibleFriendlyIndicators,
|
||||
currentEntity,
|
||||
observedTarget,
|
||||
time,
|
||||
blinkSpottedTargets: false);
|
||||
UpdateTargetStatus(currentEntity, observedTarget);
|
||||
return observedTarget;
|
||||
}
|
||||
|
||||
public void ReconcileVisibleTargetIndicators(Entity currentEntity)
|
||||
{
|
||||
_observedHostileIndicatorTargets.Clear();
|
||||
_observedFriendlyIndicatorTargets.Clear();
|
||||
|
||||
var renderSettings = ZoneRenderer?.RenderSettings;
|
||||
if (currentEntity != null && renderSettings != null)
|
||||
{
|
||||
var contacts = ResolveVisibleContacts?.Invoke(
|
||||
currentEntity,
|
||||
renderSettings.TargetDetectionInfoThreshold,
|
||||
true) ?? Array.Empty<AetheriaRuntimeZoneContactRow>();
|
||||
|
||||
foreach (var contact in contacts)
|
||||
{
|
||||
if (ResolveEntity?.Invoke(contact.TargetEntityIndex) is not { } target ||
|
||||
ReferenceEquals(target, currentEntity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (contact.Hostile)
|
||||
_observedHostileIndicatorTargets.Add(target);
|
||||
else
|
||||
_observedFriendlyIndicatorTargets.Add(target);
|
||||
}
|
||||
}
|
||||
|
||||
ReconcileVisibleTargetIndicators(
|
||||
_visibleHostileIndicators,
|
||||
_observedHostileIndicatorTargets,
|
||||
HostileTargetIndicator);
|
||||
ReconcileVisibleTargetIndicators(
|
||||
_visibleFriendlyIndicators,
|
||||
_observedFriendlyIndicatorTargets,
|
||||
FriendlyTargetIndicator);
|
||||
}
|
||||
|
||||
public void ClearIndicators()
|
||||
{
|
||||
ClearIndicators(_visibleHostileIndicators);
|
||||
ClearIndicators(_visibleFriendlyIndicators);
|
||||
}
|
||||
|
||||
public void UpdateTargetIndicators(
|
||||
Entity currentEntity,
|
||||
bool isCurrentEntityObservedUndocked,
|
||||
AetheriaUnityCurrentEntityPresentation currentEntityPresentation)
|
||||
{
|
||||
if (!isCurrentEntityObservedUndocked ||
|
||||
currentEntity == null ||
|
||||
ZoneRenderer == null ||
|
||||
ViewDot == null ||
|
||||
!ZoneRenderer.TryGetEntityInstance(currentEntity, out var entityInstance))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var observedTarget = ResolveTarget?.Invoke(currentEntity);
|
||||
ViewDot.Target = entityInstance.LookAtPoint.position;
|
||||
if (observedTarget != null && TargetIndicator != null)
|
||||
TargetIndicator.Target = observedTarget.Position;
|
||||
|
||||
var distance = CultMath.math.length(AetheriaMath.ToCult((float3)ViewDot.Target) - currentEntity.CultPosition);
|
||||
foreach (var (_, barrels, crosshair) in currentEntityPresentation.ArticulationGroups)
|
||||
{
|
||||
var averagePosition = Vector3.zero;
|
||||
foreach (var barrel in barrels)
|
||||
averagePosition += barrel.position + barrel.forward * distance;
|
||||
averagePosition /= barrels.Length;
|
||||
crosshair.Target = averagePosition;
|
||||
}
|
||||
|
||||
foreach (var (targetLock, indicator, spin) in currentEntityPresentation.LockingIndicators)
|
||||
{
|
||||
var showLockingIndicator = targetLock.Lock > .01f &&
|
||||
observedTarget != null &&
|
||||
ResolveHostileContact?.Invoke(currentEntity, observedTarget) == true;
|
||||
indicator.gameObject.SetActive(showLockingIndicator);
|
||||
if (!showLockingIndicator)
|
||||
continue;
|
||||
|
||||
var renderSettings = ZoneRenderer.RenderSettings;
|
||||
indicator.Target = observedTarget.Position;
|
||||
indicator.NoiseAmplitude = (float)renderSettings.ResolveLockIndicatorNoiseAmplitude(targetLock.Lock);
|
||||
indicator.NoiseFrequency = (float)renderSettings.ResolveLockIndicatorNoiseFrequency(targetLock.Lock);
|
||||
spin.Speed = (float)renderSettings.ResolveLockSpinSpeed(targetLock.Lock);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateVisibleIndicatorPresentation(
|
||||
Dictionary<Entity, VisibleTargetIndicator> indicators,
|
||||
Entity currentEntity,
|
||||
Entity observedTarget,
|
||||
float time,
|
||||
bool blinkSpottedTargets)
|
||||
{
|
||||
var renderSettings = ZoneRenderer?.RenderSettings;
|
||||
if (renderSettings == null)
|
||||
return;
|
||||
|
||||
foreach (var indicator in indicators)
|
||||
{
|
||||
indicator.Value.gameObject.SetActive(indicator.Key != observedTarget);
|
||||
indicator.Value.Place.Target = indicator.Key.Position;
|
||||
if (!indicator.Key.Active)
|
||||
{
|
||||
indicator.Value.Fill.enabled = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
var infoGathered = ResolveInfoGathered?.Invoke(indicator.Key, currentEntity) ?? 0f;
|
||||
indicator.Value.Fill.fillAmount = (float)renderSettings.NormalizeDetectionProgress(infoGathered);
|
||||
indicator.Value.Fill.enabled = !blinkSpottedTargets ||
|
||||
renderSettings.ResolveTargetSpottedFillEnabled(infoGathered, time);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateTargetStatus(Entity currentEntity, Entity target)
|
||||
{
|
||||
if (currentEntity == null || target == null || ZoneRenderer?.RenderSettings == null)
|
||||
return;
|
||||
|
||||
var renderSettings = ZoneRenderer.RenderSettings;
|
||||
var targetInfoGathered = ResolveInfoGathered?.Invoke(currentEntity, target) ?? 0f;
|
||||
var visibilityToTarget = ResolveInfoGathered?.Invoke(target, currentEntity) ?? 0f;
|
||||
TargetVisibilityFill.fillAmount = (float)renderSettings.NormalizeTargetVisibilityFill(targetInfoGathered);
|
||||
VisibilityToTargetFill.fillAmount = (float)renderSettings.NormalizeVisibilityToTargetFill(visibilityToTarget);
|
||||
var targetHull = RuntimeCatalog?.FindItem(target.Hull?.ItemKey ?? "");
|
||||
var targetMaxDurability = targetHull?.Durability > 0
|
||||
? (float)targetHull.Durability
|
||||
: Math.Max(target.Hull.Durability, 1f);
|
||||
TargetHitpointsFill.fillAmount =
|
||||
(float)renderSettings.NormalizeTargetStatusFill(target.Hull.Durability / targetMaxDurability);
|
||||
TargetShieldsFill.fillAmount = target.Shield == null
|
||||
? 0
|
||||
: (float)renderSettings.NormalizeTargetStatusFill(target.Shield.Progress);
|
||||
}
|
||||
|
||||
private void ReconcileVisibleTargetIndicators(
|
||||
Dictionary<Entity, VisibleTargetIndicator> indicators,
|
||||
HashSet<Entity> desiredTargets,
|
||||
Prototype prototype)
|
||||
{
|
||||
if (prototype == null)
|
||||
return;
|
||||
|
||||
_staleIndicatorTargets.Clear();
|
||||
foreach (var indicator in indicators)
|
||||
{
|
||||
if (!desiredTargets.Contains(indicator.Key))
|
||||
_staleIndicatorTargets.Add(indicator.Key);
|
||||
}
|
||||
|
||||
foreach (var staleTarget in _staleIndicatorTargets)
|
||||
{
|
||||
indicators[staleTarget].GetComponent<Prototype>().ReturnToPool();
|
||||
indicators.Remove(staleTarget);
|
||||
}
|
||||
|
||||
foreach (var target in desiredTargets)
|
||||
{
|
||||
if (!indicators.ContainsKey(target))
|
||||
indicators.Add(target, prototype.Instantiate<VisibleTargetIndicator>());
|
||||
}
|
||||
}
|
||||
|
||||
private static void ClearIndicators(Dictionary<Entity, VisibleTargetIndicator> indicators)
|
||||
{
|
||||
foreach (var indicator in indicators.Values)
|
||||
indicator.GetComponent<Prototype>().ReturnToPool();
|
||||
indicators.Clear();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 51baf83a22ca0be45abd418061686244
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/* 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 System.Collections.Generic;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
|
||||
public static class AetheriaUnityWeaponPresentationPolicy
|
||||
{
|
||||
private static readonly HashSet<string> ArticulatedWeaponBehaviorKinds = new HashSet<string>(StringComparer.Ordinal)
|
||||
{
|
||||
"GuidedWeapon",
|
||||
"InstantWeapon",
|
||||
"ConstantWeapon",
|
||||
"ChargedWeapon",
|
||||
"AutoWeapon"
|
||||
};
|
||||
|
||||
public static bool HasArticulatedWeaponBehavior(
|
||||
AetheriaRuntimeCatalogSnapshot runtimeCatalog,
|
||||
EquippedItem item)
|
||||
{
|
||||
var typedItem = runtimeCatalog?.FindItem(item?.EquippableItem?.ItemKey ?? "");
|
||||
if (typedItem?.BehaviorKinds == null)
|
||||
return false;
|
||||
|
||||
foreach (var behaviorKind in typedItem.BehaviorKinds)
|
||||
{
|
||||
if (ArticulatedWeaponBehaviorKinds.Contains(behaviorKind))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cf148956af2c4b5780cb1adcdcee0fd1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -41,11 +41,6 @@ public class EntityInstance : MonoBehaviour
|
|||
// private (Reactor reactor, GameObject sfxSource) _reactor;
|
||||
// private Dictionary<Radiator, GameObject> _radiatorSfx = new Dictionary<Radiator, GameObject>();
|
||||
|
||||
private static AetheriaRuntimeCatalogItem FindTypedHull(ItemInstance hull)
|
||||
{
|
||||
return ActionGameManager.RuntimeCatalog?.FindItem(hull?.ItemKey ?? "");
|
||||
}
|
||||
|
||||
private static Vector2 ToVector2(CultMath.float2 value) => new Vector2(value.x, value.y);
|
||||
private static Vector2 ToVector2(Unity.Mathematics.float2 value) => new Vector2(value.x, value.y);
|
||||
|
||||
|
|
@ -156,7 +151,7 @@ public class EntityInstance : MonoBehaviour
|
|||
Entity = entity;
|
||||
DaemonEntityIndex = entity.DaemonEntityIndex;
|
||||
ZoneRenderer = zoneRenderer;
|
||||
var typedHull = FindTypedHull(entity.Hull);
|
||||
var typedHull = ZoneRenderer?.FindCatalogItem(entity.Hull);
|
||||
if (typedHull == null || typedHull.ShapeWidth <= 0 || typedHull.ShapeHeight <= 0 || typedHull.ShapeCells.Count == 0)
|
||||
{
|
||||
Debug.LogError($"Cannot bind entity instance for {entity.Name}: missing typed hull shape.");
|
||||
|
|
|
|||
|
|
@ -473,13 +473,15 @@ public sealed class AetheriaYmirPhysicsBridge : MonoBehaviour
|
|||
? 1.0f / inverseMass
|
||||
: 1.0f;
|
||||
var rotation = view.HasRotation ? view.RotationRadians[i] : 0;
|
||||
var position = view.Position[i];
|
||||
var velocity = view.HasVelocity ? view.Velocity[i] : default;
|
||||
|
||||
_daemonBodies.Add(new YmirPhysicsBody
|
||||
{
|
||||
id = DaemonEntityBodyPrefix + daemonEntityIndex,
|
||||
position = new YmirVec2 { x = view.PositionX[i], y = view.PositionZ[i] },
|
||||
position = new YmirVec2 { x = position.x, y = position.z },
|
||||
velocity = view.HasVelocity
|
||||
? new YmirVec2 { x = view.VelocityX[i], y = view.VelocityZ[i] }
|
||||
? new YmirVec2 { x = velocity.x, y = velocity.z }
|
||||
: default,
|
||||
direction = new YmirVec2 { x = Mathf.Sin(rotation), y = Mathf.Cos(rotation) },
|
||||
angularVelocity = 0,
|
||||
|
|
|
|||
|
|
@ -131,15 +131,10 @@ public class ShipInstance : EntityInstance
|
|||
|
||||
private float GetMaxDurability(ItemInstance item)
|
||||
{
|
||||
var typedItem = FindTypedItem(item);
|
||||
var typedItem = ZoneRenderer?.FindCatalogItem(item);
|
||||
if (typedItem != null && typedItem.Durability > 0)
|
||||
return (float)typedItem.Durability;
|
||||
|
||||
return item is EquippableItem equippable ? Math.Max(equippable.Durability, 1f) : 1f;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCatalogItem FindTypedItem(ItemInstance item)
|
||||
{
|
||||
return ActionGameManager.RuntimeCatalog?.FindItem(item?.ItemKey ?? "");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public class ConstantLaser : MonoBehaviour
|
|||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public float Range { get; set; }
|
||||
|
||||
private float _intensity;
|
||||
|
|
@ -69,7 +70,7 @@ public class ConstantLaser : MonoBehaviour
|
|||
LineRenderer.SetPosition(0, transform.position);
|
||||
var hitFound = false;
|
||||
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
|
||||
ActionGameManager.Instance?.ZoneRenderer,
|
||||
ZoneRenderer,
|
||||
SourceEntity,
|
||||
transform.position,
|
||||
transform.forward,
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ public class ConstantLaserManager : ConstantWeaponEffectManager
|
|||
{
|
||||
var p = LaserPrototype.Instantiate<ConstantLaser>();
|
||||
p.SourceEntity = source.Entity;
|
||||
p.ZoneRenderer = source.ZoneRenderer;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
p.Range = weapon.Range;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ public class GuidedProjectile : MonoBehaviour
|
|||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
|
||||
public event Action OnKill;
|
||||
|
||||
|
|
@ -112,6 +113,7 @@ public class GuidedProjectile : MonoBehaviour
|
|||
child.Source = Source;
|
||||
child.Target = Target;
|
||||
child.SourceEntity = SourceEntity;
|
||||
child.ZoneRenderer = ZoneRenderer;
|
||||
child.GuidanceCurve = GuidanceCurve;
|
||||
child.LiftCurve = LiftCurve;
|
||||
child.ThrustCurve = ThrustCurve;
|
||||
|
|
@ -144,7 +146,7 @@ public class GuidedProjectile : MonoBehaviour
|
|||
if(_alive)
|
||||
{
|
||||
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
|
||||
ActionGameManager.Instance?.ZoneRenderer,
|
||||
ZoneRenderer,
|
||||
SourceEntity,
|
||||
t.position,
|
||||
Velocity,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
|
|||
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
|
||||
p.Source = source.transform;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.ZoneRenderer = source.ZoneRenderer;
|
||||
p.Target = target.transform;
|
||||
p.Frequency = weapon.GuidedProjectileDodgeFrequency;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
|
|
@ -48,6 +49,7 @@ public class GuidedProjectileManager : InstantWeaponEffectManager
|
|||
var p = ProjectilePrototype.Instantiate<GuidedProjectile>();
|
||||
p.Source = source.transform;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.ZoneRenderer = source.ZoneRenderer;
|
||||
p.Frequency = weapon.GuidedProjectileDodgeFrequency;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public class HitscanEffect : MonoBehaviour
|
|||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public float Range { get; set; }
|
||||
|
||||
private float _startTime;
|
||||
|
|
@ -23,7 +24,7 @@ public class HitscanEffect : MonoBehaviour
|
|||
_startTime = Time.time;
|
||||
var hitFound = false;
|
||||
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
|
||||
ActionGameManager.Instance?.ZoneRenderer,
|
||||
ZoneRenderer,
|
||||
SourceEntity,
|
||||
transform.position,
|
||||
transform.forward,
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ public class HitscanManager : InstantWeaponEffectManager
|
|||
{
|
||||
var p = Prototype.Instantiate<HitscanEffect>();
|
||||
p.SourceEntity = source.Entity;
|
||||
p.ZoneRenderer = source.ZoneRenderer;
|
||||
var hp = source.Entity.Hardpoints[item.Position.x, item.Position.y];
|
||||
var barrel = source.GetBarrel(hp);
|
||||
var t = p.transform;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public class Laser : MonoBehaviour
|
|||
public float Spread { get; set; }
|
||||
public DamageType DamageType { get; set; }
|
||||
public Entity SourceEntity { get; set; }
|
||||
public ZoneRenderer ZoneRenderer { get; set; }
|
||||
public float Range { get; set; }
|
||||
|
||||
private float _startTime;
|
||||
|
|
@ -36,7 +37,7 @@ public class Laser : MonoBehaviour
|
|||
LineRenderer.SetPosition(0, transform.position);
|
||||
var hitFound = false;
|
||||
if (AetheriaYmirPhysicsBridge.Instance.TryCastZoneHulls(
|
||||
ActionGameManager.Instance?.ZoneRenderer,
|
||||
ZoneRenderer,
|
||||
SourceEntity,
|
||||
transform.position,
|
||||
transform.forward,
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ public class LaserManager : InstantWeaponEffectManager
|
|||
t.forward = barrel.forward;
|
||||
t.position = barrel.position;
|
||||
p.SourceEntity = source.Entity;
|
||||
p.ZoneRenderer = source.ZoneRenderer;
|
||||
p.Damage = weapon.Damage;
|
||||
p.Range = weapon.Range;
|
||||
p.Penetration = weapon.Penetration;
|
||||
|
|
|
|||
Loading…
Reference in a new issue