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> /// </summary>
public string[] removeChildren; 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 #endregion
#region Modules #region Modules
@ -530,7 +535,7 @@ namespace NewHorizons.External.Configs
Spawn.shipSpawnPoints = new SpawnModule.ShipSpawnPoint[] { Spawn.shipSpawn }; Spawn.shipSpawnPoints = new SpawnModule.ShipSpawnPoint[] { Spawn.shipSpawn };
} }
// Because these guys put TWO spawn points // Because these guys put TWO spawn points
if (starSystem == "2walker2.OogaBooga" && name == "The Campground") if (starSystem == "2walker2.OogaBooga" && name == "The Campground")
{ {
Spawn.playerSpawnPoints[0].isDefault = true; Spawn.playerSpawnPoints[0].isDefault = true;
@ -742,4 +747,4 @@ namespace NewHorizons.External.Configs
} }
#endregion #endregion
} }
} }

View File

@ -168,26 +168,29 @@ namespace NewHorizons.Handlers
// I don't remember doing this why is it exceptions what am I doing // I don't remember doing this why is it exceptions what am I doing
GameObject existingPlanet = null; GameObject existingPlanet = null;
try if (body.Config.checkForExisting)
{ {
existingPlanet = AstroObjectLocator.GetAstroObject(body.Config.name).gameObject; try
}
catch (Exception)
{
if (body?.Config?.name == null)
{ {
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) if (existingPlanet == null && body.Config.destroy)
{ {
NHLogger.LogError($"{body.Config.name} was meant to be destroyed, but was not found"); NHLogger.LogError($"{body.Config.name} was meant to be destroyed, but was not found");
return false; return false;
}
} }
if (existingPlanet != null) if (existingPlanet != null)
@ -287,9 +290,9 @@ namespace NewHorizons.Handlers
try try
{ {
NHLogger.Log($"Creating [{body.Config.name}]"); NHLogger.Log($"Creating [{body.Config.name}]");
var planetObject = GenerateBody(body, defaultPrimaryToSun) var planetObject = GenerateBody(body, defaultPrimaryToSun)
?? throw new NullReferenceException("Something went wrong when generating the body but no errors were logged."); ?? throw new NullReferenceException("Something went wrong when generating the body but no errors were logged.");
planetObject.SetActive(true); planetObject.SetActive(true);
var ao = planetObject.GetComponent<NHAstroObject>(); var ao = planetObject.GetComponent<NHAstroObject>();
@ -316,7 +319,7 @@ namespace NewHorizons.Handlers
{ {
NHLogger.LogError($"Error in event handler for OnPlanetLoaded on body {body.Config.name}: {e}"); NHLogger.LogError($"Error in event handler for OnPlanetLoaded on body {body.Config.name}: {e}");
} }
body.UnloadCache(true); body.UnloadCache(true);
_loadedBodies.Add(body); _loadedBodies.Add(body);
return true; return true;
@ -390,7 +393,7 @@ namespace NewHorizons.Handlers
body.Config.MapMarker.enabled = false; body.Config.MapMarker.enabled = false;
const float sphereOfInfluence = 2000f; const float sphereOfInfluence = 2000f;
var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence, body.Config); var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence, body.Config);
var ao = AstroObjectBuilder.Make(go, null, body, false); var ao = AstroObjectBuilder.Make(go, null, body, false);
@ -402,7 +405,7 @@ namespace NewHorizons.Handlers
BrambleDimensionBuilder.Make(body, go, ao, sector, body.Mod, owRigidBody); BrambleDimensionBuilder.Make(body, go, ao, sector, body.Mod, owRigidBody);
go = SharedGenerateBody(body, go, sector, owRigidBody); go = SharedGenerateBody(body, go, sector, owRigidBody);
// Not included in SharedGenerate to not mess up gravity on base game planets // Not included in SharedGenerate to not mess up gravity on base game planets
if (body.Config.Base.surfaceGravity != 0) if (body.Config.Base.surfaceGravity != 0)
{ {
@ -467,7 +470,7 @@ namespace NewHorizons.Handlers
} }
var sphereOfInfluence = GetSphereOfInfluence(body); var sphereOfInfluence = GetSphereOfInfluence(body);
var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence, body.Config); var owRigidBody = RigidBodyBuilder.Make(go, sphereOfInfluence, body.Config);
var ao = AstroObjectBuilder.Make(go, primaryBody, body, false); var ao = AstroObjectBuilder.Make(go, primaryBody, body, false);
@ -686,7 +689,7 @@ namespace NewHorizons.Handlers
SunOverrideBuilder.Make(go, sector, body.Config.Atmosphere, body.Config.Water, surfaceSize); SunOverrideBuilder.Make(go, sector, body.Config.Atmosphere, body.Config.Water, surfaceSize);
} }
} }
if (body.Config.Atmosphere.fogSize != 0) if (body.Config.Atmosphere.fogSize != 0)
{ {
fog = FogBuilder.Make(go, sector, body.Config.Atmosphere, body.Mod); fog = FogBuilder.Make(go, sector, body.Config.Atmosphere, body.Mod);