#nullable disable using System.Collections.Generic; using Microsoft.Xna.Framework; using StardewValley; using StardewValley.Buildings; using StardewValley.Objects; using StardewValley.TerrainFeatures; namespace StardewModdingAPI.Framework.StateTracking.Snapshots { /// A frozen snapshot of a tracked game location. internal class LocationSnapshot { /********* ** Accessors *********/ /// The tracked location. public GameLocation Location { get; } /// Tracks added or removed buildings. public SnapshotListDiff Buildings { get; } = new(); /// Tracks added or removed debris. public SnapshotListDiff Debris { get; } = new(); /// Tracks added or removed large terrain features. public SnapshotListDiff LargeTerrainFeatures { get; } = new(); /// Tracks added or removed NPCs. public SnapshotListDiff Npcs { get; } = new(); /// Tracks added or removed objects. public SnapshotListDiff> Objects { get; } = new(); /// Tracks added or removed terrain features. public SnapshotListDiff> TerrainFeatures { get; } = new(); /// Tracks added or removed furniture. public SnapshotListDiff Furniture { get; } = new(); /// Tracks changed chest inventories. public IDictionary ChestItems { get; } = new Dictionary(); /********* ** Public methods *********/ /// Construct an instance. /// The tracked location. public LocationSnapshot(GameLocation location) { this.Location = location; } /// Update the tracked values. /// The watcher to snapshot. public void Update(LocationTracker watcher) { // main lists this.Buildings.Update(watcher.BuildingsWatcher); this.Debris.Update(watcher.DebrisWatcher); this.LargeTerrainFeatures.Update(watcher.LargeTerrainFeaturesWatcher); this.Npcs.Update(watcher.NpcsWatcher); this.Objects.Update(watcher.ObjectsWatcher); this.TerrainFeatures.Update(watcher.TerrainFeaturesWatcher); this.Furniture.Update(watcher.FurnitureWatcher); // chest inventories this.ChestItems.Clear(); foreach (ChestTracker tracker in watcher.ChestWatchers.Values) { if (tracker.TryGetInventoryChanges(out SnapshotItemListDiff changes)) this.ChestItems[tracker.Chest] = changes; } } } }