Skip to content

Commit

Permalink
Add callbacks to be run after MM is finished with the patch.
Browse files Browse the repository at this point in the history
  • Loading branch information
sarbian committed Sep 17, 2014
1 parent 5752ef3 commit 5404d70
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions moduleManager.cs
Expand Up @@ -313,10 +313,10 @@ public bool ElectionAndCheck()
}
}

public delegate void ModuleManagerPostPatchCallback();

public class MMPatchLoader : LoadingSystem
{
private static MMPatchLoader _instance;

public int totalPatchCount = 0;

public int appliedPatchCount = 0;
Expand All @@ -343,19 +343,18 @@ public class MMPatchLoader : LoadingSystem

private static ConfigNode topNode;

public static MMPatchLoader Instance
{
get { return _instance; }
}
private static List<ModuleManagerPostPatchCallback> postPatchCallbacks = new List<ModuleManagerPostPatchCallback>();

public static MMPatchLoader Instance { get; private set; }

private void Awake()
{
if (_instance != null)
if (Instance != null)
{
DestroyImmediate(this);
return;
}
_instance = this;
Instance = this;
DontDestroyOnLoad(gameObject);
}

Expand Down Expand Up @@ -413,6 +412,17 @@ public void StartLoad(bool blocking)
}
else
StartCoroutine(ProcessPatch(excludePaths));

foreach (var callback in postPatchCallbacks)
{
callback();
}
}

public static void addPostPatchCallback(ModuleManagerPostPatchCallback callback)
{
if (!postPatchCallbacks.Contains(callback))
postPatchCallbacks.Add(callback);
}

private List<String> PrePatchInit()
Expand Down Expand Up @@ -569,6 +579,12 @@ private IEnumerator ProcessPatch(List<String> excludePaths)
PartResourceLibrary.Instance.LoadDefinitions();

ready = true;

foreach (var callback in postPatchCallbacks)
{
callback();
yield return null;
}
yield return null;
}

Expand Down

0 comments on commit 5404d70

Please sign in to comment.