Prevent onsystemready being called twice, also dont call it from main menu

This commit is contained in:
Nick 2023-07-18 00:25:02 -04:00
parent 35f0e80df4
commit 13c0bdeec5

View File

@ -230,6 +230,7 @@ namespace NewHorizons
NHLogger.LogWarning("Couldn't find planets folder");
}
// Call this from the menu since we hadn't hooked onto the event yet
Delay.FireOnNextUpdate(() => OnSceneLoaded(SceneManager.GetActiveScene(), LoadSceneMode.Single));
Delay.FireOnNextUpdate(() => _firstLoad = false);
Instance.ModHelper.Menus.PauseMenu.OnInit += DebugReload.InitializePauseMenu;
@ -545,6 +546,9 @@ namespace NewHorizons
{
NHLogger.LogError($"Exception thrown when invoking star system loaded event with parameter [{Instance.CurrentStarSystem}]:\n{e}");
}
// Wait for player to be awake and also for frames to pass
Delay.RunWhenAndInNUpdates(() => OnSystemReady(DidWarpFromShip, DidWarpFromVessel), () => _playerAwake && PlayerSpawned, 30);
}
else
{
@ -560,13 +564,16 @@ namespace NewHorizons
_currentStarSystem = _defaultStarSystem;
}
}
// Wait for player to be awake and also for frames to pass
Delay.RunWhenAndInNUpdates(() => OnSystemReady(DidWarpFromShip, DidWarpFromVessel), () => _playerAwake && PlayerSpawned, 30);
}
// Had a bunch of separate unity things firing stuff when the system is ready so I moved it all to here
private void OnSystemReady(bool shouldWarpInFromShip, bool shouldWarpInFromVessel)
{
if (IsSystemReady)
{
NHLogger.LogWarning("OnSystemReady was called twice.");
}
else
{
IsSystemReady = true;
@ -584,6 +591,7 @@ namespace NewHorizons
CloakHandler.OnSystemReady();
}
}
public void EnableWarpDrive()
{