field to not check for existing body

This commit is contained in:
JohnCorby 2025-02-13 21:31:03 -08:00
parent 5beb803835
commit b8d7af90f1
2 changed files with 31 additions and 23 deletions

View File

@ -64,6 +64,11 @@ namespace NewHorizons.External.Configs
/// </summary>
public string[] removeChildren;
/// <summary>
/// optimization. turn this off if you know you're generating a new body and aren't worried about other mods editing it.
/// </summary>
[DefaultValue(true)] public bool checkForExisting = true;
#endregion
#region Modules

View File

@ -168,26 +168,29 @@ namespace NewHorizons.Handlers
// I don't remember doing this why is it exceptions what am I doing
GameObject existingPlanet = null;
try
if (body.Config.checkForExisting)
{
existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.name).gameObject;
}
catch (Exception)
{
if (body?.Config?.name == null)
try
{
NHLogger.LogError($"How is there no name for {body}");
existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.name).gameObject;
}
else
catch (Exception)
{
existingPlanet = SearchUtilities.Find(body.Config.name.Replace(" ", "") + "_Body", false);
if (body?.Config?.name == null)
{
NHLogger.LogError($"How is there no name for {body}");
}
else
{
existingPlanet = SearchUtilities.Find(body.Config.name.Replace(" ", "") + "_Body", false);
}
}
}
if (existingPlanet == null && body.Config.destroy)
{
NHLogger.LogError($"{body.Config.name} was meant to be destroyed, but was not found");
return false;
if (existingPlanet == null && body.Config.destroy)
{
NHLogger.LogError($"{body.Config.name} was meant to be destroyed, but was not found");
return false;
}
}
if (existingPlanet != null)