diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-11-24 13:49:30 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-11-24 13:49:30 -0500 |
commit | a3f21685049cabf2d824c8060dc0b1de47e9449e (patch) | |
tree | ad9add30e9da2a50e0ea0245f1546b7378f0d282 /src/SMAPI/Framework/SnapshotDiff.cs | |
parent | 6521df7b131924835eb797251c1e956fae0d6e13 (diff) | |
parent | 277bf082675b98b95bf6184fe3c7a45b969c7ac2 (diff) | |
download | SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.gz SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.bz2 SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/SnapshotDiff.cs')
-rw-r--r-- | src/SMAPI/Framework/SnapshotDiff.cs | 43 |
1 files changed, 43 insertions, 0 deletions
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 +{ + /// <summary>A snapshot of a tracked value.</summary> + /// <typeparam name="T">The tracked value type.</typeparam> + internal class SnapshotDiff<T> + { + /********* + ** Accessors + *********/ + /// <summary>Whether the value changed since the last update.</summary> + public bool IsChanged { get; private set; } + + /// <summary>The previous value.</summary> + public T Old { get; private set; } + + /// <summary>The current value.</summary> + public T New { get; private set; } + + + /********* + ** Public methods + *********/ + /// <summary>Update the snapshot.</summary> + /// <param name="isChanged">Whether the value changed since the last update.</param> + /// <param name="old">The previous value.</param> + /// <param name="now">The current value.</param> + public void Update(bool isChanged, T old, T now) + { + this.IsChanged = isChanged; + this.Old = old; + this.New = now; + } + + /// <summary>Update the snapshot.</summary> + /// <param name="watcher">The value watcher to snapshot.</param> + public void Update(IValueWatcher<T> watcher) + { + this.Update(watcher.IsChanged, watcher.PreviousValue, watcher.CurrentValue); + } + } +} |