summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/StateTracking/Snapshots/WatcherSnapshot.cs
blob: 27a891deb1a56db35589c33360780c2560491c2e (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
using Microsoft.Xna.Framework;
using StardewValley;
using StardewValley.Menus;

namespace StardewModdingAPI.Framework.StateTracking.Snapshots
{
    /// <summary>A frozen snapshot of the game state watchers.</summary>
    internal class WatcherSnapshot
    {
        /*********
        ** Accessors
        *********/
        /// <summary>Tracks changes to the window size.</summary>
        public SnapshotDiff<Point> WindowSize { get; } = new();

        /// <summary>Tracks changes to the current player.</summary>
        public PlayerSnapshot? CurrentPlayer { get; private set; }

        /// <summary>Tracks changes to the time of day (in 24-hour military format).</summary>
        public SnapshotDiff<int> Time { get; } = new();

        /// <summary>Tracks changes to the save ID.</summary>
        public SnapshotDiff<ulong> SaveID { get; } = new();

        /// <summary>Tracks changes to the game's locations.</summary>
        public WorldLocationsSnapshot Locations { get; } = new();

        /// <summary>Tracks changes to <see cref="Game1.activeClickableMenu"/>.</summary>
        public SnapshotDiff<IClickableMenu> ActiveMenu { get; } = new();

        /// <summary>Tracks changes to the cursor position.</summary>
        public SnapshotDiff<ICursorPosition> Cursor { get; } = new();

        /// <summary>Tracks changes to the mouse wheel scroll.</summary>
        public SnapshotDiff<int> MouseWheelScroll { get; } = new();

        /// <summary>Tracks changes to the content locale.</summary>
        public SnapshotDiff<LocalizedContentManager.LanguageCode> Locale { get; } = new();


        /*********
        ** Public methods
        *********/
        /// <summary>Update the tracked values.</summary>
        /// <param name="watchers">The watchers to snapshot.</param>
        public void Update(WatcherCore watchers)
        {
            // update player instance
            if (watchers.CurrentPlayerTracker == null)
                this.CurrentPlayer = null;
            else if (watchers.CurrentPlayerTracker.Player != this.CurrentPlayer?.Player)
                this.CurrentPlayer = new PlayerSnapshot(watchers.CurrentPlayerTracker.Player);

            // update snapshots
            this.WindowSize.Update(watchers.WindowSizeWatcher);
            this.Locale.Update(watchers.LocaleWatcher);
            this.CurrentPlayer?.Update(watchers.CurrentPlayerTracker!);
            this.Time.Update(watchers.TimeWatcher);
            this.SaveID.Update(watchers.SaveIdWatcher);
            this.Locations.Update(watchers.LocationsWatcher);
            this.ActiveMenu.Update(watchers.ActiveMenuWatcher);
            this.Cursor.Update(watchers.CursorWatcher);
            this.MouseWheelScroll.Update(watchers.MouseWheelScrollWatcher);
        }
    }
}