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();
/// The added values.
private readonly List AddedImpl = new();
/*********
** 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();
if (removed != null)
this.RemovedImpl.AddRange(removed);
this.AddedImpl.Clear();
if (added != null)
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);
}
}
}