summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/StateTracking/Snapshots
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-29 13:29:25 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2019-12-31 16:19:50 -0500
commit1286a90ec2fb0dcf26bd59feec714544844e4398 (patch)
tree33d10b57442ff38daee9c975506a8ce1ea958f23 /src/SMAPI/Framework/StateTracking/Snapshots
parentaef1b8ac2898e147e6200fe257e8fdd82ee7fdbc (diff)
downloadSMAPI-1286a90ec2fb0dcf26bd59feec714544844e4398.tar.gz
SMAPI-1286a90ec2fb0dcf26bd59feec714544844e4398.tar.bz2
SMAPI-1286a90ec2fb0dcf26bd59feec714544844e4398.zip
minor refactoring
This commit... - removes key fields added to non-keyed types like NetListWatcher and SnapshotListDiff; - fixes existing chests not being watched; - fixes diffs not correctly updated for added/removed chests; - performs minor cleanup, adds missing docs, etc.
Diffstat (limited to 'src/SMAPI/Framework/StateTracking/Snapshots')
-rw-r--r--src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs b/src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs
index 31cf29c3..4074336b 100644
--- a/src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs
+++ b/src/SMAPI/Framework/StateTracking/Snapshots/LocationSnapshot.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
+using System.Linq;
using Microsoft.Xna.Framework;
using StardewValley;
using StardewValley.Buildings;
@@ -33,7 +34,8 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots
/// <summary>Tracks added or removed terrain features.</summary>
public SnapshotListDiff<KeyValuePair<Vector2, TerrainFeature>> TerrainFeatures { get; } = new SnapshotListDiff<KeyValuePair<Vector2, TerrainFeature>>();
- public SnapshotListDiff<Item> ChestItems { get; } = new SnapshotListDiff<Item>();
+ /// <summary>Tracks changed chest inventories.</summary>
+ public IDictionary<Vector2, SnapshotListDiff<Item>> ChestItems { get; } = new Dictionary<Vector2, SnapshotListDiff<Item>>();
/*********
@@ -50,6 +52,7 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots
/// <param name="watcher">The watcher to snapshot.</param>
public void Update(LocationTracker watcher)
{
+ // main lists
this.Buildings.Update(watcher.BuildingsWatcher);
this.Debris.Update(watcher.DebrisWatcher);
this.LargeTerrainFeatures.Update(watcher.LargeTerrainFeaturesWatcher);
@@ -57,8 +60,19 @@ namespace StardewModdingAPI.Framework.StateTracking.Snapshots
this.Objects.Update(watcher.ObjectsWatcher);
this.TerrainFeatures.Update(watcher.TerrainFeaturesWatcher);
- foreach (var obj in watcher.activeChestWatchers)
- this.ChestItems.Update(obj.Value, obj.Key);
+ // chest inventories
+ foreach (Vector2 key in this.ChestItems.Keys.ToArray())
+ {
+ if (!watcher.ChestWatchers.ContainsKey(key))
+ this.ChestItems.Remove(key);
+ }
+ foreach (var pair in watcher.ChestWatchers)
+ {
+ if (!this.ChestItems.TryGetValue(pair.Key, out var diff))
+ this.ChestItems[pair.Key] = diff = new SnapshotListDiff<Item>();
+
+ diff.Update(pair.Value);
+ }
}
}
}