replace event.HasListeners() with property
This commit is contained in:
parent
05b39b7cd9
commit
077c897d53
|
@ -8,5 +8,8 @@ namespace StardewModdingAPI.Framework.Events
|
|||
*********/
|
||||
/// <summary>A human-readable name for the event.</summary>
|
||||
string EventName { get; }
|
||||
|
||||
/// <summary>Whether any handlers are listening to the event.</summary>
|
||||
bool HasListeners { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ namespace StardewModdingAPI.Framework.Events
|
|||
/// <inheritdoc />
|
||||
public string EventName { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasListeners { get; private set; }
|
||||
|
||||
|
||||
/*********
|
||||
** Public methods
|
||||
|
@ -52,12 +55,6 @@ namespace StardewModdingAPI.Framework.Events
|
|||
this.ModRegistry = modRegistry;
|
||||
}
|
||||
|
||||
/// <summary>Get whether anything is listening to the event.</summary>
|
||||
public bool HasListeners()
|
||||
{
|
||||
return this.Handlers.Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>Add an event handler.</summary>
|
||||
/// <param name="handler">The event handler.</param>
|
||||
/// <param name="mod">The mod which added the event handler.</param>
|
||||
|
@ -70,6 +67,7 @@ namespace StardewModdingAPI.Framework.Events
|
|||
|
||||
this.Handlers.Add(managedHandler);
|
||||
this.CachedHandlers = null;
|
||||
this.HasListeners = true;
|
||||
this.HasPriorities |= priority != EventPriority.Normal;
|
||||
}
|
||||
}
|
||||
|
@ -88,6 +86,7 @@ namespace StardewModdingAPI.Framework.Events
|
|||
|
||||
this.Handlers.RemoveAt(i);
|
||||
this.CachedHandlers = null;
|
||||
this.HasListeners = this.Handlers.Count != 0;
|
||||
this.HasRemovedHandlers = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -886,7 +886,7 @@ namespace StardewModdingAPI.Framework
|
|||
bool raiseWorldEvents = !state.SaveID.IsChanged; // don't report changes from unloaded => loaded
|
||||
|
||||
// location list changes
|
||||
if (state.Locations.LocationList.IsChanged && (events.LocationListChanged.HasListeners() || verbose))
|
||||
if (state.Locations.LocationList.IsChanged && (events.LocationListChanged.HasListeners || verbose))
|
||||
{
|
||||
var added = state.Locations.LocationList.Added.ToArray();
|
||||
var removed = state.Locations.LocationList.Removed.ToArray();
|
||||
|
@ -929,7 +929,7 @@ namespace StardewModdingAPI.Framework
|
|||
events.ObjectListChanged.Raise(new ObjectListChangedEventArgs(location, locState.Objects.Added, locState.Objects.Removed));
|
||||
|
||||
// chest items changed
|
||||
if (events.ChestInventoryChanged.HasListeners())
|
||||
if (events.ChestInventoryChanged.HasListeners)
|
||||
{
|
||||
foreach (var pair in locState.ChestItems)
|
||||
{
|
||||
|
@ -1077,7 +1077,7 @@ namespace StardewModdingAPI.Framework
|
|||
}
|
||||
|
||||
// raise event
|
||||
if (this.EventManager.LocaleChanged.HasListeners())
|
||||
if (this.EventManager.LocaleChanged.HasListeners)
|
||||
{
|
||||
this.EventManager.LocaleChanged.Raise(
|
||||
new LocaleChangedEventArgs(
|
||||
|
@ -1140,7 +1140,7 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="assetName">The asset name that was loaded.</param>
|
||||
private void OnAssetLoaded(IContentManager contentManager, IAssetName assetName)
|
||||
{
|
||||
if (this.EventManager.AssetReady.HasListeners())
|
||||
if (this.EventManager.AssetReady.HasListeners)
|
||||
this.EventManager.AssetReady.Raise(new AssetReadyEventArgs(assetName, assetName.GetBaseAssetName()));
|
||||
}
|
||||
|
||||
|
@ -1148,7 +1148,7 @@ namespace StardewModdingAPI.Framework
|
|||
/// <param name="assetNames">The invalidated asset names.</param>
|
||||
private void OnAssetsInvalidated(IList<IAssetName> assetNames)
|
||||
{
|
||||
if (this.EventManager.AssetsInvalidated.HasListeners())
|
||||
if (this.EventManager.AssetsInvalidated.HasListeners)
|
||||
this.EventManager.AssetsInvalidated.Raise(new AssetsInvalidatedEventArgs(assetNames, assetNames.Select(p => p.GetBaseAssetName())));
|
||||
}
|
||||
|
||||
|
|
|
@ -353,7 +353,7 @@ namespace StardewModdingAPI.Framework
|
|||
}
|
||||
if (Game1.currentMinigame != null)
|
||||
{
|
||||
if (events.Rendering.HasListeners())
|
||||
if (events.Rendering.HasListeners)
|
||||
{
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
events.Rendering.RaiseEmpty();
|
||||
|
@ -372,7 +372,7 @@ namespace StardewModdingAPI.Framework
|
|||
Game1.PushUIMode();
|
||||
this.drawOverlays(Game1.spriteBatch);
|
||||
Game1.PopUIMode();
|
||||
if (events.Rendered.HasListeners())
|
||||
if (events.Rendered.HasListeners)
|
||||
{
|
||||
Game1.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null);
|
||||
events.Rendered.RaiseEmpty();
|
||||
|
|
Loading…
Reference in New Issue