diff --git a/Winch/Util/PoiUtil.cs b/Winch/Util/PoiUtil.cs index 774cc412..4977cc97 100644 --- a/Winch/Util/PoiUtil.cs +++ b/Winch/Util/PoiUtil.cs @@ -39,10 +39,25 @@ internal static bool PopulateObjectFromMetaWithConverters(T item, Dictionary< internal static Dictionary ModdedPOIDict = new(); internal static Dictionary CreatedModdedPOIDict = new(); + internal static Dictionary AllPOIDict = new(); internal static Dictionary Harvestables = new(); internal static Dictionary HarvestParticlePrefabs = new(); internal static Dictionary ModdedHarvestParticlePrefabs = new(); + public static POI GetPOI(string id) + { + if (string.IsNullOrWhiteSpace(id)) + return null; + + if (AllPOIDict.TryGetValue(id, out POI poi)) + return poi; + + if (CreatedModdedPOIDict.TryGetValue(id, out POI moddedPoi)) + return moddedPoi; + + return null; + } + public static CustomPOI GetModdedPOI(string id) { if (string.IsNullOrWhiteSpace(id)) @@ -88,12 +103,24 @@ internal static void Populate() WinchCore.Log.Debug($"Added particle {name} to HarvestParticlePrefabs"); } } + foreach (var dockPoi in Resources.FindObjectsOfTypeAll()) + { + AllPOIDict.Add(dockPoi.dock.Data.Id, dockPoi); + WinchCore.Log.Debug($"Added POI {dockPoi.dock.Data.Id} to AllPOIDict"); + } + foreach (var conversationPoi in Resources.FindObjectsOfTypeAll()) + { + var id = conversationPoi is ExplosivePOI explosivePoi ? explosivePoi.id : conversationPoi.name.Replace("_Inspect", ""); + AllPOIDict.Add(id, conversationPoi); + WinchCore.Log.Debug($"Added POI {id} to AllPOIDict"); + } foreach (var harvestPoi in GameManager.Instance.HarvestPOIManager.allHarvestPOIs) { try { - if (!Harvestables.ContainsKey(harvestPoi.Harvestable.GetId())) - Harvestables.Add(harvestPoi.Harvestable.GetId(), harvestPoi.Harvestable); + AllPOIDict.SafeAdd(harvestPoi.Harvestable.GetId(), harvestPoi); + WinchCore.Log.Debug($"Added POI \"{harvestPoi.name}\" to AllPOIDict"); + Harvestables.SafeAdd(harvestPoi.Harvestable.GetId(), harvestPoi.Harvestable); var prefab = harvestPoi.Harvestable.GetParticlePrefab(); var name = prefab.name.RemoveClone(); if (!HarvestParticlePrefabs.ContainsKey(name)) @@ -112,8 +139,9 @@ internal static void Populate() { try { - if (!Harvestables.ContainsKey(itemPoi.Harvestable.GetId())) - Harvestables.Add(itemPoi.Harvestable.GetId(), itemPoi.Harvestable); + AllPOIDict.SafeAdd(itemPoi.Harvestable.GetId(), itemPoi); + WinchCore.Log.Debug($"Added POI \"{itemPoi.name}\" to AllPOIDict"); + Harvestables.SafeAdd(itemPoi.Harvestable.GetId(), itemPoi.Harvestable); var prefab = itemPoi.Harvestable.GetParticlePrefab(); var name = prefab.name.RemoveClone(); if (!HarvestParticlePrefabs.ContainsKey(name)) @@ -133,6 +161,7 @@ internal static void Populate() internal static void Clear() { CreatedModdedPOIDict.Clear(); + AllPOIDict.Clear(); Harvestables.Clear(); HarvestParticlePrefabs.Clear(); } @@ -422,6 +451,7 @@ internal static (GameObject, T) CreateGenericPoiFromCustomPoi(CustomPOI custo customPoiObject.transform.position = customPoi.location; var poi = customPoiObject.AddComponent(); CreatedModdedPOIDict.Add(customPoi.id, poi); + WinchCore.Log.Debug($"Added POI {customPoi.id} to CreatedModdedPOIDict"); poi.canBeGhostWindTarget = customPoi.canBeGhostWindTarget; @@ -482,6 +512,11 @@ internal static void AddCustomPoiFromMeta(string metaPath) where T : CustomPO } } + public static IReadOnlyDictionary GetAllPOI() + { + return AllPOIDict.Concat(CreatedModdedPOIDict).ToDictionary(kvp => kvp.Key, kvp => kvp.Value); + } + public static IHarvestable[] GetAllHarvestables() { return Harvestables.Values.ToArray();