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/SnapshotDiff.cs | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/SMAPI/Framework/SnapshotDiff.cs (limited to 'src/SMAPI/Framework/SnapshotDiff.cs') diff --git a/src/SMAPI/Framework/SnapshotDiff.cs b/src/SMAPI/Framework/SnapshotDiff.cs new file mode 100644 index 00000000..5b6288ff --- /dev/null +++ b/src/SMAPI/Framework/SnapshotDiff.cs @@ -0,0 +1,43 @@ +using StardewModdingAPI.Framework.StateTracking; + +namespace StardewModdingAPI.Framework +{ + /// A snapshot of a tracked value. + /// The tracked value type. + internal class SnapshotDiff + { + /********* + ** Accessors + *********/ + /// Whether the value changed since the last update. + public bool IsChanged { get; private set; } + + /// The previous value. + public T Old { get; private set; } + + /// The current value. + public T New { get; private set; } + + + /********* + ** Public methods + *********/ + /// Update the snapshot. + /// Whether the value changed since the last update. + /// The previous value. + /// The current value. + public void Update(bool isChanged, T old, T now) + { + this.IsChanged = isChanged; + this.Old = old; + this.New = now; + } + + /// Update the snapshot. + /// The value watcher to snapshot. + public void Update(IValueWatcher watcher) + { + this.Update(watcher.IsChanged, watcher.PreviousValue, watcher.CurrentValue); + } + } +} -- cgit