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 *********/ /**** ** Values ****/ /// 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 IValueWatcher 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 IValueWatcher 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 IValueWatcher ForReference(Func getValue) { return new ComparableWatcher(getValue, new ObjectReferenceComparer()); } /// Get a watcher for a net collection. /// The value type. /// The net field instance type. /// The net collection. public static IValueWatcher ForNetValue(NetFieldBase field) where TSelf : NetFieldBase { return new NetValueWatcher(field); } /**** ** Collections ****/ /// Get a watcher which detects when an object reference in a collection changes. /// The value type. /// The observable collection. public static ICollectionWatcher ForReferenceList(ICollection collection) { return new ComparableListWatcher(collection, new ObjectReferenceComparer()); } /// Get a watcher for an observable collection. /// The value type. /// The observable collection. public static ICollectionWatcher ForObservableCollection(ObservableCollection collection) { return new ObservableCollectionWatcher(collection); } /// Get a watcher for a collection that never changes. /// The value type. public static ICollectionWatcher ForImmutableCollection() { return ImmutableCollectionWatcher.Instance; } /// Get a watcher for a net collection. /// The value type. /// The net collection. public static ICollectionWatcher 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); } } }