move stuff out of QSBSceneManager

This commit is contained in:
JohnCorby 2022-05-03 21:53:18 -07:00
parent aeee63ac90
commit 8f38bedcfa
3 changed files with 26 additions and 24 deletions

View File

@ -202,6 +202,14 @@ public class QSBNetworkManager : NetworkManager, IAddComponentOnStart
};
}
QSBSceneManager.OnPostSceneLoad += (_, loadScene) =>
{
if (QSBCore.IsInMultiplayer && loadScene == OWScene.TitleScreen)
{
StopHost();
}
};
DebugLog.DebugWrite("Network Manager ready.", MessageType.Success);
}

View File

@ -2,9 +2,7 @@
using OWML.Common;
using QSB.Patches;
using QSB.Utility;
using QSB.WorldSync;
using System;
using UnityEngine;
namespace QSB;
@ -20,11 +18,13 @@ public static class QSBSceneManager
public static event Action<OWScene, OWScene> OnUniverseSceneLoaded;
/// <summary>
/// runs before objects are destroyed
/// runs before the scene is changed
/// and objects are destroyed
/// </summary>
public static event LoadManager.SceneLoadEvent OnPreSceneLoad;
/// <summary>
/// runs after objects are awakened and started
/// runs after the scene has changewd
/// and objects are awakened and started
/// </summary>
public static event LoadManager.SceneLoadEvent OnPostSceneLoad;
@ -42,24 +42,6 @@ public static class QSBSceneManager
OnPostSceneLoad?.SafeInvoke(originalScene, loadScene);
});
OnPreSceneLoad += (_, _) =>
QSBWorldSync.RemoveWorldObjects();
OnPostSceneLoad += (_, loadScene) =>
{
if (QSBCore.IsInMultiplayer)
{
if (loadScene.IsUniverseScene())
{
QSBWorldSync.BuildWorldObjects(loadScene).Forget();
}
if (loadScene == OWScene.TitleScreen)
{
QSBNetworkManager.singleton.StopHost();
}
}
};
DebugLog.DebugWrite("Scene Manager ready.", MessageType.Success);
}

View File

@ -180,7 +180,18 @@ public static class QSBWorldSync
private static readonly Dictionary<MonoBehaviour, IWorldObject> UnityObjectsToWorldObjects = new();
private static readonly Dictionary<Type, MonoBehaviour> CachedUnityObjects = new();
static QSBWorldSync() =>
static QSBWorldSync()
{
QSBSceneManager.OnPreSceneLoad += (_, _) =>
RemoveWorldObjects();
QSBSceneManager.OnPostSceneLoad += (_, loadScene) =>
{
if (QSBCore.IsInMultiplayer && loadScene.IsUniverseScene())
{
BuildWorldObjects(loadScene).Forget();
}
};
RequestInitialStatesMessage.SendInitialState += to =>
{
DialogueConditions.ForEach(condition
@ -189,6 +200,7 @@ public static class QSBWorldSync
ShipLogFacts.ForEach(fact
=> new RevealFactMessage(fact.Id, fact.SaveGame, false) { To = to }.Send());
};
}
private static void GameInit()
{
@ -278,7 +290,7 @@ public static class QSBWorldSync
if (unityObjects.Count() != 1)
{
DebugLog.ToConsole($"Warning - Tried to cache a unity object that there are multiple of. ({typeof(TUnityObject).Name})" +
$"\r\nCaching the first one - this probably is going to end badly!", MessageType.Warning);
"\r\nCaching the first one - this probably is going to end badly!", MessageType.Warning);
}
var unityObject = unityObjects.First();