From 956e477edb515953e71d1cce1a728284f6ce3cc0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 6 Nov 2016 11:15:46 -0500 Subject: add developer mode which shows all deprecation warnings, update release process (#165) --- src/StardewModdingAPI/Framework/DeprecationManager.cs | 12 +++++++++++- src/StardewModdingAPI/Framework/UserSettings.cs | 9 +++++++++ src/StardewModdingAPI/Program.cs | 15 ++++++++++++++- src/StardewModdingAPI/StardewModdingAPI-settings.json | 4 ++++ src/StardewModdingAPI/StardewModdingAPI.csproj | 8 ++++++-- 5 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/StardewModdingAPI/Framework/UserSettings.cs create mode 100644 src/StardewModdingAPI/StardewModdingAPI-settings.json (limited to 'src/StardewModdingAPI') diff --git a/src/StardewModdingAPI/Framework/DeprecationManager.cs b/src/StardewModdingAPI/Framework/DeprecationManager.cs index a3d1ea41..0c5a49f9 100644 --- a/src/StardewModdingAPI/Framework/DeprecationManager.cs +++ b/src/StardewModdingAPI/Framework/DeprecationManager.cs @@ -18,6 +18,13 @@ namespace StardewModdingAPI.Framework private readonly HashSet LoggedDeprecations = new HashSet(StringComparer.InvariantCultureIgnoreCase); + /********* + ** Accessors + *********/ + /// Whether -level deprecation messages should be shown in the console. + public bool SendNoticesToConsole { get; set; } + + /********* ** Public methods *********/ @@ -63,7 +70,10 @@ namespace StardewModdingAPI.Framework switch (severity) { case DeprecationLevel.Notice: - Log.LogToFile(message); + if (this.SendNoticesToConsole) + Log.Debug($"[DEV] {message}"); + else + Log.LogToFile(message); break; case DeprecationLevel.Info: diff --git a/src/StardewModdingAPI/Framework/UserSettings.cs b/src/StardewModdingAPI/Framework/UserSettings.cs new file mode 100644 index 00000000..199d19b3 --- /dev/null +++ b/src/StardewModdingAPI/Framework/UserSettings.cs @@ -0,0 +1,9 @@ +namespace StardewModdingAPI.Framework +{ + /// Contains user settings from SMAPI's JSON configuration file. + internal class UserSettings + { + /// Whether to enable development features. + public bool DeveloperMode { get; set; } + } +} diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index e9e357d5..047d74c7 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Windows.Forms; #endif using Microsoft.Xna.Framework.Graphics; +using Newtonsoft.Json; using StardewModdingAPI.Events; using StardewModdingAPI.Framework; using StardewModdingAPI.Inheritance; @@ -67,6 +68,18 @@ namespace StardewModdingAPI // set thread culture for consistent log formatting Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB"); + // load user settings + { + string settingsPath = $@"{Constants.ExecutionPath}\{typeof(Program).Assembly.GetName().Name}-settings.json"; + if (File.Exists(settingsPath)) + { + string json = File.ReadAllText(settingsPath); + UserSettings settings = JsonConvert.DeserializeObject(json); + Program.DeprecationManager.SendNoticesToConsole = settings?.DeveloperMode == true; + } + + } + // hook into & launch the game try { @@ -271,7 +284,7 @@ namespace StardewModdingAPI } // log deprecated fields - if(manifest.UsedAuthourField) + if (manifest.UsedAuthourField) Program.DeprecationManager.Warn(manifest.Name, $"{nameof(Manifest)}.{nameof(Manifest.Authour)}", "1.0", DeprecationLevel.Notice); } catch (Exception ex) diff --git a/src/StardewModdingAPI/StardewModdingAPI-settings.json b/src/StardewModdingAPI/StardewModdingAPI-settings.json new file mode 100644 index 00000000..d27d0141 --- /dev/null +++ b/src/StardewModdingAPI/StardewModdingAPI-settings.json @@ -0,0 +1,4 @@ +{ + /* show all deprecation notices in the console? */ + "DeveloperMode": true +} diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 5540267a..bbb41ee3 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -59,7 +59,7 @@ true false $(SolutionDir)\..\bin\Debug\SMAPI - bin\Debug\StardewModdingAPI.xml + $(SolutionDir)\..\bin\Debug\SMAPI\StardewModdingAPI.xml true 6 @@ -68,7 +68,7 @@ bin\Release\ false $(SolutionDir)\..\bin\Release\SMAPI - bin\Release\StardewModdingAPI.xml + $(SolutionDir)\..\bin\Debug\SMAPI\StardewModdingAPI.xml TRACE true true @@ -200,6 +200,7 @@ + @@ -220,6 +221,9 @@ Designer + + Always + Always -- cgit