blob: edfba736a611738aeb5d55afadc74f5a8368b7a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Buildings;
using StardewValley.Objects;
using StardewValley.TerrainFeatures;
namespace StardewModdingAPI.Framework.StateTracking.Snapshots
{
/// <summary>A frozen snapshot of a tracked game location.</summary>
internal class LocationSnapshot
{
/*********
** Accessors
*********/
/// <summary>The tracked location.</summary>
public GameLocation Location { get; }
/// <summary>Tracks added or removed buildings.</summary>
public SnapshotListDiff<Building> Buildings { get; } = new SnapshotListDiff<Building>();
/// <summary>Tracks added or removed debris.</summary>
public SnapshotListDiff<Debris> Debris { get; } = new SnapshotListDiff<Debris>();
/// <summary>Tracks added or removed large terrain features.</summary>
public SnapshotListDiff<LargeTerrainFeature> LargeTerrainFeatures { get; } = new SnapshotListDiff<LargeTerrainFeature>();
/// <summary>Tracks added or removed NPCs.</summary>
public SnapshotListDiff<NPC> Npcs { get; } = new SnapshotListDiff<NPC>();
/// <summary>Tracks added or removed objects.</summary>
public SnapshotListDiff<KeyValuePair<Vector2, Object>> Objects { get; } = new SnapshotListDiff<KeyValuePair<Vector2, Object>>();
/// <summary>Tracks added or removed terrain features.</summary>
public SnapshotListDiff<KeyValuePair<Vector2, TerrainFeature>> TerrainFeatures { get; } = new SnapshotListDiff<KeyValuePair<Vector2, TerrainFeature>>();
/// <summary>Tracks changed chest inventories.</summary>
public IDictionary<Chest, ItemStackChange[]> ChestItems { get; } = new Dictionary<Chest, ItemStackChange[]>();
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
/// <param name="location">The tracked location.</param>
public LocationSnapshot(GameLocation location)
{
this.Location = location;
}
/// <summary>Update the tracked values.</summary>
/// <param name="watcher">The watcher to snapshot.</param>
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);
// chest inventories
this.ChestItems.Clear();
foreach (ChestTracker tracker in watcher.ChestWatchers.Values)
{
ItemStackChange[] changes = tracker.GetInventoryChanges().ToArray();
if (changes.Length > 0)
this.ChestItems[tracker.Chest] = changes;
}
}
}
}
|