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
{
#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;
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;
foreach (NewHorizonsBody body in bodies)
foreach (NewHorizonsBody body in bodies.Where(b => ShipLogHandler.IsVanillaBody(b) == false))
{
if (body.Config.ShipLog?.mapMode?.manualPosition == null)
{
@ -50,7 +50,7 @@ namespace NewHorizons.Builder.ShipLog
}
else if (flagManualPositionUsed)
{
return ConstructMapModeManual(bodies, transformParent, greyScaleMaterial, layer);
return ConstructMapModeManual(bodies, transformParent, greyScaleMaterial, currentNav, layer);
}
return null;
}
@ -178,29 +178,77 @@ namespace NewHorizons.Builder.ShipLog
#endregion
#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][];
for (int i = 0; i < maxAmount; i++)
{
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);
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;
}
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++)
{
navMatrix[index] = navMatrix[index].Where(a => a != null).ToArray();
navMatrix[index] = navMatrix[index].Where(a => a != null && a.gameObject != null).ToArray();
}
return navMatrix;

View File

@ -18,10 +18,18 @@ namespace NewHorizons.Builder.Handlers
private static Dictionary<string, NewHorizonsBody> _astroIdToBody = new Dictionary<string, NewHorizonsBody>();
private static string[] vanillaBodies;
private static string[] vanillaIDs;
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)

View File

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