summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Events/LocationEvents.cs
blob: b834bc1c856b2e4350ef01e541fdfae70b238b7a (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
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using StardewModdingAPI.Framework;
using StardewValley;
using Object = StardewValley.Object;

namespace StardewModdingAPI.Events
{
    /// <summary>Events raised when the player transitions between game locations, a location is added or removed, or the objects in the current location change.</summary>
    public static class LocationEvents
    {
        /*********
        ** Events
        *********/
        /// <summary>Raised after the player warps to a new location.</summary>
        public static event EventHandler<EventArgsCurrentLocationChanged> CurrentLocationChanged;

        /// <summary>Raised after a game location is added or removed.</summary>
        public static event EventHandler<EventArgsGameLocationsChanged> LocationsChanged;

        /// <summary>Raised after the list of objects in the current location changes (e.g. an object is added or removed).</summary>
        public static event EventHandler<EventArgsLocationObjectsChanged> LocationObjectsChanged;


        /*********
        ** Internal methods
        *********/
        /// <summary>Raise a <see cref="CurrentLocationChanged"/> event.</summary>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="priorLocation">The player's previous location.</param>
        /// <param name="newLocation">The player's current location.</param>
        internal static void InvokeCurrentLocationChanged(IMonitor monitor, GameLocation priorLocation, GameLocation newLocation)
        {
            monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.CurrentLocationChanged)}", LocationEvents.CurrentLocationChanged?.GetInvocationList(), null, new EventArgsCurrentLocationChanged(priorLocation, newLocation));
        }

        /// <summary>Raise a <see cref="LocationsChanged"/> event.</summary>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="newLocations">The current list of game locations.</param>
        internal static void InvokeLocationsChanged(IMonitor monitor, List<GameLocation> newLocations)
        {
            monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.LocationsChanged)}", LocationEvents.LocationsChanged?.GetInvocationList(), null, new EventArgsGameLocationsChanged(newLocations));
        }

        /// <summary>Raise a <see cref="LocationObjectsChanged"/> event.</summary>
        /// <param name="monitor">Encapsulates monitoring and logging.</param>
        /// <param name="newObjects">The current list of objects in the current location.</param>
        internal static void InvokeOnNewLocationObject(IMonitor monitor, SerializableDictionary<Vector2, Object> newObjects)
        {
            monitor.SafelyRaiseGenericEvent($"{nameof(LocationEvents)}.{nameof(LocationEvents.LocationObjectsChanged)}", LocationEvents.LocationObjectsChanged?.GetInvocationList(), null, new EventArgsLocationObjectsChanged(newObjects));
        }
    }
}