Skip to content

Commit

Permalink
AllPOIDict
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Sep 11, 2024
1 parent 2ed3b6b commit 41ec2f8
Showing 1 changed file with 39 additions and 4 deletions.
43 changes: 39 additions & 4 deletions Winch/Util/PoiUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,25 @@ internal static bool PopulateObjectFromMetaWithConverters<T>(T item, Dictionary<

internal static Dictionary<string, CustomPOI> ModdedPOIDict = new();
internal static Dictionary<string, POI> CreatedModdedPOIDict = new();
internal static Dictionary<string, POI> AllPOIDict = new();
internal static Dictionary<string, IHarvestable> Harvestables = new();
internal static Dictionary<string, GameObject> HarvestParticlePrefabs = new();
internal static Dictionary<string, GameObject> 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))
Expand Down Expand Up @@ -88,12 +103,24 @@ internal static void Populate()
WinchCore.Log.Debug($"Added particle {name} to HarvestParticlePrefabs");
}
}
foreach (var dockPoi in Resources.FindObjectsOfTypeAll<DockPOI>())
{
AllPOIDict.Add(dockPoi.dock.Data.Id, dockPoi);
WinchCore.Log.Debug($"Added POI {dockPoi.dock.Data.Id} to AllPOIDict");
}
foreach (var conversationPoi in Resources.FindObjectsOfTypeAll<ConversationPOI>())
{
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))
Expand All @@ -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))
Expand All @@ -133,6 +161,7 @@ internal static void Populate()
internal static void Clear()
{
CreatedModdedPOIDict.Clear();
AllPOIDict.Clear();
Harvestables.Clear();
HarvestParticlePrefabs.Clear();
}
Expand Down Expand Up @@ -422,6 +451,7 @@ internal static (GameObject, T) CreateGenericPoiFromCustomPoi<T>(CustomPOI custo
customPoiObject.transform.position = customPoi.location;
var poi = customPoiObject.AddComponent<T>();
CreatedModdedPOIDict.Add(customPoi.id, poi);
WinchCore.Log.Debug($"Added POI {customPoi.id} to CreatedModdedPOIDict");

poi.canBeGhostWindTarget = customPoi.canBeGhostWindTarget;

Expand Down Expand Up @@ -482,6 +512,11 @@ internal static void AddCustomPoiFromMeta<T>(string metaPath) where T : CustomPO
}
}

public static IReadOnlyDictionary<string, POI> GetAllPOI()
{
return AllPOIDict.Concat(CreatedModdedPOIDict).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
}

public static IHarvestable[] GetAllHarvestables()
{
return Harvestables.Values.ToArray();
Expand Down

0 comments on commit 41ec2f8

Please sign in to comment.