Added Overwriting SolarSystem Planets

This commit is contained in:
Ben C 2022-02-10 18:50:59 -05:00
parent 77c749a2ac
commit a0b1de7e60
3 changed files with 88 additions and 28 deletions

View File

@ -16,13 +16,13 @@ namespace NewHorizons.Builder.ShipLog
public static class MapModeBuilder public static class MapModeBuilder
{ {
#region General #region General
public static ShipLogAstroObject[][] ConstructMapMode(string systemName, GameObject transformParent, int layer) public static ShipLogAstroObject[][] ConstructMapMode(string systemName, GameObject transformParent, ShipLogAstroObject[][] currentNav, int layer)
{ {
Material greyScaleMaterial = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/Sprite").GetComponent<Image>().material; Material greyScaleMaterial = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/TimberHearth/Sprite").GetComponent<Image>().material;
List<NewHorizonsBody> bodies = Main.BodyDict[systemName].Where(b => (b.Config.ShipLog?.mapMode?.remove ?? false) == false).ToList(); List<NewHorizonsBody> bodies = Main.BodyDict[systemName].Where(b => (b.Config.ShipLog?.mapMode?.remove ?? false) == false).ToList();
bool flagManualPositionUsed = false; bool flagManualPositionUsed = systemName == "SolarSystem";
bool flagAutoPositionUsed = false; bool flagAutoPositionUsed = false;
foreach (NewHorizonsBody body in bodies) foreach (NewHorizonsBody body in bodies.Where(b => ShipLogHandler.IsVanillaBody(b) == false))
{ {
if (body.Config.ShipLog?.mapMode?.manualPosition == null) if (body.Config.ShipLog?.mapMode?.manualPosition == null)
{ {
@ -50,7 +50,7 @@ namespace NewHorizons.Builder.ShipLog
} }
else if (flagManualPositionUsed) else if (flagManualPositionUsed)
{ {
return ConstructMapModeManual(bodies, transformParent, greyScaleMaterial, layer); return ConstructMapModeManual(bodies, transformParent, greyScaleMaterial, currentNav, layer);
} }
return null; return null;
} }
@ -178,18 +178,32 @@ namespace NewHorizons.Builder.ShipLog
#endregion #endregion
#region Manual Map Mode #region Manual Map Mode
private static ShipLogAstroObject[][] ConstructMapModeManual(List<NewHorizonsBody> bodies, GameObject transformParent, Material greyScaleMaterial, int layer) private static ShipLogAstroObject[][] ConstructMapModeManual(List<NewHorizonsBody> bodies, GameObject transformParent, Material greyScaleMaterial, ShipLogAstroObject[][] currentNav, int layer)
{ {
int maxAmount = bodies.Count; int maxAmount = bodies.Count + 20;
ShipLogAstroObject[][] navMatrix = new ShipLogAstroObject[maxAmount][]; ShipLogAstroObject[][] navMatrix = new ShipLogAstroObject[maxAmount][];
for (int i = 0; i < maxAmount; i++) for (int i = 0; i < maxAmount; i++)
{ {
navMatrix[i] = new ShipLogAstroObject[maxAmount]; navMatrix[i] = new ShipLogAstroObject[maxAmount];
} }
foreach (NewHorizonsBody body in bodies) Dictionary<string, int[]> astroIdToNavIndex = new Dictionary<string, int[]>();
if (Main.Instance.CurrentStarSystem == "SolarSystem")
{
for (int y = 0; y < currentNav.Length; y++)
{
for (int x = 0; x < currentNav[y].Length; x++)
{
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))
{ {
if (ShipLogHandler.IsVanillaBody(body)) continue;
GameObject newMapModeGO = CreateMapModeGameObject(body, transformParent, layer, body.Config.ShipLog?.mapMode?.manualPosition); GameObject newMapModeGO = CreateMapModeGameObject(body, transformParent, layer, body.Config.ShipLog?.mapMode?.manualPosition);
ShipLogAstroObject newAstroObject = AddShipLogAstroObject(newMapModeGO, body, greyScaleMaterial, layer); ShipLogAstroObject newAstroObject = AddShipLogAstroObject(newMapModeGO, body, greyScaleMaterial, layer);
MakeDetails(body, newMapModeGO.transform, greyScaleMaterial); MakeDetails(body, newMapModeGO.transform, greyScaleMaterial);
@ -197,10 +211,44 @@ namespace NewHorizons.Builder.ShipLog
navMatrix[(int) navigationPosition.y][(int) navigationPosition.x] = newAstroObject; navMatrix[(int) navigationPosition.y][(int) navigationPosition.x] = newAstroObject;
} }
navMatrix = navMatrix.Where(a => a.Count(c => c != null) > 0).Prepend(new ShipLogAstroObject[1]).ToArray(); if (Main.Instance.CurrentStarSystem == "SolarSystem")
{
foreach (NewHorizonsBody body in Main.BodyDict["SolarSystem"].Where(ShipLogHandler.IsVanillaBody))
{
GameObject gameObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + body.Config.Name.Replace(" ", ""));
if (body.Config.Destroy || (body.Config.ShipLog?.mapMode?.remove ?? false))
{
ShipLogAstroObject astroObject = gameObject.GetComponent<ShipLogAstroObject>();
if (astroObject != null)
{
int[] navIndex = astroIdToNavIndex[astroObject.GetID()];
navMatrix[navIndex[0]][navIndex[1]] = null;
}
Object.Destroy(gameObject);
}
else
{
if (body.Config.ShipLog?.mapMode?.manualPosition != null)
{
gameObject.transform.localPosition = (Vector2)body.Config.ShipLog.mapMode.manualPosition;
}
if (body.Config.ShipLog?.mapMode?.manualNavigationPosition != null)
{
Vector2 navigationPosition = body.Config.ShipLog?.mapMode?.manualNavigationPosition;
navMatrix[(int) navigationPosition.y][(int) navigationPosition.x] = gameObject.GetComponent<ShipLogAstroObject>();
}
if (body.Config.ShipLog?.mapMode?.scale != null)
{
gameObject.transform.localScale = Vector3.one * body.Config.ShipLog.mapMode.scale;
}
}
}
}
navMatrix = navMatrix.Where(a => a.Count(c => c != null && c.gameObject != null) > 0).Prepend(new ShipLogAstroObject[1]).ToArray();
for (var index = 0; index < navMatrix.Length; index++) for (var index = 0; index < navMatrix.Length; index++)
{ {
navMatrix[index] = navMatrix[index].Where(a => a != null).ToArray(); navMatrix[index] = navMatrix[index].Where(a => a != null && a.gameObject != null).ToArray();
} }
return navMatrix; return navMatrix;

View File

@ -18,10 +18,18 @@ namespace NewHorizons.Builder.Handlers
private static Dictionary<string, NewHorizonsBody> _astroIdToBody = new Dictionary<string, NewHorizonsBody>(); private static Dictionary<string, NewHorizonsBody> _astroIdToBody = new Dictionary<string, NewHorizonsBody>();
private static string[] vanillaBodies; private static string[] vanillaBodies;
private static string[] vanillaIDs;
public static void Init() public static void Init()
{ {
vanillaBodies = SearchUtilities.GetAllChildren(GameObject.Find(PAN_ROOT_PATH)).ConvertAll(g => g.name).ToArray(); List<GameObject> gameObjects = SearchUtilities.GetAllChildren(GameObject.Find(PAN_ROOT_PATH));
vanillaBodies = gameObjects.ConvertAll(g => g.name).ToArray();
vanillaIDs = gameObjects.ConvertAll(g => g.GetComponent<ShipLogAstroObject>()?.GetID()).ToArray();
}
public static bool IsVanillaAstroID(string astroId)
{
return vanillaIDs.Contains(astroId);
} }
public static bool IsVanillaBody(NewHorizonsBody body) public static bool IsVanillaBody(NewHorizonsBody body)

View File

@ -43,6 +43,7 @@ namespace NewHorizons.Tools
logEntryLocation._initialized = true; logEntryLocation._initialized = true;
} }
} }
foreach (NewHorizonsBody body in Main.BodyDict[Main.Instance.CurrentStarSystem]) foreach (NewHorizonsBody body in Main.BodyDict[Main.Instance.CurrentStarSystem])
{ {
if (body.Config.ShipLog?.curiosities != null) if (body.Config.ShipLog?.curiosities != null)
@ -50,6 +51,7 @@ namespace NewHorizons.Tools
RumorModeBuilder.AddCuriosityColors(body.Config.ShipLog.curiosities); RumorModeBuilder.AddCuriosityColors(body.Config.ShipLog.curiosities);
} }
} }
foreach (NewHorizonsBody body in Main.BodyDict[Main.Instance.CurrentStarSystem]) foreach (NewHorizonsBody body in Main.BodyDict[Main.Instance.CurrentStarSystem])
{ {
if (body.Config.ShipLog?.xmlFile != null) if (body.Config.ShipLog?.xmlFile != null)
@ -67,6 +69,7 @@ namespace NewHorizons.Tools
ShipLogEntry logEntry = __instance._entryList[i]; ShipLogEntry logEntry = __instance._entryList[i];
RumorModeBuilder.UpdateEntryCuriosity(ref logEntry); RumorModeBuilder.UpdateEntryCuriosity(ref logEntry);
} }
Logger.Log("Ship Log Generation Complete For: " + Main.Instance.CurrentStarSystem, Logger.LogType.Log); Logger.Log("Ship Log Generation Complete For: " + Main.Instance.CurrentStarSystem, Logger.LogType.Log);
} }
@ -82,6 +85,7 @@ namespace NewHorizons.Tools
{ {
__result = false; __result = false;
} }
return false; return false;
} }
@ -99,6 +103,7 @@ namespace NewHorizons.Tools
__instance.RevealFact(fact, false, false); __instance.RevealFact(fact, false, false);
} }
} }
if (Main.Instance.CurrentStarSystem == "SolarSystem") if (Main.Instance.CurrentStarSystem == "SolarSystem")
{ {
return true; return true;
@ -124,35 +129,35 @@ namespace NewHorizons.Tools
} }
public static void OnShipLogMapModeInitialize(ShipLogMapMode __instance) public static void OnShipLogMapModeInitialize(ShipLogMapMode __instance)
{
if (Main.Instance.CurrentStarSystem != "SolarSystem")
{ {
GameObject panRoot = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH); GameObject panRoot = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH);
GameObject sunObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun"); GameObject sunObject = GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/Sun");
ShipLogAstroObject[][] navMatrix = MapModeBuilder.ConstructMapMode(Main.Instance.CurrentStarSystem, panRoot, sunObject.layer); ShipLogAstroObject[][] navMatrix = MapModeBuilder.ConstructMapMode(Main.Instance.CurrentStarSystem, panRoot, __instance._astroObjects, sunObject.layer);
if (navMatrix == null || navMatrix.Length <= 1) if (navMatrix == null || navMatrix.Length <= 1)
{ {
Logger.LogWarning("No planets suitable for map mode found! Defaulting to vanilla menu (expect weirdness!)."); Logger.LogWarning("Skipping Map Mode Generation.");
} }
else else
{ {
__instance._astroObjects = navMatrix; __instance._astroObjects = navMatrix;
__instance._startingAstroObjectID = navMatrix[1][0].GetID(); __instance._startingAstroObjectID = navMatrix[1][0].GetID();
if (Main.Instance.CurrentStarSystem != "SolarSystem")
{
List<GameObject> delete = SearchUtilities.GetAllChildren(panRoot).Where(g => g.name.Contains("_ShipLog") == false).ToList(); List<GameObject> delete = SearchUtilities.GetAllChildren(panRoot).Where(g => g.name.Contains("_ShipLog") == false).ToList();
foreach (GameObject gameObject in delete) foreach (GameObject gameObject in delete)
{ {
Object.Destroy(GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + gameObject.name)); Object.Destroy(GameObject.Find(ShipLogHandler.PAN_ROOT_PATH + "/" + gameObject.name));
} }
// Just Lie About Having A Sand Funnel
__instance._sandFunnel = __instance.gameObject.AddComponent<ShipLogSandFunnel>(); __instance._sandFunnel = __instance.gameObject.AddComponent<ShipLogSandFunnel>();
} }
} }
Logger.Log("Map Mode Construction Complete", Logger.LogType.Log); Logger.Log("Map Mode Construction Complete", Logger.LogType.Log);
} }
public static bool OnShipLogAstroObjectGetName(ShipLogAstroObject __instance, ref string __result) public static bool OnShipLogAstroObjectGetName(ShipLogAstroObject __instance, ref string __result)
{ {
if (Main.Instance.CurrentStarSystem == "SolarSystem") if (ShipLogHandler.IsVanillaAstroID(__instance.GetID()))
{ {
return true; return true;
} }
@ -198,4 +203,3 @@ namespace NewHorizons.Tools
} }
} }
} }