Skip to content

Commit

Permalink
Fixed bug with tracking new lockers built after the resource monitor …
Browse files Browse the repository at this point in the history
…has been built.
  • Loading branch information
brett-taylor committed Dec 26, 2018
1 parent 32c2215 commit 7e45281
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions ResourceMonitor/Components/ResourceMonitorLogic.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace ResourceMonitor
Expand Down Expand Up @@ -44,7 +45,7 @@ private void TurnOn()
rmd = gameObject.AddComponent<ResourceMonitorDisplay>();
rmd.Setup(gameObject.transform, this);

Patchers.BuilderPatcher.OnStorageContainedAdded += TrackNewlyPlacedStorageContainer;
Patchers.BuilderPatcher.OnStorageContainedAdded += AlertedNewStorageContainerPlaced;
}

private void TurnOff()
Expand All @@ -63,14 +64,23 @@ private void TrackExistingStorageContainers()
}
}

public void TrackNewlyPlacedStorageContainer(StorageContainer sc)
public void AlertedNewStorageContainerPlaced(StorageContainer sc)
{
GameObject newSeaBase = gameObject?.transform?.parent?.gameObject;
StartCoroutine("TrackNewStorageContainerCoroutine", sc);
}

public IEnumerator TrackNewStorageContainerCoroutine(StorageContainer sc)
{
// We yield to the end of the frame as we need the parent/children tree to update.
yield return new WaitForEndOfFrame();

GameObject newSeaBase = sc?.gameObject?.transform?.parent?.gameObject;
if (newSeaBase != null && newSeaBase == seaBase)
{
ErrorMessage.AddMessage("New StorageContainer tracked v2");
TrackStorageContainer(sc);
}

StopCoroutine("TrackNewStorageContainerCoroutine");
}

private void TrackStorageContainer(StorageContainer sc)
Expand Down
2 changes: 1 addition & 1 deletion ResourceMonitor/Patchers/BuilderPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace ResourceMonitor.Patchers
{
/**
* Patches into the Builder's Awake() method to alert our Resource monitor about the newly placed storage container - if it was a newly placed storage container.
* Patches into StorageContainer::Awake method to alert our Resource monitor about the newly placed storage container
*/
[HarmonyPatch(typeof(StorageContainer))]
[HarmonyPatch("Awake")]
Expand Down

0 comments on commit 7e45281

Please sign in to comment.