Move Aetheria EveUnity hooks into provider package
This commit is contained in:
parent
b945e4e177
commit
074eab26fe
9 changed files with 188 additions and 69 deletions
|
|
@ -0,0 +1,99 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using GameCult.Mesh;
|
||||
using UnityEngine;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.EveRuntime
|
||||
{
|
||||
public static class AetheriaEveRuntimeUnityClientCache
|
||||
{
|
||||
private static readonly Dictionary<string, AetheriaClient> RuntimeClients =
|
||||
new Dictionary<string, AetheriaClient>(StringComparer.Ordinal);
|
||||
private static DirectoryInfo? s_gameDataDirectory;
|
||||
private static string? s_runtimeStateFilePath;
|
||||
|
||||
public static DirectoryInfo GameDataDirectory =>
|
||||
s_gameDataDirectory ??= new DirectoryInfo(Application.dataPath).Parent.CreateSubdirectory("GameData");
|
||||
|
||||
public static string RuntimeStateFilePath =>
|
||||
s_runtimeStateFilePath ??= AetheriaRuntimeStateBoot.Inspect(GameDataDirectory).StateFilePath;
|
||||
|
||||
public static AetheriaClientState RuntimeState(
|
||||
AetheriaRuntimeStateBootReport stateBoot,
|
||||
string runtimeId = "")
|
||||
{
|
||||
return RuntimeClient(stateBoot, runtimeId).State;
|
||||
}
|
||||
|
||||
public static AetheriaControl Control(
|
||||
AetheriaRuntimeStateBootReport stateBoot,
|
||||
string runtimeId = "")
|
||||
{
|
||||
return RuntimeClient(stateBoot, runtimeId).Control;
|
||||
}
|
||||
|
||||
public static AetheriaUi Ui(
|
||||
AetheriaRuntimeStateBootReport stateBoot,
|
||||
string runtimeId = "")
|
||||
{
|
||||
return RuntimeClient(stateBoot, runtimeId).Ui;
|
||||
}
|
||||
|
||||
public static CultMeshStateRefResolver EveSurfaceCultMeshStateRefResolver(
|
||||
AetheriaRuntimeStateBootReport stateBoot,
|
||||
string runtimeId = "")
|
||||
{
|
||||
return RuntimeState(stateBoot, runtimeId).CreateEveSurfaceCultMeshStateRefResolver();
|
||||
}
|
||||
|
||||
public static void ClearRuntimeStateFilePathCache()
|
||||
{
|
||||
s_runtimeStateFilePath = null;
|
||||
}
|
||||
|
||||
public static void Dispose()
|
||||
{
|
||||
foreach (var client in RuntimeClients.Values)
|
||||
client.Dispose();
|
||||
|
||||
RuntimeClients.Clear();
|
||||
s_runtimeStateFilePath = null;
|
||||
}
|
||||
|
||||
private static AetheriaClient RuntimeClient(
|
||||
AetheriaRuntimeStateBootReport stateBoot,
|
||||
string runtimeId = "")
|
||||
{
|
||||
return ResolveClient(
|
||||
stateBoot.StateFilePath,
|
||||
string.IsNullOrWhiteSpace(runtimeId) ? stateBoot.RuntimeId : runtimeId);
|
||||
}
|
||||
|
||||
private static AetheriaClient ResolveClient(string stateFilePath, string runtimeId)
|
||||
{
|
||||
var effectiveStateFilePath = stateFilePath ?? "";
|
||||
var effectiveRuntimeId = string.IsNullOrWhiteSpace(runtimeId)
|
||||
? AetheriaRuntimeStateBoundary.DefaultClientRuntimeId
|
||||
: runtimeId;
|
||||
var cacheKey = effectiveStateFilePath + "\n" + effectiveRuntimeId;
|
||||
if (RuntimeClients.TryGetValue(cacheKey, out var runtimeClient))
|
||||
return runtimeClient;
|
||||
|
||||
runtimeClient = AetheriaClient
|
||||
.OpenAsync(
|
||||
effectiveStateFilePath,
|
||||
effectiveRuntimeId,
|
||||
"local",
|
||||
startServer: false,
|
||||
pullOnOpen: true)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
RuntimeClients[cacheKey] = runtimeClient;
|
||||
return runtimeClient;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2a2c3bf5e2954d1f8aeab60ee92f7f0a
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.EveRuntime
|
||||
{
|
||||
public static class AetheriaEveRuntimeUnityHookInstaller
|
||||
{
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
public static void Install()
|
||||
{
|
||||
AetheriaEveRuntimeUnityHooks.ResolveStateBoot =
|
||||
overridePath => AetheriaRuntimeStateBoot.Inspect(
|
||||
AetheriaEveRuntimeUnityClientCache.GameDataDirectory,
|
||||
overridePath ?? "");
|
||||
AetheriaEveRuntimeUnityHooks.RuntimeState =
|
||||
(stateBoot, runtimeId) => AetheriaEveRuntimeUnityClientCache.RuntimeState(stateBoot, runtimeId);
|
||||
AetheriaEveRuntimeUnityHooks.Control =
|
||||
(stateBoot, runtimeId) => AetheriaEveRuntimeUnityClientCache.Control(stateBoot, runtimeId);
|
||||
AetheriaEveRuntimeUnityHooks.Ui =
|
||||
(stateBoot, runtimeId) => AetheriaEveRuntimeUnityClientCache.Ui(stateBoot, runtimeId);
|
||||
AetheriaEveRuntimeUnityHooks.StateRefResolver =
|
||||
(stateBoot, runtimeId) =>
|
||||
AetheriaEveRuntimeUnityClientCache.EveSurfaceCultMeshStateRefResolver(stateBoot, runtimeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d60d5ddc6b3240438128f85f90464b42
|
||||
Loading…
Reference in a new issue