Account for going back and forth and yanking tons of items

This commit is contained in:
xen-42 2024-10-05 17:31:31 -04:00
parent 5ddcae3d15
commit fafb0a5df0

View File

@ -17,7 +17,7 @@ public static class HeldItemHandler
/// Dictionary of system name to item path
/// If we travel to multiple systems within a single loop, this will hold the items we move between systems
/// </summary>
private static Dictionary<string, string> _pathOfItemTakenFromSystem = new();
private static Dictionary<string, List<string>> _pathOfItemTakenFromSystem = new();
private static GameObject _currentlyHeldItem;
@ -86,7 +86,11 @@ public static class HeldItemHandler
// Track it so that when we return to this system we can delete the original
if (_trackedPaths.TryGetValue(_currentlyHeldItem, out var path))
{
_pathOfItemTakenFromSystem[Main.Instance.CurrentStarSystem] = path;
if (!_pathOfItemTakenFromSystem.ContainsKey(Main.Instance.CurrentStarSystem))
{
_pathOfItemTakenFromSystem[Main.Instance.CurrentStarSystem] = new();
}
_pathOfItemTakenFromSystem[Main.Instance.CurrentStarSystem].Add(path);
}
NHLogger.Log($"Scene unloaded, preserved inactive held item {_currentlyHeldItem.name}");
@ -101,7 +105,9 @@ public static class HeldItemHandler
private static void OnSystemReady(string _)
{
// If something was taken from this system during this life, remove it
if (_pathOfItemTakenFromSystem.TryGetValue(Main.Instance.CurrentStarSystem, out var path))
if (_pathOfItemTakenFromSystem.TryGetValue(Main.Instance.CurrentStarSystem, out var paths))
{
foreach (var path in paths)
{
NHLogger.Log($"Removing item that was taken from this system at {path}");
var item = SearchUtilities.Find(path)?.GetComponent<OWItem>();
@ -112,6 +118,7 @@ public static class HeldItemHandler
}
GameObject.Destroy(item.gameObject);
}
}
// Give whatever item we were previously holding
if (_currentlyHeldItem != null)