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 which compares values using their method. This method should only be used when won't work, since this doesn't validate whether they're comparable. /// The value type. /// Get the current value. public static ComparableWatcher ForGenericEquality(Func getValue) where T : struct { return new ComparableWatcher(getValue, new GenericEqualsComparer()); } /// 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 collection. /// The value type. /// The net field instance type. /// The net collection. public static NetValueWatcher ForNetValue(NetFieldBase field) where TSelf : NetFieldBase { return new NetValueWatcher(field); } /// Get a watcher for a net collection. /// The value type. /// The net collection. public static NetCollectionWatcher ForNetCollection(NetCollection collection) where T : class, INetObject { return new NetCollectionWatcher(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); } } }