Skip to content

Commit

Permalink
Merge pull request #60 from SpaceWarpDev/fix_mod_persistence
Browse files Browse the repository at this point in the history
Fix #58
  • Loading branch information
Rexicon226 authored Feb 28, 2023
2 parents ef4afb2 + e522f04 commit eefe0eb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions SpaceWarp/API/SpaceWarpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ private void Initialize()
public void InitializeConfigManager()
{
GameObject confManagerObject = new GameObject("Configuration Manager");
DontDestroyOnLoad(confManagerObject);
Persist(confManagerObject);

confManagerObject.AddComponent<ConfigurationManager>();
confManagerObject.SetActive(true);
Expand Down Expand Up @@ -522,7 +522,7 @@ private void InitializeModObject(string modName, ModInfo info, Type mainModType)
try
{
ModLocator.Add(modComponent);
DontDestroyOnLoad(modObject);
Persist(modObject);
modComponent.Initialize();
}
catch(Exception exception)
Expand Down Expand Up @@ -557,15 +557,15 @@ internal void InvokePostInitializeModsAfterAllModsLoaded()
private void InitModUI()
{
GameObject modUIObject = new GameObject("Space Warp Mod UI");
DontDestroyOnLoad(modUIObject);
Persist(modUIObject);

modUIObject.transform.SetParent(transform.parent);
ModListUI = modUIObject.AddComponent<ModListUI>();

modUIObject.SetActive(true);

GameObject consoleUIObject = new GameObject("Space Warp Console");
DontDestroyOnLoad(consoleUIObject);
Persist(consoleUIObject);
consoleUIObject.transform.SetParent(transform.parent);
SpaceWarpConsole con = consoleUIObject.AddComponent<SpaceWarpConsole>();
consoleUIObject.SetActive(true);
Expand All @@ -576,7 +576,7 @@ private void InitModUI()
public T RegisterGameToolbarMenu<T>(string text, Sprite icon, string id) where T : ToolbarMenu
{
GameObject toolBarUIObject = new GameObject($"Toolbar: {id}");
DontDestroyOnLoad(toolBarUIObject);
Persist(toolBarUIObject);
ToolbarMenu menu = toolBarUIObject.AddComponent<T>();
menu.Name = text;
toolBarUIObject.transform.SetParent(transform.parent);
Expand All @@ -585,6 +585,12 @@ public T RegisterGameToolbarMenu<T>(string text, Sprite icon, string id) where T
return menu as T;
}

public static void Persist(GameObject toPersist)
{
DontDestroyOnLoad(toPersist);
toPersist.tag = "Game Manager";
}

private void LoadAllButtons()
{
foreach (var button in _buttonsToBeLoaded)
Expand Down
2 changes: 1 addition & 1 deletion SpaceWarp/StartupManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static void OnGameStarted()
private static void CreateSpaceWarpManager()
{
GameObject spaceWarp = new GameObject("Space Warp");
Object.DontDestroyOnLoad(spaceWarp);
SpaceWarpManager.Persist(spaceWarp);
SpaceWarpObject = spaceWarp.AddComponent<SpaceWarpManager>();
spaceWarp.SetActive(true);
// SpaceWarpObject.Initialize();
Expand Down

0 comments on commit eefe0eb

Please sign in to comment.