quantum-space-buddies/QSB/QSBSceneManager.cs

69 lines
2.0 KiB
C#
Raw Normal View History

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 04:41:05 +00:00
[Obsolete]
2022-03-03 03:46:33 +00:00
public static event Action<OWScene, OWScene, bool> OnSceneLoaded;
2022-05-04 04:41:05 +00:00
[Obsolete]
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 04:53:18 +00:00
/// runs before the scene is changed
/// and objects are destroyed
2022-05-04 04:20:59 +00:00
/// </summary>
public static event LoadManager.SceneLoadEvent OnPreSceneLoad;
/// <summary>
2022-05-04 04:53:18 +00:00
/// runs after the scene has changewd
/// and objects are awakened and started
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) =>
Delay.RunNextFrame(() =>
{
DebugLog.DebugWrite($"POST SCENE LOAD ({originalScene} -> {loadScene})", MessageType.Info);
OnPostSceneLoad?.SafeInvoke(originalScene, loadScene);
});
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 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");
}