Skip to content

Commit

Permalink
fix: RegisterOnFinishLoading not working BZ (#547)
Browse files Browse the repository at this point in the history
* OnFinishLoading is now called on finish loading BZ

* Converted `OnLoad` to local method
  • Loading branch information
Metious committed May 6, 2024
1 parent 1711ac2 commit c068b7f
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions Nautilus/Patchers/SaveUtilsPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using System.Collections;
using System.Collections.Generic;
using HarmonyLib;
using Nautilus.Extensions;
using UnityEngine;

namespace Nautilus.Patchers;

Expand Down Expand Up @@ -64,17 +66,40 @@ internal static IEnumerator InvokeLoadEvents(IEnumerator enumerator)
{
yield return enumerator.Current;
}

OnFinishLoadingEvents?.Invoke();

if (oneTimeUseOnLoadEvents.Count > 0)

#if SUBNAUTICA
OnLoad();
#elif BELOWZERO
uGUI_MainMenu.main.StartCoroutine(WaitUntilLoaded());

IEnumerator WaitUntilLoaded()
{
foreach (Action action in oneTimeUseOnLoadEvents)
if (uGUI.main.loading.isLoading)
{
action.Invoke();
yield return new WaitWhile(() => uGUI.main.loading.isLoading);
}

if (WaitScreen.main.Exists()?.isShown is true)
{
yield return new WaitWhile(() => WaitScreen.main.isShown);
}

OnLoad();
}
#endif
void OnLoad()
{
OnFinishLoadingEvents?.Invoke();

if (oneTimeUseOnLoadEvents.Count > 0)
{
foreach (Action action in oneTimeUseOnLoadEvents)
{
action.Invoke();
}

oneTimeUseOnLoadEvents.Clear();
}

oneTimeUseOnLoadEvents.Clear();
}
}

Expand Down

0 comments on commit c068b7f

Please sign in to comment.