using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Netcode; using StardewModdingAPI.Framework.StateTracking.Comparers; namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers { /// Provides convenience wrappers for creating watchers. internal static class WatcherFactory { /********* ** Public methods *********/ /// Get a watcher for an value. /// The value type. /// Get the current value. public static ComparableWatcher ForEquatable(Func getValue) where T : IEquatable { return new ComparableWatcher(getValue, new EquatableComparer()); } /// Get a watcher which detects when an object reference changes. /// The value type. /// Get the current value. public static ComparableWatcher ForReference(Func getValue) { return new ComparableWatcher(getValue, new ObjectReferenceComparer()); } /// Get a watcher for an observable collection. /// The value type. /// The observable collection. public static ObservableCollectionWatcher ForObservableCollection(ObservableCollection collection) { return new ObservableCollectionWatcher(collection); } /// Get a watcher for a net dictionary. /// The dictionary key type. /// The dictionary value type. /// The net type equivalent to . /// The serializable dictionary type that can store the keys and values. /// The net field instance type. /// The net field. public static NetDictionaryWatcher ForNetDictionary(NetDictionary field) where TField : class, INetObject, new() where TSerialDict : IDictionary, new() where TSelf : NetDictionary { return new NetDictionaryWatcher(field); } } }