summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Events/LocationEvents.cs
blob: af2eb4001a53597b9ad56fc77e1a8caf4d0cd93c (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
using System;
using System.Collections.Generic;
using Microsoft.Xna.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 = delegate { };

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

        /// <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 = delegate { };


        /*********
        ** Internal methods
        *********/
        /// <summary>Raise a <see cref="CurrentLocationChanged"/> event.</summary>
        /// <param name="priorLocation">The player's previous location.</param>
        /// <param name="newLocation">The player's current location.</param>
        internal static void InvokeCurrentLocationChanged(GameLocation priorLocation, GameLocation newLocation)
        {
            LocationEvents.CurrentLocationChanged.Invoke(null, new EventArgsCurrentLocationChanged(priorLocation, newLocation));
        }

        /// <summary>Raise a <see cref="LocationsChanged"/> event.</summary>
        /// <param name="newLocations">The current list of game locations.</param>
        internal static void InvokeLocationsChanged(List<GameLocation> newLocations)
        {
            LocationEvents.LocationsChanged.Invoke(null, new EventArgsGameLocationsChanged(newLocations));
        }

        /// <summary>Raise a <see cref="LocationObjectsChanged"/> event.</summary>
        /// <param name="newObjects">The current list of objects in the current location.</param>
        internal static void InvokeOnNewLocationObject(SerializableDictionary<Vector2, Object> newObjects)
        {
            LocationEvents.LocationObjectsChanged.Invoke(null, new EventArgsLocationObjectsChanged(newObjects));
        }
    }
}