Me when line numbers

This commit is contained in:
Nick 2022-06-28 13:03:17 -04:00
parent 729b0297dc
commit 0e9fbab82a

View File

@ -1,151 +1,151 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
namespace NewHorizons.Utility namespace NewHorizons.Utility
{ {
public static class AstroObjectLocator public static class AstroObjectLocator
{ {
private static Dictionary<string, AstroObject> _customAstroObjectDictionary = new Dictionary<string, AstroObject>(); private static Dictionary<string, AstroObject> _customAstroObjectDictionary = new Dictionary<string, AstroObject>();
public static void Init() public static void Init()
{ {
_customAstroObjectDictionary = new Dictionary<string, AstroObject>(); _customAstroObjectDictionary = new Dictionary<string, AstroObject>();
foreach (AstroObject ao in GameObject.FindObjectsOfType<AstroObject>()) foreach (AstroObject ao in GameObject.FindObjectsOfType<AstroObject>())
{ {
// Ignore the sun station debris, we handle it as a child of the sun station // Ignore the sun station debris, we handle it as a child of the sun station
if (ao.gameObject.name == "SS_Debris_Body") continue; if (ao.gameObject.name == "SS_Debris_Body") continue;
RegisterCustomAstroObject(ao); RegisterCustomAstroObject(ao);
}
}
public static AstroObject GetAstroObject(string name, bool flag = false)
{
if (string.IsNullOrEmpty(name)) return null;
if (_customAstroObjectDictionary.ContainsKey(name))
{
return _customAstroObjectDictionary[name];
} }
}
// Else check stock names
var stringID = name.ToUpper().Replace(" ", "_").Replace("'", ""); public static AstroObject GetAstroObject(string name, bool flag = false)
if (stringID.Equals("ATTLEROCK")) stringID = "TIMBER_MOON"; {
if (stringID.Equals("HOLLOWS_LANTERN")) stringID = "VOLCANIC_MOON"; if (string.IsNullOrEmpty(name)) return null;
if (stringID.Equals("ASH_TWIN")) stringID = "TOWER_TWIN";
if (stringID.Equals("EMBER_TWIN")) stringID = "CAVE_TWIN"; if (_customAstroObjectDictionary.ContainsKey(name))
if (stringID.Equals("INTERLOPER")) stringID = "COMET"; {
return _customAstroObjectDictionary[name];
string key; }
if (stringID.ToUpper().Replace("_", "").Equals("MAPSATELLITE"))
{ // Else check stock names
key = AstroObject.Name.MapSatellite.ToString(); var stringID = name.ToUpper().Replace(" ", "_").Replace("'", "");
} if (stringID.Equals("ATTLEROCK")) stringID = "TIMBER_MOON";
else if (stringID.Equals("HOLLOWS_LANTERN")) stringID = "VOLCANIC_MOON";
{ if (stringID.Equals("ASH_TWIN")) stringID = "TOWER_TWIN";
key = AstroObject.StringIDToAstroObjectName(stringID).ToString(); if (stringID.Equals("EMBER_TWIN")) stringID = "CAVE_TWIN";
} if (stringID.Equals("INTERLOPER")) stringID = "COMET";
if (_customAstroObjectDictionary.ContainsKey(key)) string key;
{ if (stringID.ToUpper().Replace("_", "").Equals("MAPSATELLITE"))
return _customAstroObjectDictionary[key]; {
} key = AstroObject.Name.MapSatellite.ToString();
}
// Try again else
if (!flag) return GetAstroObject(name.Replace(" ", ""), true); {
key = AstroObject.StringIDToAstroObjectName(stringID).ToString();
return null; }
}
if (_customAstroObjectDictionary.ContainsKey(key))
public static void RegisterCustomAstroObject(AstroObject ao) {
{ return _customAstroObjectDictionary[key];
var key = ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString(); }
if (_customAstroObjectDictionary.Keys.Contains(key)) // Try again
{ if (!flag) return GetAstroObject(name.Replace(" ", ""), true);
Logger.LogWarning($"Registering duplicate [{ao.name}] as [{key}]");
_customAstroObjectDictionary[key] = ao; return null;
} }
else
{ public static void RegisterCustomAstroObject(AstroObject ao)
Logger.Log($"Registering [{ao.name}] as [{key}]"); {
_customAstroObjectDictionary.Add(key, ao); var key = ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString();
}
} if (_customAstroObjectDictionary.Keys.Contains(key))
{
public static void DeregisterCustomAstroObject(AstroObject ao) Logger.LogWarning($"Registering duplicate [{ao.name}] as [{key}]");
{ _customAstroObjectDictionary[key] = ao;
var key = ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString(); }
_customAstroObjectDictionary.Remove(key); else
} {
Logger.Log($"Registering [{ao.name}] as [{key}]");
public static AstroObject[] GetAllAstroObjects() _customAstroObjectDictionary.Add(key, ao);
{ }
return _customAstroObjectDictionary.Values.ToArray(); }
}
public static void DeregisterCustomAstroObject(AstroObject ao)
public static GameObject[] GetMoons(AstroObject primary) {
{ var key = ao._name == AstroObject.Name.CustomString ? ao.GetCustomName() : ao._name.ToString();
return _customAstroObjectDictionary.Values.Where(x => x._primaryBody == primary).Select(x => x.gameObject).ToArray(); _customAstroObjectDictionary.Remove(key);
} }
public static GameObject[] GetChildren(AstroObject primary) public static AstroObject[] GetAllAstroObjects()
{ {
if (primary == null) return new GameObject[0]; return _customAstroObjectDictionary.Values.ToArray();
}
var otherChildren = new List<GameObject>();
switch (primary._name) public static GameObject[] GetMoons(AstroObject primary)
{ {
case AstroObject.Name.TowerTwin: return _customAstroObjectDictionary.Values.Where(x => x._primaryBody == primary).Select(x => x.gameObject).ToArray();
otherChildren.Add(SearchUtilities.Find("TimeLoopRing_Body")); }
break;
case AstroObject.Name.ProbeCannon: public static GameObject[] GetChildren(AstroObject primary)
otherChildren.Add(SearchUtilities.Find("NomaiProbe_Body")); {
otherChildren.Add(SearchUtilities.Find("CannonMuzzle_Body")); if (primary == null) return new GameObject[0];
otherChildren.Add(SearchUtilities.Find("FakeCannonMuzzle_Body (1)"));
otherChildren.Add(SearchUtilities.Find("CannonBarrel_Body")); var otherChildren = new List<GameObject>();
otherChildren.Add(SearchUtilities.Find("FakeCannonBarrel_Body (1)")); switch (primary._name)
otherChildren.Add(SearchUtilities.Find("Debris_Body (1)")); {
break; case AstroObject.Name.TowerTwin:
case AstroObject.Name.GiantsDeep: otherChildren.Add(SearchUtilities.Find("TimeLoopRing_Body"));
otherChildren.Add(SearchUtilities.Find("BrambleIsland_Body")); break;
otherChildren.Add(SearchUtilities.Find("GabbroIsland_Body")); case AstroObject.Name.ProbeCannon:
otherChildren.Add(SearchUtilities.Find("QuantumIsland_Body")); otherChildren.Add(SearchUtilities.Find("NomaiProbe_Body"));
otherChildren.Add(SearchUtilities.Find("StatueIsland_Body")); otherChildren.Add(SearchUtilities.Find("CannonMuzzle_Body"));
otherChildren.Add(SearchUtilities.Find("ConstructionYardIsland_Body")); otherChildren.Add(SearchUtilities.Find("FakeCannonMuzzle_Body (1)"));
otherChildren.Add(SearchUtilities.Find("GabbroShip_Body")); otherChildren.Add(SearchUtilities.Find("CannonBarrel_Body"));
break; otherChildren.Add(SearchUtilities.Find("FakeCannonBarrel_Body (1)"));
case AstroObject.Name.WhiteHole: otherChildren.Add(SearchUtilities.Find("Debris_Body (1)"));
otherChildren.Add(SearchUtilities.Find("WhiteholeStation_Body")); break;
otherChildren.Add(SearchUtilities.Find("WhiteholeStationSuperstructure_Body")); case AstroObject.Name.GiantsDeep:
break; otherChildren.Add(SearchUtilities.Find("BrambleIsland_Body"));
case AstroObject.Name.TimberHearth: otherChildren.Add(SearchUtilities.Find("GabbroIsland_Body"));
otherChildren.Add(SearchUtilities.Find("MiningRig_Body")); otherChildren.Add(SearchUtilities.Find("QuantumIsland_Body"));
otherChildren.Add(SearchUtilities.Find("Ship_Body")); otherChildren.Add(SearchUtilities.Find("StatueIsland_Body"));
otherChildren.Add(SearchUtilities.Find("ModelRocket_Body")); otherChildren.Add(SearchUtilities.Find("ConstructionYardIsland_Body"));
break; otherChildren.Add(SearchUtilities.Find("GabbroShip_Body"));
case AstroObject.Name.DreamWorld: break;
otherChildren.Add(SearchUtilities.Find("BackRaft_Body")); case AstroObject.Name.WhiteHole:
otherChildren.Add(SearchUtilities.Find("SealRaft_Body")); otherChildren.Add(SearchUtilities.Find("WhiteholeStation_Body"));
break; otherChildren.Add(SearchUtilities.Find("WhiteholeStationSuperstructure_Body"));
case AstroObject.Name.MapSatellite: break;
otherChildren.Add(SearchUtilities.Find("HearthianRecorder_Body")); case AstroObject.Name.TimberHearth:
break; otherChildren.Add(SearchUtilities.Find("MiningRig_Body"));
// For some dumb reason the sun station doesn't use AstroObject.Name.SunStation otherChildren.Add(SearchUtilities.Find("Ship_Body"));
case AstroObject.Name.CustomString: otherChildren.Add(SearchUtilities.Find("ModelRocket_Body"));
if (primary._customName.Equals("Sun Station")) break;
{ case AstroObject.Name.DreamWorld:
// there are multiple debris with the same name otherChildren.Add(SearchUtilities.Find("BackRaft_Body"));
otherChildren.AddRange(Object.FindObjectsOfType<AstroObject>() otherChildren.Add(SearchUtilities.Find("SealRaft_Body"));
.Select(x => x.gameObject) break;
.Where(x => x.name == "SS_Debris_Body")); case AstroObject.Name.MapSatellite:
} otherChildren.Add(SearchUtilities.Find("HearthianRecorder_Body"));
break; break;
default: // For some dumb reason the sun station doesn't use AstroObject.Name.SunStation
break; case AstroObject.Name.CustomString:
} if (primary._customName.Equals("Sun Station"))
{
return otherChildren.ToArray(); // there are multiple debris with the same name
} otherChildren.AddRange(Object.FindObjectsOfType<AstroObject>()
} .Select(x => x.gameObject)
} .Where(x => x.name == "SS_Debris_Body"));
}
break;
default:
break;
}
return otherChildren.ToArray();
}
}
}