Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
JohnCorby 2022-07-21 16:52:02 -07:00
commit 25df3d8bbe
2 changed files with 26 additions and 39 deletions

View File

@ -90,7 +90,7 @@ namespace NewHorizons.Builder.Props
// 1) Run Floyd-Warshall on the dimensions (where each dimension is a vertex and each node is an edge)
// 2) For each dimension A, if it's possible to reach dimension B, add dimension B's signals to the list propagatedSignals[A]
var allDimensions = PlanetCreationHandler.allBodies.Where(body => body?.Config?.Bramble?.dimension != null).Select(body => body.Config).ToList();
var allDimensions = PlanetCreationHandler.Bodies.Where(body => body?.Config?.Bramble?.dimension != null).Select(body => body.Config).ToList();
//
// Floyd Warshall

View File

@ -17,36 +17,24 @@ namespace NewHorizons.Handlers
{
public static class PlanetCreationHandler
{
public static List<NewHorizonsBody> NextPassBodies = new List<NewHorizonsBody>();
public static List<NewHorizonsBody> Bodies { get; private set; }
// I literally forget what this is for
private static Dictionary<AstroObject, NewHorizonsBody> ExistingAOConfigs;
private static List<NewHorizonsBody> _nextPassBodies = new List<NewHorizonsBody>();
private static Dictionary<NHAstroObject, NewHorizonsBody> _dict;
private static Dictionary<AstroObject, NewHorizonsBody> _dimensions;
// Stock bodies being updated
private static Dictionary<NHAstroObject, NewHorizonsBody> _existingBodyDict;
public static List<NewHorizonsBody> allBodies;
public static NewHorizonsBody GetNewHorizonsBody(AstroObject ao)
{
if (ao is NHAstroObject nhAO)
{
if (_dict.ContainsKey(nhAO)) return _dict[nhAO];
}
if (!_dimensions.ContainsKey(ao)) return null;
return _dimensions[ao];
}
// Custom bodies being created
private static Dictionary<NHAstroObject, NewHorizonsBody> _customBodyDict;
public static void Init(List<NewHorizonsBody> bodies)
{
Main.FurthestOrbit = 30000;
ExistingAOConfigs = new Dictionary<AstroObject, NewHorizonsBody>();
_dict = new Dictionary<NHAstroObject, NewHorizonsBody>();
_dimensions = new Dictionary<AstroObject, NewHorizonsBody>();
allBodies = bodies;
_existingBodyDict = new();
_customBodyDict = new();
Bodies = bodies;
// Set up stars
// Need to manage this when there are multiple stars
@ -125,15 +113,15 @@ namespace NewHorizons.Handlers
Logger.Log("Loading Deferred Bodies");
// Make a copy of the next pass of bodies so that the array can be edited while we load them
toLoad = NextPassBodies.Select(x => x).ToList();
while (NextPassBodies.Count != 0)
toLoad = _nextPassBodies.Select(x => x).ToList();
while (_nextPassBodies.Count != 0)
{
foreach (var body in toLoad)
{
LoadBody(body, true);
}
toLoad = NextPassBodies;
NextPassBodies = new List<NewHorizonsBody>();
toLoad = _nextPassBodies;
_nextPassBodies = new List<NewHorizonsBody>();
}
Logger.Log("Done loading bodies");
@ -179,7 +167,7 @@ namespace NewHorizons.Handlers
var ao = quantumPlanet.GetComponent<NHAstroObject>();
var rootSector = quantumPlanet.GetComponentInChildren<Sector>();
var groundOrbit = _dict[ao].Config.Orbit;
var groundOrbit = _customBodyDict[ao].Config.Orbit;
quantumPlanet.groundState = new QuantumPlanet.State(rootSector, groundOrbit);
quantumPlanet.states.Add(quantumPlanet.groundState);
@ -188,7 +176,7 @@ namespace NewHorizons.Handlers
visibilityTracker.transform.parent = existingPlanet.transform;
visibilityTracker.transform.localPosition = Vector3.zero;
var sphere = visibilityTracker.AddComponent<SphereShape>();
sphere.radius = GetSphereOfInfluence(_dict[ao]);
sphere.radius = GetSphereOfInfluence(_customBodyDict[ao]);
var tracker = visibilityTracker.AddComponent<ShapeVisibilityTracker>();
quantumPlanet._visibilityTrackers = new VisibilityTracker[] { tracker };
}
@ -230,7 +218,7 @@ namespace NewHorizons.Handlers
if (body.Config.isQuantumState)
{
// If the ground state object isn't made yet do it later
NextPassBodies.Add(body);
_nextPassBodies.Add(body);
}
else
{
@ -246,8 +234,7 @@ namespace NewHorizons.Handlers
var solarSystemRoot = SearchUtilities.Find("SolarSystemRoot").transform;
planetObject.GetComponent<OWRigidbody>()._origParent = ao.IsDimension ? solarSystemRoot.Find("Dimensions") : solarSystemRoot;
if (!ao.IsDimension) _dict.Add(ao, body);
else _dimensions.Add(ao, body);
_customBodyDict.Add(ao, body);
}
catch (Exception e)
{
@ -363,7 +350,7 @@ namespace NewHorizons.Handlers
}
else
{
NextPassBodies.Add(body);
_nextPassBodies.Add(body);
return null;
}
}
@ -657,10 +644,10 @@ namespace NewHorizons.Handlers
var childAO = child.GetComponent<NHAstroObject>() ?? child.GetComponent<AstroObject>();
if (childAO != null)
{
if (childAO is NHAstroObject && ExistingAOConfigs.ContainsKey(childAO))
if (childAO is NHAstroObject childNHAO && _existingBodyDict.ContainsKey(childNHAO))
{
// If it's already an NH object we repeat the whole process else it doesn't work idk
NextPassBodies.Add(ExistingAOConfigs[childAO]);
_nextPassBodies.Add(_existingBodyDict[childNHAO]);
}
else
{
@ -684,7 +671,7 @@ namespace NewHorizons.Handlers
// Have to register this new AO to the locator
Locator.RegisterAstroObject(newAO);
ExistingAOConfigs.Add(newAO, body);
_existingBodyDict.Add(newAO, body);
}
catch (Exception ex)
{