mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Allow mods to change the same planet shiplog
This commit is contained in:
parent
65694f2666
commit
1e601f6c02
@ -41,25 +41,23 @@ namespace NewHorizons.Builder.ShipLog
|
||||
}
|
||||
}
|
||||
|
||||
if (flagAutoPositionUsed && flagManualPositionUsed)
|
||||
if(flagManualPositionUsed)
|
||||
{
|
||||
Logger.LogError("Can't mix manual and automatic layout of ship log map mode, skipping generation");
|
||||
return null;
|
||||
if (flagAutoPositionUsed && flagManualPositionUsed)
|
||||
Logger.LogWarning("Can't mix manual and automatic layout of ship log map mode, defaulting to manual");
|
||||
return ConstructMapModeManual(bodies, transformParent, greyScaleMaterial, currentNav, layer);
|
||||
}
|
||||
else if (flagAutoPositionUsed)
|
||||
{
|
||||
return ConstructMapModeAuto(bodies, transformParent, greyScaleMaterial, layer);
|
||||
}
|
||||
else if (flagManualPositionUsed)
|
||||
{
|
||||
return ConstructMapModeManual(bodies, transformParent, greyScaleMaterial, currentNav, layer);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static string GetAstroBodyShipLogName(string id)
|
||||
{
|
||||
return ShipLogHandler.GetConfigFromID(id)?.Config?.Name ?? id;
|
||||
return ShipLogHandler.GetNameFromAstroID(id) ?? id;
|
||||
}
|
||||
|
||||
private static GameObject CreateImage(GameObject nodeGO, IModAssets assets, string imagePath, string name, int layer)
|
||||
|
||||
@ -58,12 +58,14 @@ namespace NewHorizons.Builder.ShipLog
|
||||
}
|
||||
else
|
||||
{
|
||||
var entryIDs = new List<string>();
|
||||
foreach (XElement entryElement in astroBodyFile.DescendantsAndSelf("Entry"))
|
||||
{
|
||||
XElement curiosityName = entryElement.Element("Curiosity");
|
||||
XElement id = entryElement.Element("ID");
|
||||
if (curiosityName != null && id != null && _entryIdToRawName.ContainsKey(id.Value) == false)
|
||||
{
|
||||
entryIDs.Add(id.Value);
|
||||
_entryIdToRawName.Add(id.Value, curiosityName.Value);
|
||||
}
|
||||
foreach (XElement childEntryElement in entryElement.Elements("Entry"))
|
||||
@ -80,6 +82,7 @@ namespace NewHorizons.Builder.ShipLog
|
||||
{
|
||||
_entryIdToRawName.Add(childId.Value, childCuriosityName.Value);
|
||||
}
|
||||
entryIDs.Add(childId.Value);
|
||||
}
|
||||
AddTranslation(childEntryElement);
|
||||
}
|
||||
@ -88,7 +91,7 @@ namespace NewHorizons.Builder.ShipLog
|
||||
TextAsset newAsset = new TextAsset(astroBodyFile.ToString());
|
||||
List<TextAsset> newBodies = new List<TextAsset>(manager._shipLogXmlAssets) { newAsset };
|
||||
manager._shipLogXmlAssets = newBodies.ToArray();
|
||||
ShipLogHandler.AddConfig(astroBodyId.Value, body);
|
||||
ShipLogHandler.AddConfig(astroBodyId.Value, entryIDs, body);
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,7 +104,7 @@ namespace NewHorizons.Builder.ShipLog
|
||||
{
|
||||
if (manager._entryDataDict.ContainsKey(entry._id) == false)
|
||||
{
|
||||
NewHorizonsBody body = ShipLogHandler.GetConfigFromID(entry._astroObjectID);
|
||||
NewHorizonsBody body = ShipLogHandler.GetConfigFromEntryID(entry._id);
|
||||
Vector2? manualEntryPosition = GetManualEntryPosition(entry._id, body.Config.ShipLog);
|
||||
Vector2 entryPosition;
|
||||
if (manualEntryPosition == null)
|
||||
|
||||
@ -16,12 +16,22 @@ namespace NewHorizons.Builder.Handlers
|
||||
{
|
||||
public static readonly string PAN_ROOT_PATH = "Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/MapMode/ScaleRoot/PanRoot";
|
||||
|
||||
private static Dictionary<string, List<NewHorizonsBody>> _astroIdToBodies = new Dictionary<string, List<NewHorizonsBody>>();
|
||||
// NewHorizonsBody -> EntryIDs
|
||||
private static Dictionary<NewHorizonsBody, List<string>> _nhBodyToEntryIDs;
|
||||
//EntryID -> NewHorizonsBody
|
||||
private static Dictionary<string, NewHorizonsBody> _entryIDsToNHBody;
|
||||
// NewHorizonsBody -> AstroID
|
||||
private static Dictionary<NewHorizonsBody, string> _nhBodyToAstroIDs;
|
||||
|
||||
private static string[] vanillaBodies;
|
||||
private static string[] vanillaIDs;
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
_nhBodyToEntryIDs = new Dictionary<NewHorizonsBody, List<string>>();
|
||||
_entryIDsToNHBody = new Dictionary<string, NewHorizonsBody>();
|
||||
_nhBodyToAstroIDs = new Dictionary<NewHorizonsBody, string>();
|
||||
|
||||
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();
|
||||
@ -41,42 +51,48 @@ namespace NewHorizons.Builder.Handlers
|
||||
return vanillaBodies.Contains(body.Config.Name.Replace(" ", ""));
|
||||
}
|
||||
|
||||
public static NewHorizonsBody GetConfigFromID(string id)
|
||||
public static string GetNameFromAstroID(string astroID)
|
||||
{
|
||||
return _astroIdToBodies.ContainsKey(id) ? _astroIdToBodies[id][0] : null;
|
||||
return CollectionUtilities.KeyByValue(_nhBodyToAstroIDs, astroID)?.Config.Name;
|
||||
}
|
||||
|
||||
public static void AddConfig(string id, NewHorizonsBody body)
|
||||
public static NewHorizonsBody GetConfigFromEntryID(string entryID)
|
||||
{
|
||||
if (!_astroIdToBodies.ContainsKey(id))
|
||||
{
|
||||
_astroIdToBodies.Add(id, new List<NewHorizonsBody>() { body });
|
||||
}
|
||||
if (_entryIDsToNHBody.ContainsKey(entryID)) return _entryIDsToNHBody[entryID];
|
||||
else
|
||||
{
|
||||
if(!_astroIdToBodies[id].Contains(body))
|
||||
_astroIdToBodies[id].Append(body);
|
||||
Logger.LogError($"Couldn't find NewHorizonsBody that corresponds to {entryID}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddConfig(string astroID, List<string> entryIDs, NewHorizonsBody body)
|
||||
{
|
||||
// Nice to be able to just get the AstroID from the body
|
||||
if (!_nhBodyToEntryIDs.ContainsKey(body)) _nhBodyToEntryIDs.Add(body, entryIDs);
|
||||
else Logger.LogWarning($"Possible duplicate shiplog entry {body.Config.Name}");
|
||||
|
||||
// AstroID
|
||||
if (!_nhBodyToAstroIDs.ContainsKey(body)) _nhBodyToAstroIDs.Add(body, astroID);
|
||||
else Logger.LogWarning($"Possible duplicate shiplog entry {astroID} for {body.Config.Name}");
|
||||
|
||||
// EntryID to Body
|
||||
foreach (var entryID in entryIDs)
|
||||
{
|
||||
if (!_entryIDsToNHBody.ContainsKey(entryID)) _entryIDsToNHBody.Add(entryID, body);
|
||||
else Logger.LogWarning($"Possible duplicate shiplog entry {entryID} for {astroID} from NewHorizonsBody {body.Config.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetAstroObjectId(NewHorizonsBody body)
|
||||
{
|
||||
foreach(var id in _astroIdToBodies.Keys)
|
||||
{
|
||||
if (_astroIdToBodies[id].Contains(body)) return id;
|
||||
}
|
||||
|
||||
return body.Config.Name;
|
||||
if (_nhBodyToAstroIDs.ContainsKey(body)) return _nhBodyToAstroIDs[body];
|
||||
else return body.Config.Name;
|
||||
}
|
||||
|
||||
public static bool BodyHasEntries(NewHorizonsBody body)
|
||||
{
|
||||
foreach(var id in _astroIdToBodies.Keys)
|
||||
{
|
||||
if (_astroIdToBodies[id].Contains(body)) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return _nhBodyToAstroIDs.ContainsKey(body) && _nhBodyToAstroIDs[body].Length > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,21 +14,13 @@ using NewHorizons.Utility;
|
||||
using OWML.Common;
|
||||
using OWML.ModHelper;
|
||||
using OWML.Utils;
|
||||
using PacificEngine.OW_CommonResources.Game.Player;
|
||||
using PacificEngine.OW_CommonResources.Game.Resource;
|
||||
using PacificEngine.OW_CommonResources.Game.State;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Epic.OnlineServices;
|
||||
using PacificEngine.OW_CommonResources.Game.Player;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
using Logger = NewHorizons.Utility.Logger;
|
||||
using NewHorizons.Handlers;
|
||||
|
||||
namespace NewHorizons
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user