summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-13 02:00:30 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2018-12-13 02:00:30 -0500
commit6045351395f6b74846a2b18b131f662b88641569 (patch)
tree79dd58dd038c482b3890afc238e708c1b2224436 /src/SMAPI/Framework
parent11787f9fea35ee8597c8a4c028b9c3be42751463 (diff)
downloadSMAPI-6045351395f6b74846a2b18b131f662b88641569.tar.gz
SMAPI-6045351395f6b74846a2b18b131f662b88641569.tar.bz2
SMAPI-6045351395f6b74846a2b18b131f662b88641569.zip
simplify access to deprecation manager for deprecation warnings
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/ModHelpers/ModHelper.cs17
-rw-r--r--src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs7
-rw-r--r--src/SMAPI/Framework/SCore.cs51
3 files changed, 30 insertions, 45 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/ModHelper.cs b/src/SMAPI/Framework/ModHelpers/ModHelper.cs
index 0dbc5fd7..ca872e32 100644
--- a/src/SMAPI/Framework/ModHelpers/ModHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/ModHelper.cs
@@ -13,15 +13,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
internal class ModHelper : BaseHelper, IModHelper, IDisposable
{
/*********
- ** Properties
- *********/
-#if !SMAPI_3_0_STRICT
- /// <summary>Manages deprecation warnings.</summary>
- private readonly DeprecationManager DeprecationManager;
-#endif
-
-
- /*********
** Accessors
*********/
/// <summary>The full path to the mod's folder.</summary>
@@ -80,10 +71,9 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <param name="reflectionHelper">An API for accessing private game code.</param>
/// <param name="multiplayer">Provides multiplayer utilities.</param>
/// <param name="translationHelper">An API for reading translations stored in the mod's <c>i18n</c> folder.</param>
- /// <param name="deprecationManager">Manages deprecation warnings.</param>
/// <exception cref="ArgumentNullException">An argument is null or empty.</exception>
/// <exception cref="InvalidOperationException">The <paramref name="modDirectory"/> path does not exist on disk.</exception>
- public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper, DeprecationManager deprecationManager)
+ public ModHelper(string modID, string modDirectory, JsonHelper jsonHelper, SInputState inputState, IModEvents events, IContentHelper contentHelper, IContentPackHelper contentPackHelper, ICommandHelper commandHelper, IDataHelper dataHelper, IModRegistry modRegistry, IReflectionHelper reflectionHelper, IMultiplayerHelper multiplayer, ITranslationHelper translationHelper)
: base(modID)
{
// validate directory
@@ -106,7 +96,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
this.Events = events;
#if !SMAPI_3_0_STRICT
this.JsonHelper = jsonHelper ?? throw new ArgumentNullException(nameof(jsonHelper));
- this.DeprecationManager = deprecationManager;
#endif
}
@@ -177,8 +166,8 @@ namespace StardewModdingAPI.Framework.ModHelpers
[Obsolete("Use " + nameof(IModHelper) + "." + nameof(IModHelper.ContentPacks) + "." + nameof(IContentPackHelper.CreateTemporary) + " instead")]
public IContentPack CreateTransitionalContentPack(string directoryPath, string id, string name, string description, string author, ISemanticVersion version)
{
- this.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice);
- return this.ContentPacks.CreateFake(directoryPath, id, name, description, author, version);
+ SCore.DeprecationManager.Warn($"{nameof(IModHelper)}.{nameof(IModHelper.CreateTransitionalContentPack)}", "2.5", DeprecationLevel.Notice);
+ return this.ContentPacks.CreateTemporary(directoryPath, id, name, description, author, version);
}
/// <summary>Get all content packs loaded for this mod.</summary>
diff --git a/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs b/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs
index 648d6742..cfe2ddbe 100644
--- a/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/ReflectionHelper.cs
@@ -17,9 +17,6 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <summary>The mod name for error messages.</summary>
private readonly string ModName;
- /// <summary>Manages deprecation warnings.</summary>
- private readonly DeprecationManager DeprecationManager;
-
/*********
** Public methods
@@ -28,13 +25,11 @@ namespace StardewModdingAPI.Framework.ModHelpers
/// <param name="modID">The unique ID of the relevant mod.</param>
/// <param name="modName">The mod name for error messages.</param>
/// <param name="reflector">The underlying reflection helper.</param>
- /// <param name="deprecationManager">Manages deprecation warnings.</param>
- public ReflectionHelper(string modID, string modName, Reflector reflector, DeprecationManager deprecationManager)
+ public ReflectionHelper(string modID, string modName, Reflector reflector)
: base(modID)
{
this.ModName = modName;
this.Reflector = reflector;
- this.DeprecationManager = deprecationManager;
}
/// <summary>Get an instance field.</summary>
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index 76b091d0..3749bab4 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -75,10 +75,6 @@ namespace StardewModdingAPI.Framework
/// <remarks>This is initialised after the game starts.</remarks>
private readonly ModRegistry ModRegistry = new ModRegistry();
- /// <summary>Manages deprecation warnings.</summary>
- /// <remarks>This is initialised after the game starts.</remarks>
- private readonly DeprecationManager DeprecationManager;
-
/// <summary>Manages SMAPI events for mods.</summary>
private readonly EventManager EventManager;
@@ -121,6 +117,14 @@ namespace StardewModdingAPI.Framework
/*********
+ ** Accessors
+ *********/
+ /// <summary>Manages deprecation warnings.</summary>
+ /// <remarks>This is initialised after the game starts. This is accessed directly because it's not part of the normal class model.</remarks>
+ internal static DeprecationManager DeprecationManager { get; private set; }
+
+
+ /*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
@@ -148,15 +152,12 @@ namespace StardewModdingAPI.Framework
};
this.MonitorForGame = this.GetSecondaryMonitor("game");
this.EventManager = new EventManager(this.Monitor, this.ModRegistry);
- this.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry);
+ SCore.DeprecationManager = new DeprecationManager(this.Monitor, this.ModRegistry);
// redirect direct console output
if (this.MonitorForGame.WriteToConsole)
this.ConsoleManager.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message);
- // inject deprecation managers
- SemanticVersion.DeprecationManager = this.DeprecationManager;
-
// init logging
this.Monitor.Log($"SMAPI {Constants.ApiVersion} with Stardew Valley {Constants.GameVersion} on {EnvironmentUtility.GetFriendlyPlatformName(Constants.Platform)}", LogLevel.Info);
this.Monitor.Log($"Mods go here: {modsPath}");
@@ -196,19 +197,19 @@ namespace StardewModdingAPI.Framework
{
#if !SMAPI_3_0_STRICT
// hook up events
- ContentEvents.Init(this.EventManager, this.DeprecationManager);
- ControlEvents.Init(this.EventManager, this.DeprecationManager);
- GameEvents.Init(this.EventManager, this.DeprecationManager);
- GraphicsEvents.Init(this.EventManager, this.DeprecationManager);
- InputEvents.Init(this.EventManager, this.DeprecationManager);
- LocationEvents.Init(this.EventManager, this.DeprecationManager);
- MenuEvents.Init(this.EventManager, this.DeprecationManager);
- MineEvents.Init(this.EventManager, this.DeprecationManager);
- MultiplayerEvents.Init(this.EventManager, this.DeprecationManager);
- PlayerEvents.Init(this.EventManager, this.DeprecationManager);
- SaveEvents.Init(this.EventManager, this.DeprecationManager);
- SpecialisedEvents.Init(this.EventManager, this.DeprecationManager);
- TimeEvents.Init(this.EventManager, this.DeprecationManager);
+ ContentEvents.Init(this.EventManager);
+ ControlEvents.Init(this.EventManager);
+ GameEvents.Init(this.EventManager);
+ GraphicsEvents.Init(this.EventManager);
+ InputEvents.Init(this.EventManager);
+ LocationEvents.Init(this.EventManager);
+ MenuEvents.Init(this.EventManager);
+ MineEvents.Init(this.EventManager);
+ MultiplayerEvents.Init(this.EventManager);
+ PlayerEvents.Init(this.EventManager);
+ SaveEvents.Init(this.EventManager);
+ SpecialisedEvents.Init(this.EventManager);
+ TimeEvents.Init(this.EventManager);
#endif
// init JSON parser
@@ -232,7 +233,7 @@ namespace StardewModdingAPI.Framework
// override game
SGame.ConstructorHack = new SGameConstructorHack(this.Monitor, this.Reflection, this.Toolkit.JsonHelper);
- this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, this.DeprecationManager, this.OnLocaleChanged, this.InitialiseAfterGameStart, this.Dispose);
+ this.GameInstance = new SGame(this.Monitor, this.MonitorForGame, this.Reflection, this.EventManager, this.Toolkit.JsonHelper, this.ModRegistry, SCore.DeprecationManager, this.OnLocaleChanged, this.InitialiseAfterGameStart, this.Dispose);
StardewValley.Program.gamePtr = this.GameInstance;
// add exit handler
@@ -920,7 +921,7 @@ namespace StardewModdingAPI.Framework
// add deprecation warning for old version format
{
if (mod.Manifest?.Version is Toolkit.SemanticVersion version && version.IsLegacyFormat)
- this.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.Notice);
+ SCore.DeprecationManager.Warn(mod.DisplayName, "non-string manifest version", "2.8", DeprecationLevel.Notice);
}
#endif
@@ -1016,7 +1017,7 @@ namespace StardewModdingAPI.Framework
IContentHelper contentHelper = new ContentHelper(contentCore, mod.DirectoryPath, manifest.UniqueID, mod.DisplayName, monitor);
IContentPackHelper contentPackHelper = new ContentPackHelper(manifest.UniqueID, new Lazy<IContentPack[]>(GetContentPacks), CreateFakeContentPack);
IDataHelper dataHelper = new DataHelper(manifest.UniqueID, mod.DirectoryPath, jsonHelper);
- IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, mod.DisplayName, this.Reflection, this.DeprecationManager);
+ IReflectionHelper reflectionHelper = new ReflectionHelper(manifest.UniqueID, mod.DisplayName, this.Reflection);
IModRegistry modRegistryHelper = new ModRegistryHelper(manifest.UniqueID, this.ModRegistry, proxyFactory, monitor);
IMultiplayerHelper multiplayerHelper = new MultiplayerHelper(manifest.UniqueID, this.GameInstance.Multiplayer);
ITranslationHelper translationHelper = new TranslationHelper(manifest.UniqueID, manifest.Name, contentCore.GetLocale(), contentCore.Language);
@@ -1028,7 +1029,7 @@ namespace StardewModdingAPI.Framework
return new ContentPack(packDirPath, packManifest, packContentHelper, this.Toolkit.JsonHelper);
}
- modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper, this.DeprecationManager);
+ modHelper = new ModHelper(manifest.UniqueID, mod.DirectoryPath, this.Toolkit.JsonHelper, this.GameInstance.Input, events, contentHelper, contentPackHelper, commandHelper, dataHelper, modRegistryHelper, reflectionHelper, multiplayerHelper, translationHelper);
}
// init mod