diff options
-rw-r--r-- | src/SMAPI/Events/IWorldEvents.cs | 5 | ||||
-rw-r--r-- | src/SMAPI/Events/WorldLargeTerrainFeatureListChangedEventArgs.cs | 39 | ||||
-rw-r--r-- | src/SMAPI/Framework/Events/EventManager.cs | 6 | ||||
-rw-r--r-- | src/SMAPI/Framework/Events/ModWorldEvents.cs | 9 | ||||
-rw-r--r-- | src/SMAPI/Framework/SGame.cs | 11 | ||||
-rw-r--r-- | src/SMAPI/Framework/StateTracking/LocationTracker.cs | 5 | ||||
-rw-r--r-- | src/SMAPI/StardewModdingAPI.csproj | 1 |
7 files changed, 73 insertions, 3 deletions
diff --git a/src/SMAPI/Events/IWorldEvents.cs b/src/SMAPI/Events/IWorldEvents.cs index ce288ae1..6a43baf2 100644 --- a/src/SMAPI/Events/IWorldEvents.cs +++ b/src/SMAPI/Events/IWorldEvents.cs @@ -14,13 +14,16 @@ namespace StardewModdingAPI.Events /// <summary>Raised after buildings are added or removed in a location.</summary> event EventHandler<WorldBuildingListChangedEventArgs> BuildingListChanged; + /// <summary>Raised after large terrain features (like bushes) are added or removed in a location.</summary> + event EventHandler<WorldLargeTerrainFeatureListChangedEventArgs> LargeTerrainFeatureListChanged; + /// <summary>Raised after NPCs are added or removed in a location.</summary> event EventHandler<WorldNpcListChangedEventArgs> NpcListChanged; /// <summary>Raised after objects are added or removed in a location.</summary> event EventHandler<WorldObjectListChangedEventArgs> ObjectListChanged; - /// <summary>Raised after terrain features are added or removed in a location.</summary> + /// <summary>Raised after terrain features (like floors and trees) are added or removed in a location.</summary> event EventHandler<WorldTerrainFeatureListChangedEventArgs> TerrainFeatureListChanged; } } diff --git a/src/SMAPI/Events/WorldLargeTerrainFeatureListChangedEventArgs.cs b/src/SMAPI/Events/WorldLargeTerrainFeatureListChangedEventArgs.cs new file mode 100644 index 00000000..053a0e41 --- /dev/null +++ b/src/SMAPI/Events/WorldLargeTerrainFeatureListChangedEventArgs.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using StardewValley; +using StardewValley.TerrainFeatures; + +namespace StardewModdingAPI.Events +{ + /// <summary>Event arguments for a <see cref="IWorldEvents.LargeTerrainFeatureListChanged"/> event.</summary> + public class WorldLargeTerrainFeatureListChangedEventArgs : EventArgs + { + /********* + ** Accessors + *********/ + /// <summary>The location which changed.</summary> + public GameLocation Location { get; } + + /// <summary>The large terrain features added to the location.</summary> + public IEnumerable<LargeTerrainFeature> Added { get; } + + /// <summary>The large terrain features removed from the location.</summary> + public IEnumerable<LargeTerrainFeature> Removed { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Construct an instance.</summary> + /// <param name="location">The location which changed.</param> + /// <param name="added">The large terrain features added to the location.</param> + /// <param name="removed">The large terrain features removed from the location.</param> + public WorldLargeTerrainFeatureListChangedEventArgs(GameLocation location, IEnumerable<LargeTerrainFeature> added, IEnumerable<LargeTerrainFeature> 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 cb331e7a..7ce8c640 100644 --- a/src/SMAPI/Framework/Events/EventManager.cs +++ b/src/SMAPI/Framework/Events/EventManager.cs @@ -20,13 +20,16 @@ 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 large terrain features (like bushes) are added or removed in a location.</summary> + public readonly ManagedEvent<WorldLargeTerrainFeatureListChangedEventArgs> World_LargeTerrainFeatureListChanged; + /// <summary>Raised after NPCs are added or removed in a location.</summary> public readonly ManagedEvent<WorldNpcListChangedEventArgs> World_NpcListChanged; /// <summary>Raised after objects are added or removed in a location.</summary> public readonly ManagedEvent<WorldObjectListChangedEventArgs> World_ObjectListChanged; - /// <summary>Raised after terrain features are added or removed in a location.</summary> + /// <summary>Raised after terrain features (like floors and trees) are added or removed in a location.</summary> public readonly ManagedEvent<WorldTerrainFeatureListChangedEventArgs> World_TerrainFeatureListChanged; @@ -232,6 +235,7 @@ namespace StardewModdingAPI.Framework.Events // init events (new) this.World_BuildingListChanged = ManageEventOf<WorldBuildingListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.LocationListChanged)); + 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)); this.World_ObjectListChanged = ManageEventOf<WorldObjectListChangedEventArgs>(nameof(IModEvents.World), nameof(IWorldEvents.ObjectListChanged)); diff --git a/src/SMAPI/Framework/Events/ModWorldEvents.cs b/src/SMAPI/Framework/Events/ModWorldEvents.cs index ca851550..db03e447 100644 --- a/src/SMAPI/Framework/Events/ModWorldEvents.cs +++ b/src/SMAPI/Framework/Events/ModWorldEvents.cs @@ -33,6 +33,13 @@ namespace StardewModdingAPI.Framework.Events remove => this.EventManager.World_BuildingListChanged.Remove(value); } + /// <summary>Raised after large terrain features (like bushes) are added or removed in a location.</summary> + public event EventHandler<WorldLargeTerrainFeatureListChangedEventArgs> LargeTerrainFeatureListChanged + { + add => this.EventManager.World_LargeTerrainFeatureListChanged.Add(value, this.Mod); + remove => this.EventManager.World_LargeTerrainFeatureListChanged.Remove(value); + } + /// <summary>Raised after NPCs are added or removed in a location.</summary> public event EventHandler<WorldNpcListChangedEventArgs> NpcListChanged { @@ -47,7 +54,7 @@ namespace StardewModdingAPI.Framework.Events remove => this.EventManager.World_ObjectListChanged.Remove(value); } - /// <summary>Raised after terrain features are added or removed in a location.</summary> + /// <summary>Raised after terrain features (like floors and trees) are added or removed in a location.</summary> public event EventHandler<WorldTerrainFeatureListChangedEventArgs> TerrainFeatureListChanged { add => this.EventManager.World_TerrainFeatureListChanged.Add(value); diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs index 38f96566..90dbacfe 100644 --- a/src/SMAPI/Framework/SGame.cs +++ b/src/SMAPI/Framework/SGame.cs @@ -567,6 +567,17 @@ namespace StardewModdingAPI.Framework this.Events.Location_BuildingsChanged.Raise(new EventArgsLocationBuildingsChanged(location, added, removed)); } + // large terrain features changed + if (watcher.LargeTerrainFeaturesWatcher.IsChanged) + { + GameLocation location = watcher.Location; + LargeTerrainFeature[] added = watcher.LargeTerrainFeaturesWatcher.Added.ToArray(); + LargeTerrainFeature[] removed = watcher.LargeTerrainFeaturesWatcher.Removed.ToArray(); + watcher.LargeTerrainFeaturesWatcher.Reset(); + + this.Events.World_LargeTerrainFeatureListChanged.Raise(new WorldLargeTerrainFeatureListChangedEventArgs(location, added, removed)); + } + // NPCs changed if (watcher.NpcsWatcher.IsChanged) { diff --git a/src/SMAPI/Framework/StateTracking/LocationTracker.cs b/src/SMAPI/Framework/StateTracking/LocationTracker.cs index 4ac455ac..1b4c0b19 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 large terrain features.</summary> + public ICollectionWatcher<LargeTerrainFeature> LargeTerrainFeaturesWatcher { get; } + /// <summary>Tracks added or removed NPCs.</summary> public ICollectionWatcher<NPC> NpcsWatcher { get; } @@ -56,6 +59,7 @@ namespace StardewModdingAPI.Framework.StateTracking this.BuildingsWatcher = location is BuildableGameLocation buildableLocation ? WatcherFactory.ForNetCollection(buildableLocation.buildings) : (ICollectionWatcher<Building>)WatcherFactory.ForObservableCollection(new ObservableCollection<Building>()); + this.LargeTerrainFeaturesWatcher = WatcherFactory.ForNetCollection(location.largeTerrainFeatures); this.NpcsWatcher = WatcherFactory.ForNetCollection(location.characters); this.ObjectsWatcher = WatcherFactory.ForNetDictionary(location.netObjects); this.TerrainFeaturesWatcher = WatcherFactory.ForNetDictionary(location.terrainFeatures); @@ -63,6 +67,7 @@ namespace StardewModdingAPI.Framework.StateTracking this.Watchers.AddRange(new IWatcher[] { this.BuildingsWatcher, + this.LargeTerrainFeaturesWatcher, this.NpcsWatcher, this.ObjectsWatcher, this.TerrainFeaturesWatcher diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index 37b624fb..f9c93671 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -89,6 +89,7 @@ <Compile Include="Events\IWorldEvents.cs" /> <Compile Include="Events\MultiplayerEvents.cs" /> <Compile Include="Events\WorldNpcListChangedEventArgs.cs" /> + <Compile Include="Events\WorldLargeTerrainFeatureListChangedEventArgs.cs" /> <Compile Include="Events\WorldTerrainFeatureListChangedEventArgs.cs" /> <Compile Include="Events\WorldBuildingListChangedEventArgs.cs" /> <Compile Include="Events\WorldLocationListChangedEventArgs.cs" /> |