Skip to content

Commit

Permalink
change to string event
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Feb 16, 2025
1 parent cfaa0dc commit 3251805
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
27 changes: 18 additions & 9 deletions NewHorizons/Handlers/TitleSceneHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,6 @@ public static void Init()
// default to displaying nh planets if no title screen builders
else
DisplayBodiesOnTitleScreen();

try
{
Main.Instance.OnTitleScreenLoaded?.Invoke();
}
catch (Exception e)
{
NHLogger.LogError($"Error in event handler for OnTitleScreenLoaded: {e}");
}
}

public static void InitSubtitles()
Expand Down Expand Up @@ -465,6 +456,15 @@ public void Build()
{
NHLogger.LogError(e);
}

try
{
Main.Instance.OnTitleScreenLoaded?.Invoke(mod.ModHelper.Manifest.UniqueName);
}
catch (Exception e)
{
NHLogger.LogError($"Error in event handler for OnTitleScreenLoaded on title screen {mod.ModHelper.Manifest.UniqueName}: {e}");
}
}

public IModBehaviour Mod => mod;
Expand Down Expand Up @@ -500,6 +500,15 @@ public void Build()
{
NHLogger.LogError(e);
}

try
{
Main.Instance.OnTitleScreenLoaded?.Invoke(mod.ModHelper.Manifest.UniqueName);
}
catch (Exception e)
{
NHLogger.LogError($"Error in event handler for OnTitleScreenLoaded on title screen {mod.ModHelper.Manifest.UniqueName}: {e}");
}
}

public IModBehaviour Mod => mod;
Expand Down
5 changes: 3 additions & 2 deletions NewHorizons/INewHorizons.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ public interface INewHorizons
UnityEvent<string> GetBodyLoadedEvent();

/// <summary>
/// An event invoked when NH has finished building the title screen.
/// An event invoked when NH has finished building a title screen.
/// Gives the unique name of the mod the title screen builder was from.
/// </summary>
UnityEvent GetTitleScreenLoadedEvent();
UnityEvent<string> GetTitleScreenLoadedEvent();
#endregion

#region Querying configs
Expand Down
10 changes: 5 additions & 5 deletions NewHorizons/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ public string CurrentStarSystem
public ShipWarpController ShipWarpController { get; private set; }

// API events
public class StarSystemEvent : UnityEvent<string> { }
public StarSystemEvent OnChangeStarSystem = new();
public StarSystemEvent OnStarSystemLoaded = new();
public StarSystemEvent OnPlanetLoaded = new();
public UnityEvent OnTitleScreenLoaded = new();
public class StringEvent : UnityEvent<string> { }
public StringEvent OnChangeStarSystem = new();
public StringEvent OnStarSystemLoaded = new();
public StringEvent OnPlanetLoaded = new();
public StringEvent OnTitleScreenLoaded = new();

/// <summary>
/// Depending on platform, the AsyncOwnershipStatus might not be ready by the time we go to check it.
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/NewHorizonsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public GameObject GetPlanet(string name)
public UnityEvent<string> GetChangeStarSystemEvent() => Main.Instance.OnChangeStarSystem;
public UnityEvent<string> GetStarSystemLoadedEvent() => Main.Instance.OnStarSystemLoaded;
public UnityEvent<string> GetBodyLoadedEvent() => Main.Instance.OnPlanetLoaded;
public UnityEvent GetTitleScreenLoadedEvent() => Main.Instance.OnTitleScreenLoaded;
public UnityEvent<string> GetTitleScreenLoadedEvent() => Main.Instance.OnTitleScreenLoaded;

public bool SetDefaultSystem(string name)
{
Expand Down

0 comments on commit 3251805

Please sign in to comment.