2022-05-04 04:20:59 +00:00
|
|
|
|
using HarmonyLib;
|
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Patches;
|
2020-11-04 09:34:01 +00:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using System;
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB;
|
|
|
|
|
|
|
|
|
|
public static class QSBSceneManager
|
2020-08-16 20:39:21 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static OWScene CurrentScene => LoadManager.GetCurrentScene();
|
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
public static bool IsInUniverse => CurrentScene.IsUniverseScene();
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-05-04 05:04:27 +00:00
|
|
|
|
[Obsolete("TODO: remove after migration")]
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static event Action<OWScene, OWScene, bool> OnSceneLoaded;
|
2022-05-04 05:04:27 +00:00
|
|
|
|
[Obsolete("TODO: remove after migration")]
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public static event Action<OWScene, OWScene> OnUniverseSceneLoaded;
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-05-04 04:20:59 +00:00
|
|
|
|
/// <summary>
|
2022-05-04 05:55:09 +00:00
|
|
|
|
/// runs before the scene is changed.
|
|
|
|
|
/// happens before OnDestroy.
|
2022-05-04 04:20:59 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static event LoadManager.SceneLoadEvent OnPreSceneLoad;
|
|
|
|
|
/// <summary>
|
2022-05-04 05:55:09 +00:00
|
|
|
|
/// runs after the scene is changed.
|
|
|
|
|
/// happens after Awake, but before Start.
|
2022-05-04 04:20:59 +00:00
|
|
|
|
/// </summary>
|
|
|
|
|
public static event LoadManager.SceneLoadEvent OnPostSceneLoad;
|
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
static QSBSceneManager()
|
|
|
|
|
{
|
2022-05-04 04:20:59 +00:00
|
|
|
|
LoadManager.OnStartSceneLoad += (originalScene, loadScene) =>
|
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"PRE SCENE LOAD ({originalScene} -> {loadScene})", MessageType.Info);
|
|
|
|
|
OnPreSceneLoad?.SafeInvoke(originalScene, loadScene);
|
|
|
|
|
};
|
|
|
|
|
LoadManager.OnCompleteSceneLoad += (originalScene, loadScene) =>
|
2022-05-04 05:55:09 +00:00
|
|
|
|
{
|
|
|
|
|
DebugLog.DebugWrite($"POST SCENE LOAD ({originalScene} -> {loadScene})", MessageType.Info);
|
|
|
|
|
OnPostSceneLoad?.SafeInvoke(originalScene, loadScene);
|
2022-05-04 05:56:23 +00:00
|
|
|
|
|
|
|
|
|
OnCompleteSceneLoad(originalScene, loadScene);
|
2022-05-04 05:55:09 +00:00
|
|
|
|
};
|
2020-08-16 20:39:21 +00:00
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
|
2022-05-04 05:04:27 +00:00
|
|
|
|
[Obsolete("TODO: remove after migration")]
|
|
|
|
|
private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
|
|
|
|
|
{
|
|
|
|
|
var universe = newScene.IsUniverseScene();
|
|
|
|
|
|
|
|
|
|
OnSceneLoaded?.SafeInvoke(oldScene, newScene, universe);
|
|
|
|
|
if (universe)
|
|
|
|
|
{
|
|
|
|
|
OnUniverseSceneLoaded?.SafeInvoke(oldScene, newScene);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-04 04:41:05 +00:00
|
|
|
|
public static bool IsUniverseScene(this OWScene scene) =>
|
2022-03-03 03:46:33 +00:00
|
|
|
|
scene is OWScene.SolarSystem or OWScene.EyeOfTheUniverse;
|
2022-05-04 04:20:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HarmonyPatch(typeof(GhostBrain))]
|
2022-05-04 04:41:05 +00:00
|
|
|
|
internal class TestPatch : QSBPatch
|
2022-05-04 04:20:59 +00:00
|
|
|
|
{
|
|
|
|
|
public override QSBPatchTypes Type => QSBPatchTypes.OnModStart;
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(GhostBrain.Awake))]
|
|
|
|
|
private static void Awake() => DebugLog.DebugWrite("GhostBrain.Awake");
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(GhostBrain.Start))]
|
|
|
|
|
private static void Start() => DebugLog.DebugWrite("GhostBrain.Start");
|
|
|
|
|
|
|
|
|
|
[HarmonyPrefix]
|
|
|
|
|
[HarmonyPatch(nameof(GhostBrain.OnDestroy))]
|
|
|
|
|
private static void OnDestroy() => DebugLog.DebugWrite("GhostBrain.OnDestroy");
|
|
|
|
|
}
|