diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-05-04 20:44:20 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2018-05-04 20:44:20 -0400 |
commit | 8051862c7bd2fe498657eef4bb102b5ca33390a6 (patch) | |
tree | c877a63aef6fd987adb1a4da727ae233d1978121 /src/SMAPI/Framework/StateTracking/LocationTracker.cs | |
parent | 05f81cb85f09c8e82ea125f520e4a264abfc3869 (diff) | |
download | SMAPI-8051862c7bd2fe498657eef4bb102b5ca33390a6.tar.gz SMAPI-8051862c7bd2fe498657eef4bb102b5ca33390a6.tar.bz2 SMAPI-8051862c7bd2fe498657eef4bb102b5ca33390a6.zip |
add LocationEvents.ObjectsChanged event
Diffstat (limited to 'src/SMAPI/Framework/StateTracking/LocationTracker.cs')
-rw-r--r-- | src/SMAPI/Framework/StateTracking/LocationTracker.cs | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/StateTracking/LocationTracker.cs b/src/SMAPI/Framework/StateTracking/LocationTracker.cs new file mode 100644 index 00000000..8cf4e7a2 --- /dev/null +++ b/src/SMAPI/Framework/StateTracking/LocationTracker.cs @@ -0,0 +1,71 @@ +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using StardewModdingAPI.Framework.StateTracking.FieldWatchers; +using StardewValley; +using Object = StardewValley.Object; + +namespace StardewModdingAPI.Framework.StateTracking +{ + /// <summary>Tracks changes to a location's data.</summary> + internal class LocationTracker : IWatcher + { + /********* + ** Properties + *********/ + /// <summary>The underlying watchers.</summary> + private readonly List<IWatcher> Watchers = new List<IWatcher>(); + + + /********* + ** Accessors + *********/ + /// <summary>Whether the value changed since the last reset.</summary> + public bool IsChanged => this.Watchers.Any(p => p.IsChanged); + + /// <summary>The tracked location.</summary> + public GameLocation Location { get; } + + /// <summary>Tracks changes to the current location's objects.</summary> + public IDictionaryWatcher<Vector2, Object> LocationObjectsWatcher { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="location">The location to track.</param> + public LocationTracker(GameLocation location) + { + this.Location = location; + + // init watchers + this.LocationObjectsWatcher = WatcherFactory.ForNetDictionary(location.netObjects); + this.Watchers.AddRange(new[] + { + this.LocationObjectsWatcher + }); + } + + /// <summary>Stop watching the player fields and release all references.</summary> + public void Dispose() + { + foreach (IWatcher watcher in this.Watchers) + watcher.Dispose(); + } + + /// <summary>Update the current value if needed.</summary> + public void Update() + { + foreach (IWatcher watcher in this.Watchers) + watcher.Update(); + } + + /// <summary>Set the current value as the baseline.</summary> + public void Reset() + { + foreach (IWatcher watcher in this.Watchers) + watcher.Reset(); + } + } +} |