Merge pull request #206 from xen-42/fix-prop-placer-for-custom-planets

Fix prop placer for custom planets
This commit is contained in:
Ben C 2022-06-26 22:31:15 -04:00 committed by GitHub
commit e2272298d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 8 deletions

View File

@ -69,24 +69,26 @@ namespace NewHorizons.Utility
else else
{ {
Logger.Log($"Registering [{ao.name}] as [{key}]"); Logger.Log($"Registering [{ao.name}] as [{key}]");
_customAstroObjectDictionary.Add(key, ao); _customAstroObjectDictionary.Add(key, ao);
_customAstroObjectDictionary.Add(ao.name, ao);
} }
} }
public static void DeregisterCustomAstroObject(AstroObject ao) public static void DeregisterCustomAstroObject(AstroObject ao)
{ {
var key = ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString(); var key = ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString();
_customAstroObjectDictionary.Remove(key); _customAstroObjectDictionary.Remove(key);
_customAstroObjectDictionary.Remove(ao.name);
} }
public static AstroObject[] GetAllAstroObjects() public static AstroObject[] GetAllAstroObjects()
{ {
return _customAstroObjectDictionary.Values.ToArray(); return _customAstroObjectDictionary.Values.Distinct().ToArray();
} }
public static GameObject[] GetMoons(AstroObject primary) public static GameObject[] GetMoons(AstroObject primary)
{ {
return _customAstroObjectDictionary.Values.Where(x => x._primaryBody == primary).Select(x => x.gameObject).ToArray(); return _customAstroObjectDictionary.Values.Distinct().Where(x => x._primaryBody == primary).Select(x => x.gameObject).ToArray();
} }
public static GameObject[] GetChildren(AstroObject primary) public static GameObject[] GetChildren(AstroObject primary)

View File

@ -144,13 +144,10 @@ namespace NewHorizons.Utility.DebugUtilities
public static string GetAstroObjectName(string bodyName) public static string GetAstroObjectName(string bodyName)
{ {
if (bodyName.EndsWith("_Body")) bodyName = bodyName.Substring(0, bodyName.Length-"_Body".Length);
var astroObject = AstroObjectLocator.GetAstroObject(bodyName); var astroObject = AstroObjectLocator.GetAstroObject(bodyName);
if (astroObject == null) return null; if (astroObject == null) return null;
var astroObjectName = astroObject.name; var astroObjectName = astroObject.name;
if (astroObjectName.EndsWith("_Body")) astroObjectName = astroObjectName.Substring(0, astroObjectName.Length-"_Body".Length);
return astroObjectName; return astroObjectName;
} }
@ -202,7 +199,7 @@ namespace NewHorizons.Utility.DebugUtilities
string bodyName = GetAstroObjectName(bodyGameObjectName); string bodyName = GetAstroObjectName(bodyGameObjectName);
Logger.Log("Adding prop to " + Main.Instance.CurrentStarSystem + "::" + bodyName); Logger.Log($"Adding prop to {Main.Instance.CurrentStarSystem}::{bodyName} (passed name: {bodyGameObjectName})");
detailInfo = detailInfo == null ? new DetailInfo() : detailInfo; detailInfo = detailInfo == null ? new DetailInfo() : detailInfo;