From 97a2bdfdd443b3d5b79f48eb1d718ebf255f5e0f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 2 Jun 2018 01:47:33 -0400 Subject: [PATCH] add base implementation for mod event classes (#310) --- src/SMAPI/Framework/Events/ModEventsBase.cs | 28 ++++++++++++++++++++ src/SMAPI/Framework/Events/ModWorldEvents.cs | 17 ++---------- src/SMAPI/StardewModdingAPI.csproj | 1 + 3 files changed, 31 insertions(+), 15 deletions(-) create mode 100644 src/SMAPI/Framework/Events/ModEventsBase.cs diff --git a/src/SMAPI/Framework/Events/ModEventsBase.cs b/src/SMAPI/Framework/Events/ModEventsBase.cs new file mode 100644 index 00000000..545c58a8 --- /dev/null +++ b/src/SMAPI/Framework/Events/ModEventsBase.cs @@ -0,0 +1,28 @@ +namespace StardewModdingAPI.Framework.Events +{ + /// An internal base class for event API classes. + internal abstract class ModEventsBase + { + /********* + ** Properties + *********/ + /// The underlying event manager. + protected readonly EventManager EventManager; + + /// The mod which uses this instance. + protected readonly IModMetadata Mod; + + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The mod which uses this instance. + /// The underlying event manager. + internal ModEventsBase(IModMetadata mod, EventManager eventManager) + { + this.Mod = mod; + this.EventManager = eventManager; + } + } +} diff --git a/src/SMAPI/Framework/Events/ModWorldEvents.cs b/src/SMAPI/Framework/Events/ModWorldEvents.cs index db03e447..e1a53e0c 100644 --- a/src/SMAPI/Framework/Events/ModWorldEvents.cs +++ b/src/SMAPI/Framework/Events/ModWorldEvents.cs @@ -4,18 +4,8 @@ using StardewModdingAPI.Events; namespace StardewModdingAPI.Framework.Events { /// Events raised when something changes in the world. - public class ModWorldEvents : IWorldEvents + internal class ModWorldEvents : ModEventsBase, IWorldEvents { - /********* - ** Properties - *********/ - /// The underlying event manager. - private readonly EventManager EventManager; - - /// The mod which uses this instance. - private readonly IModMetadata Mod; - - /********* ** Accessors *********/ @@ -69,9 +59,6 @@ namespace StardewModdingAPI.Framework.Events /// The mod which uses this instance. /// The underlying event manager. internal ModWorldEvents(IModMetadata mod, EventManager eventManager) - { - this.Mod = mod; - this.EventManager = eventManager; - } + : base(mod, eventManager) { } } } diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj index f9c93671..7b9629e2 100644 --- a/src/SMAPI/StardewModdingAPI.csproj +++ b/src/SMAPI/StardewModdingAPI.csproj @@ -98,6 +98,7 @@ +