Build typed Aetheria client surfaces
This commit is contained in:
parent
74b3b3d72a
commit
2e96660d48
246 changed files with 37893 additions and 6728 deletions
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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue