diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-11-24 13:49:30 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-11-24 13:49:30 -0500 |
commit | a3f21685049cabf2d824c8060dc0b1de47e9449e (patch) | |
tree | ad9add30e9da2a50e0ea0245f1546b7378f0d282 /src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs | |
parent | 6521df7b131924835eb797251c1e956fae0d6e13 (diff) | |
parent | 277bf082675b98b95bf6184fe3c7a45b969c7ac2 (diff) | |
download | SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.gz SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.tar.bz2 SMAPI-a3f21685049cabf2d824c8060dc0b1de47e9449e.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs')
-rw-r--r-- | src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs b/src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs new file mode 100644 index 00000000..7bcd9f82 --- /dev/null +++ b/src/SMAPI/Framework/StateTracking/Snapshots/PlayerSnapshot.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StardewModdingAPI.Enums; +using StardewModdingAPI.Events; +using StardewValley; + +namespace StardewModdingAPI.Framework.StateTracking.Snapshots +{ + /// <summary>A frozen snapshot of a tracked player.</summary> + internal class PlayerSnapshot + { + /********* + ** Accessors + *********/ + /// <summary>The player being tracked.</summary> + public Farmer Player { get; } + + /// <summary>The player's current location.</summary> + public SnapshotDiff<GameLocation> Location { get; } = new SnapshotDiff<GameLocation>(); + + /// <summary>Tracks changes to the player's skill levels.</summary> + public IDictionary<SkillType, SnapshotDiff<int>> Skills { get; } = + Enum + .GetValues(typeof(SkillType)) + .Cast<SkillType>() + .ToDictionary(skill => skill, skill => new SnapshotDiff<int>()); + + /// <summary>Get a list of inventory changes.</summary> + public IEnumerable<ItemStackChange> InventoryChanges { get; private set; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="player">The player being tracked.</param> + public PlayerSnapshot(Farmer player) + { + this.Player = player; + } + + /// <summary>Update the tracked values.</summary> + /// <param name="watcher">The player watcher to snapshot.</param> + public void Update(PlayerTracker watcher) + { + this.Location.Update(watcher.LocationWatcher); + foreach (var pair in this.Skills) + pair.Value.Update(watcher.SkillWatchers[pair.Key]); + this.InventoryChanges = watcher.GetInventoryChanges().ToArray(); + } + } +} |