Skip to content

Commit

Permalink
Merge pull request stokastic#2 from ZaneYork/update-code
Browse files Browse the repository at this point in the history
Fix for Android(work only once bug)
  • Loading branch information
Pathoschild committed Apr 16, 2020
2 parents 6ee0408 + 66b5a38 commit 8cffde6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
26 changes: 13 additions & 13 deletions DeluxeGrabber/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e) {
continue;
}

if ((grabber.heldObject.Value as Chest).items.Count >= Chest.capacity) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity) {
return;
}

Expand Down Expand Up @@ -119,7 +119,7 @@ private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e) {
}
}

if ((grabber.heldObject.Value as Chest).items.Count > 0) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
Expand Down Expand Up @@ -174,7 +174,7 @@ private void AutograbBuildings() {
bool full = false;
foreach (Vector2 tile in grabbables) {

if ((grabber.heldObject.Value as Chest).items.Count >= Chest.capacity) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity) {
Monitor.Log($" Grabber is full", LogLevel.Trace);
full = true;
break;
Expand Down Expand Up @@ -218,7 +218,7 @@ private void AutograbBuildings() {
}

// update sprite if grabber has items in it
if (grabber != null && (grabber.heldObject.Value as Chest).items.Count > 0) {
if (grabber != null && (grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
Expand All @@ -235,10 +235,10 @@ private void AutograbCrops() {
foreach (KeyValuePair<Vector2, SObject> pair in location.Objects.Pairs) {
if (pair.Value.Name.Contains("Grabber")) {
SObject grabber = pair.Value;
if ((grabber.heldObject.Value == null) || (grabber.heldObject.Value as Chest).items.Count >= Chest.capacity) {
if ((grabber.heldObject.Value == null) || (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity) {
continue;
}
bool full = (grabber.heldObject.Value as Chest).items.Count >= Chest.capacity;
bool full = (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity;
for (int x = (int)pair.Key.X - range; x < pair.Key.X + range + 1; x ++) {
for (int y = (int)pair.Key.Y - range; y < pair.Key.Y + range + 1 && !full; y++) {
Vector2 tile = new Vector2(x, y);
Expand Down Expand Up @@ -278,10 +278,10 @@ private void AutograbCrops() {
}
}
}
full = (grabber.heldObject.Value as Chest).items.Count >= Chest.capacity;
full = (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity;
}
}
if (grabber != null && (grabber.heldObject.Value as Chest).items.Count > 0) {
if (grabber != null && (grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
Expand Down Expand Up @@ -440,7 +440,7 @@ private void AutograbWorld() {
if (location.Name.Equals("Forest")) {
foreach (TerrainFeature feature in location.terrainFeatures.Values) {

if ((grabber.heldObject.Value as Chest).items.Count >= Chest.capacity) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
Expand Down Expand Up @@ -498,7 +498,7 @@ private void AutograbWorld() {
break;
}

if ((grabber.heldObject.Value as Chest).items.Count >= Chest.capacity) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
Expand Down Expand Up @@ -528,7 +528,7 @@ private void AutograbWorld() {
// add items to grabber and remove from floor
foreach (Vector2 tile in grabbables) {

if ((grabber.heldObject.Value as Chest).items.Count >= Chest.capacity) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
Expand Down Expand Up @@ -571,7 +571,7 @@ private void AutograbWorld() {
foreach (SObject obj in location.Objects.Values)
{

if ((grabber.heldObject.Value as Chest).items.Count >= Chest.capacity)
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= Chest.capacity)
{
Monitor.Log("Global grabber full", LogLevel.Info);
return;
Expand Down Expand Up @@ -604,7 +604,7 @@ private void AutograbWorld() {
Monitor.Log($" {location} - found {pair.Value} {pair.Key}{plural}", LogLevel.Trace);
}

if ((grabber.heldObject.Value as Chest).items.Count > 0) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
Expand Down
13 changes: 13 additions & 0 deletions DeluxeGrabber/NetListExtend.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Netcode;
using System.Linq;

namespace DeluxeGrabber
{
public static class NetListExtend
{
public static int CountIgnoreNull<T>(this NetObjectList<T> list) where T : class, INetObject<INetSerializable>
{
return list.Count(item => item != null);
}
}
}

0 comments on commit 8cffde6

Please sign in to comment.