add large terrain feature list changed event (#310)
This commit is contained in:
parent
a2523696fd
commit
92006bd6ed
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" />
|
||||
|
|
Loading…
Reference in New Issue