blob: d659d2b4968700a5975be80d92406b76a508fca0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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);
}
}
}
|