From 65694f2666ef08bc4ec46c04f0476e450a68c436 Mon Sep 17 00:00:00 2001 From: "Nick J. Connors" Date: Mon, 21 Feb 2022 02:47:39 -0500 Subject: [PATCH] Fix more issues with vanilla bodies --- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 47 ++++++++++++------- .../Builder/ShipLog/RumorModeBuilder.cs | 10 +++- NewHorizons/Handlers/ShipLogHandler.cs | 4 ++ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index f50d4cbc..10520e91 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -201,25 +201,38 @@ namespace NewHorizons.Builder.ShipLog navMatrix[y][x] = currentNav[y][x]; astroIdToNavIndex.Add(currentNav[y][x].GetID(), new [] {y, x}); } - } + } } - foreach (NewHorizonsBody body in bodies.Where(b => ShipLogHandler.IsVanillaBody(b) == false)) + foreach(NewHorizonsBody body in bodies) { - if (body.Config.ShipLog == null) continue; + if (body.Config.ShipLog?.mapMode?.manualNavigationPosition == null) continue; - GameObject newMapModeGO = CreateMapModeGameObject(body, transformParent, layer, body.Config.ShipLog?.mapMode?.manualPosition); - ShipLogAstroObject newAstroObject = AddShipLogAstroObject(newMapModeGO, body, greyScaleMaterial, layer); - MakeDetails(body, newMapModeGO.transform, greyScaleMaterial); - Vector2 navigationPosition = body.Config.ShipLog?.mapMode?.manualNavigationPosition; - navMatrix[(int) navigationPosition.y][(int) navigationPosition.x] = newAstroObject; - } - - if (Main.Instance.CurrentStarSystem == "SolarSystem") - { - foreach (NewHorizonsBody body in Main.BodyDict["SolarSystem"].Where(ShipLogHandler.IsVanillaBody)) + // Sometimes they got other names idk + var name = body.Config.Name.Replace(" ", ""); + var existingBody = AstroObjectLocator.GetAstroObject(body.Config.Name); + if (existingBody != null) { - GameObject gameObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + body.Config.Name.Replace(" ", "")); + var astroName = existingBody.GetAstroObjectName(); + if (astroName == AstroObject.Name.RingWorld) name = "InvisiblePlanet"; + else if (astroName != AstroObject.Name.CustomString) name = astroName.ToString(); + } + // Should probably also just fix the IsVanilla method + var isVanilla = ShipLogHandler.IsVanillaBody(body); + + Logger.Log($"The name: {name} is vanilla? {isVanilla}"); + + if (!isVanilla) + { + GameObject newMapModeGO = CreateMapModeGameObject(body, transformParent, layer, body.Config.ShipLog?.mapMode?.manualPosition); + ShipLogAstroObject newAstroObject = AddShipLogAstroObject(newMapModeGO, body, greyScaleMaterial, layer); + MakeDetails(body, newMapModeGO.transform, greyScaleMaterial); + Vector2 navigationPosition = body.Config.ShipLog?.mapMode?.manualNavigationPosition; + navMatrix[(int)navigationPosition.y][(int)navigationPosition.x] = newAstroObject; + } + else if (Main.Instance.CurrentStarSystem == "SolarSystem") + { + GameObject gameObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + name); if (body.Config.Destroy || (body.Config.ShipLog?.mapMode?.remove ?? false)) { ShipLogAstroObject astroObject = gameObject.GetComponent(); @@ -232,7 +245,7 @@ namespace NewHorizons.Builder.ShipLog GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); } } - else if(body.Config.Name == "SandFunnel") + else if (name == "SandFunnel") { GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + "SandFunnel").SetActive(false); } @@ -247,11 +260,11 @@ namespace NewHorizons.Builder.ShipLog if (body.Config.ShipLog?.mapMode?.manualNavigationPosition != null) { Vector2 navigationPosition = body.Config.ShipLog?.mapMode?.manualNavigationPosition; - navMatrix[(int) navigationPosition.y][(int) navigationPosition.x] = gameObject.GetComponent(); + navMatrix[(int)navigationPosition.y][(int)navigationPosition.x] = gameObject.GetComponent(); } if (body.Config.ShipLog?.mapMode?.scale != null) { - gameObject.transform.localScale = Vector3.one * body.Config.ShipLog.mapMode.scale; + gameObject.transform.localScale = Vector3.one * body.Config.ShipLog.mapMode.scale; } } } diff --git a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs index 6647123d..3b61eb33 100644 --- a/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/RumorModeBuilder.cs @@ -180,7 +180,15 @@ namespace NewHorizons.Builder.ShipLog { if (_entryIdToRawName.ContainsKey(entry._id)) { - entry._curiosity = _rawNameToCuriosityName[_entryIdToRawName[entry._id]]; + var raw = _entryIdToRawName[entry._id]; + if (_rawNameToCuriosityName.ContainsKey(raw)) + { + entry._curiosity = _rawNameToCuriosityName[raw]; + } + else + { + Logger.LogError($"Couldn't find {raw}. Did you define the curiosity in a json config? Because you have to."); + } } } diff --git a/NewHorizons/Handlers/ShipLogHandler.cs b/NewHorizons/Handlers/ShipLogHandler.cs index 8b9c5fd3..1dec08c2 100644 --- a/NewHorizons/Handlers/ShipLogHandler.cs +++ b/NewHorizons/Handlers/ShipLogHandler.cs @@ -34,6 +34,10 @@ namespace NewHorizons.Builder.Handlers public static bool IsVanillaBody(NewHorizonsBody body) { + var existingBody = AstroObjectLocator.GetAstroObject(body.Config.Name); + if (existingBody != null && existingBody.GetAstroObjectName() != AstroObject.Name.CustomString) + return true; + return vanillaBodies.Contains(body.Config.Name.Replace(" ", "")); }