summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/SMAPI/Events/IWorldEvents.cs3
-rw-r--r--src/SMAPI/Events/WorldDebrisListChangedEventArgs.cs38
-rw-r--r--src/SMAPI/Framework/Events/EventManager.cs4
-rw-r--r--src/SMAPI/Framework/Events/ModWorldEvents.cs7
-rw-r--r--src/SMAPI/Framework/SGame.cs11
-rw-r--r--src/SMAPI/Framework/StateTracking/LocationTracker.cs5
-rw-r--r--src/SMAPI/Framework/WatcherCore.cs2
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj1
8 files changed, 70 insertions, 1 deletions
diff --git a/src/SMAPI/Events/IWorldEvents.cs b/src/SMAPI/Events/IWorldEvents.cs
index 067a79bc..d4efb53b 100644
--- a/src/SMAPI/Events/IWorldEvents.cs
+++ b/src/SMAPI/Events/IWorldEvents.cs
@@ -11,6 +11,9 @@ namespace StardewModdingAPI.Events
/// <summary>Raised after buildings are added or removed in a location.</summary>
event EventHandler<WorldBuildingListChangedEventArgs> BuildingListChanged;
+ /// <summary>Raised after debris are added or removed in a location.</summary>
+ event EventHandler<WorldDebrisListChangedEventArgs> DebrisListChanged;
+
/// <summary>Raised after large terrain features (like bushes) are added or removed in a location.</summary>
event EventHandler<WorldLargeTerrainFeatureListChangedEventArgs> LargeTerrainFeatureListChanged;
diff --git a/src/SMAPI/Events/WorldDebrisListChangedEventArgs.cs b/src/SMAPI/Events/WorldDebrisListChangedEventArgs.cs
new file mode 100644
index 00000000..aad9c24d
--- /dev/null
+++ b/src/SMAPI/Events/WorldDebrisListChangedEventArgs.cs
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using StardewValley;
+
+namespace StardewModdingAPI.Events
+{
+ /// <summary>Event arguments for a <see cref="IWorldEvents.DebrisListChanged"/> event.</summary>
+ public class WorldDebrisListChangedEventArgs : EventArgs
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The location which changed.</summary>
+ public GameLocation Location { get; }
+
+ /// <summary>The debris added to the location.</summary>
+ public IEnumerable<Debris> Added { get; }
+
+ /// <summary>The debris removed from the location.</summary>
+ public IEnumerable<Debris> Removed { get; }
+
+
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="location">The location which changed.</param>
+ /// <param name="added">The debris added to the location.</param>
+ /// <param name="removed">The debris removed from the location.</param>
+ public WorldDebrisListChangedEventArgs(GameLocation location, IEnumerable<Debris> added, IEnumerable<Debris> removed)
+ {
+ this.Location = location;
+ this.Added = added.ToArray();
+ this.Removed = removed.ToArray();
+ }
+ }
+}
diff --git a/src/SMAPI/Framework/Events/EventManager.cs b/src/SMAPI/Framework/Events/EventManager.cs
index 9f67244a..b05d82ce 100644
--- a/src/SMAPI/Framework/Events/EventManager.cs
+++ b/src/SMAPI/Framework/Events/EventManager.cs
@@ -20,6 +20,9 @@ namespace StardewModdingAPI.Framework.Events
/// <summary>Raised after buildings are added or removed in a location.</summary>
public readonly ManagedEvent<WorldBuildingListChangedEventArgs> World_BuildingListChanged;
+ /// <summary>Raised after debris are added or removed in a location.</summary>
+ public readonly ManagedEvent<WorldDebrisListChangedEventArgs> World_DebrisListChanged;
+
/// <summary>Raised after large terrain features (like bushes) are added or removed in a location.</summary>
public readonly ManagedEvent<WorldLargeTerrainFeatureListChangedEventArgs> World_LargeTerrainFeatureListChanged;
@@ -255,6 +258,7 @@ namespace StardewModdingAPI.Framework.Events
this.Input_MouseWheelScrolled = ManageEventOf<InputMouseWheelScrolledEventArgs>(nameof(IModEvents.Input), nameof(IInputEvents.MouseWheelScrolled));
this.World_BuildingListChanged = ManageEventOf<WorldBuildingListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LocationListChanged));
+ this.World_DebrisListChanged = ManageEventOf<WorldDebrisListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.DebrisListChanged));
this.World_LargeTerrainFeatureListChanged = ManageEventOf<WorldLargeTerrainFeatureListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LargeTerrainFeatureListChanged));
this.World_LocationListChanged = ManageEventOf<WorldLocationListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.BuildingListChanged));
this.World_NpcListChanged = ManageEventOf<WorldNpcListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.NpcListChanged));
diff --git a/src/SMAPI/Framework/Events/ModWorldEvents.cs b/src/SMAPI/Framework/Events/ModWorldEvents.cs
index e1a53e0c..dc9c0f4c 100644
--- a/src/SMAPI/Framework/Events/ModWorldEvents.cs
+++ b/src/SMAPI/Framework/Events/ModWorldEvents.cs
@@ -23,6 +23,13 @@ namespace StardewModdingAPI.Framework.Events
remove => this.EventManager.World_BuildingListChanged.Remove(value);
}
+ /// <summary>Raised after debris are added or removed in a location.</summary>
+ public event EventHandler<WorldDebrisListChangedEventArgs> DebrisListChanged
+ {
+ add => this.EventManager.World_DebrisListChanged.Add(value, this.Mod);
+ remove => this.EventManager.World_DebrisListChanged.Remove(value);
+ }
+
/// <summary>Raised after large terrain features (like bushes) are added or removed in a location.</summary>
public event EventHandler<WorldLargeTerrainFeatureListChangedEventArgs> LargeTerrainFeatureListChanged
{
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs
index 588d30c8..984c1f57 100644
--- a/src/SMAPI/Framework/SGame.cs
+++ b/src/SMAPI/Framework/SGame.cs
@@ -536,6 +536,17 @@ namespace StardewModdingAPI.Framework
this.Events.Legacy_Location_BuildingsChanged.Raise(new EventArgsLocationBuildingsChanged(location, added, removed));
}
+ // debris changed
+ if (watcher.DebrisWatcher.IsChanged)
+ {
+ GameLocation location = watcher.Location;
+ Debris[] added = watcher.DebrisWatcher.Added.ToArray();
+ Debris[] removed = watcher.DebrisWatcher.Removed.ToArray();
+ watcher.DebrisWatcher.Reset();
+
+ this.Events.World_DebrisListChanged.Raise(new WorldDebrisListChangedEventArgs(location, added, removed));
+ }
+
// large terrain features changed
if (watcher.LargeTerrainFeaturesWatcher.IsChanged)
{
diff --git a/src/SMAPI/Framework/StateTracking/LocationTracker.cs b/src/SMAPI/Framework/StateTracking/LocationTracker.cs
index 1b4c0b19..708c0716 100644
--- a/src/SMAPI/Framework/StateTracking/LocationTracker.cs
+++ b/src/SMAPI/Framework/StateTracking/LocationTracker.cs
@@ -33,6 +33,9 @@ namespace StardewModdingAPI.Framework.StateTracking
/// <summary>Tracks added or removed buildings.</summary>
public ICollectionWatcher<Building> BuildingsWatcher { get; }
+ /// <summary>Tracks added or removed debris.</summary>
+ public ICollectionWatcher<Debris> DebrisWatcher { get; }
+
/// <summary>Tracks added or removed large terrain features.</summary>
public ICollectionWatcher<LargeTerrainFeature> LargeTerrainFeaturesWatcher { get; }
@@ -59,6 +62,7 @@ namespace StardewModdingAPI.Framework.StateTracking
this.BuildingsWatcher = location is BuildableGameLocation buildableLocation
? WatcherFactory.ForNetCollection(buildableLocation.buildings)
: (ICollectionWatcher<Building>)WatcherFactory.ForObservableCollection(new ObservableCollection<Building>());
+ this.DebrisWatcher = WatcherFactory.ForNetCollection(location.debris);
this.LargeTerrainFeaturesWatcher = WatcherFactory.ForNetCollection(location.largeTerrainFeatures);
this.NpcsWatcher = WatcherFactory.ForNetCollection(location.characters);
this.ObjectsWatcher = WatcherFactory.ForNetDictionary(location.netObjects);
@@ -67,6 +71,7 @@ namespace StardewModdingAPI.Framework.StateTracking
this.Watchers.AddRange(new IWatcher[]
{
this.BuildingsWatcher,
+ this.DebrisWatcher,
this.LargeTerrainFeaturesWatcher,
this.NpcsWatcher,
this.ObjectsWatcher,
diff --git a/src/SMAPI/Framework/WatcherCore.cs b/src/SMAPI/Framework/WatcherCore.cs
index 64b063cf..e06423b9 100644
--- a/src/SMAPI/Framework/WatcherCore.cs
+++ b/src/SMAPI/Framework/WatcherCore.cs
@@ -13,7 +13,7 @@ namespace StardewModdingAPI.Framework
internal class WatcherCore
{
/*********
- ** Public methods
+ ** Properties
*********/
/// <summary>The underlying watchers for convenience. These are accessible individually as separate properties.</summary>
private readonly List<IWatcher> Watchers = new List<IWatcher>();
diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj
index 67c48a57..ab3967c5 100644
--- a/src/SMAPI/StardewModdingAPI.csproj
+++ b/src/SMAPI/StardewModdingAPI.csproj
@@ -97,6 +97,7 @@
<Compile Include="Events\IInputEvents.cs" />
<Compile Include="Events\IWorldEvents.cs" />
<Compile Include="Events\MultiplayerEvents.cs" />
+ <Compile Include="Events\WorldDebrisListChangedEventArgs.cs" />
<Compile Include="Events\WorldNpcListChangedEventArgs.cs" />
<Compile Include="Events\WorldLargeTerrainFeatureListChangedEventArgs.cs" />
<Compile Include="Events\WorldTerrainFeatureListChangedEventArgs.cs" />