From d3209b17de4e46ee1d604aac24642af80ce855cc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 14 Jun 2019 01:16:50 -0400 Subject: decouple updating watchers & raising event to fix some mod changes not being tracked correctly (#648) --- src/SMAPI/Framework/SnapshotListDiff.cs | 58 +++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/SMAPI/Framework/SnapshotListDiff.cs (limited to 'src/SMAPI/Framework/SnapshotListDiff.cs') diff --git a/src/SMAPI/Framework/SnapshotListDiff.cs b/src/SMAPI/Framework/SnapshotListDiff.cs new file mode 100644 index 00000000..d4d5df50 --- /dev/null +++ b/src/SMAPI/Framework/SnapshotListDiff.cs @@ -0,0 +1,58 @@ +using System.Collections.Generic; +using StardewModdingAPI.Framework.StateTracking; + +namespace StardewModdingAPI.Framework +{ + /// A snapshot of a tracked list. + /// The tracked list value type. + internal class SnapshotListDiff + { + /********* + ** Fields + *********/ + /// The removed values. + private readonly List RemovedImpl = new List(); + + /// The added values. + private readonly List AddedImpl = new List(); + + + /********* + ** Accessors + *********/ + /// Whether the value changed since the last update. + public bool IsChanged { get; private set; } + + /// The removed values. + public IEnumerable Removed => this.RemovedImpl; + + /// The added values. + public IEnumerable Added => this.AddedImpl; + + + /********* + ** Public methods + *********/ + /// Update the snapshot. + /// Whether the value changed since the last update. + /// The removed values. + /// The added values. + public void Update(bool isChanged, IEnumerable removed, IEnumerable added) + { + this.IsChanged = isChanged; + + this.RemovedImpl.Clear(); + this.RemovedImpl.AddRange(removed); + + this.AddedImpl.Clear(); + this.AddedImpl.AddRange(added); + } + + /// Update the snapshot. + /// The value watcher to snapshot. + public void Update(ICollectionWatcher watcher) + { + this.Update(watcher.IsChanged, watcher.Removed, watcher.Added); + } + } +} -- cgit