From e5f42badcc6e31fea4c98d7519142a1c578cf299 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Wed, 23 Mar 2016 16:50:05 -0400 Subject: note --- StardewModdingAPI/Config.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'StardewModdingAPI') diff --git a/StardewModdingAPI/Config.cs b/StardewModdingAPI/Config.cs index 8e6a590c..c2cd6db1 100644 --- a/StardewModdingAPI/Config.cs +++ b/StardewModdingAPI/Config.cs @@ -175,6 +175,7 @@ namespace StardewModdingAPI /// /// Re-reads the json blob on the disk and merges its values with a default config + /// NOTE: You MUST set your config EQUAL to the return of this method! /// public static T ReloadConfig(this T baseConfig) where T : Config { -- cgit From e4d1e0a40e89b3fb35bf3ee7a4c213919caae640 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sat, 26 Mar 2016 18:27:07 -0400 Subject: mid-update commit for resync --- StardewModdingAPI/Config.cs | 8 +- StardewModdingAPI/Events/Mine.cs | 10 +- StardewModdingAPI/Extensions.cs | 17 ++- StardewModdingAPI/Inheritance/SBareObject.cs | 27 ++++ StardewModdingAPI/JsonResolver.cs | 215 +++++++++++++++++++++++++++ StardewModdingAPI/Log.cs | 45 +++--- StardewModdingAPI/StardewModdingAPI.csproj | 2 + 7 files changed, 297 insertions(+), 27 deletions(-) create mode 100644 StardewModdingAPI/Inheritance/SBareObject.cs create mode 100644 StardewModdingAPI/JsonResolver.cs (limited to 'StardewModdingAPI') diff --git a/StardewModdingAPI/Config.cs b/StardewModdingAPI/Config.cs index c2cd6db1..d5517535 100644 --- a/StardewModdingAPI/Config.cs +++ b/StardewModdingAPI/Config.cs @@ -56,7 +56,7 @@ namespace StardewModdingAPI try { //try to load the config from a json blob on disk - T c = JsonConvert.DeserializeObject(File.ReadAllText(ConfigLocation)); + T c = JsonConvert.DeserializeObject(File.ReadAllText(ConfigLocation), new JsonSerializerSettings() {ContractResolver = new JsonResolver()}); c.ConfigLocation = ConfigLocation; @@ -94,10 +94,10 @@ namespace StardewModdingAPI try { //default config - var b = JObject.FromObject(Instance().GenerateDefaultConfig()); + var b = JObject.FromObject(Instance().GenerateDefaultConfig(), new JsonSerializer() {ContractResolver = new JsonResolver()}); //user config - var u = JObject.FromObject(this); + var u = JObject.FromObject(this, new JsonSerializer() {ContractResolver = new JsonResolver()}); //overwrite default values with user values b.Merge(u, new JsonMergeSettings {MergeArrayHandling = MergeArrayHandling.Replace}); @@ -164,7 +164,7 @@ namespace StardewModdingAPI return; } - string s = JsonConvert.SerializeObject(baseConfig, typeof (T), Formatting.Indented, new JsonSerializerSettings()); + string s = JsonConvert.SerializeObject(baseConfig, typeof (T), Formatting.Indented, new JsonSerializerSettings() {ContractResolver = new JsonResolver()}); if (!Directory.Exists(baseConfig.ConfigDir)) Directory.CreateDirectory(baseConfig.ConfigDir); diff --git a/StardewModdingAPI/Events/Mine.cs b/StardewModdingAPI/Events/Mine.cs index ea23a8a3..2f4e9ba7 100644 --- a/StardewModdingAPI/Events/Mine.cs +++ b/StardewModdingAPI/Events/Mine.cs @@ -1,6 +1,14 @@ -namespace StardewModdingAPI.Events +using System; + +namespace StardewModdingAPI.Events { public static class MineEvents { + public static event EventHandler MineLevelChanged = delegate { }; + + public static void InvokeLocationsChanged(int currentMineLevel) + { + + } } } diff --git a/StardewModdingAPI/Extensions.cs b/StardewModdingAPI/Extensions.cs index 53c69c29..58430a6e 100644 --- a/StardewModdingAPI/Extensions.cs +++ b/StardewModdingAPI/Extensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; using System.Reflection; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Input; @@ -21,16 +22,28 @@ namespace StardewModdingAPI return new Color(Random.Next(0, 255), Random.Next(0, 255), Random.Next(0, 255)); } + [Obsolete("The usage of ToSingular has changed. Please update your call to use ToSingular")] public static string ToSingular(this IEnumerable ienum, string split = ", ") + { + Log.Error("The usage of ToSingular has changed. Please update your call to use ToSingular"); + return ""; + } + + public static string ToSingular(this IEnumerable ienum, string split = ", ")// where T : class { //Apparently Keys[] won't split normally :l - if (ienum is Keys[]) + if (typeof(T) == typeof(Keys)) { - return string.Join(split, (Keys[])ienum); + return string.Join(split, ienum.ToArray()); } return string.Join(split, ienum); } + /*public static string ToSingular(this IEnumerable ienum, string split = ", ") + { + return string.Join(split, ienum); + }*/ + public static bool IsInt32(this object o) { int i; diff --git a/StardewModdingAPI/Inheritance/SBareObject.cs b/StardewModdingAPI/Inheritance/SBareObject.cs new file mode 100644 index 00000000..905dac0d --- /dev/null +++ b/StardewModdingAPI/Inheritance/SBareObject.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.AccessControl; +using System.Text; +using System.Threading.Tasks; + +namespace StardewModdingAPI.Inheritance +{ + public struct SBareObject + { + public int parentSheetIndex { get; set; } + public int stack { get; set; } + public bool isRecipe { get; set; } + public int price { get; set; } + public int quality { get; set; } + + public SBareObject(int psi, int sta, bool ir, int pri, int qua) + { + parentSheetIndex = psi; + stack = sta; + isRecipe = ir; + price = pri; + quality = qua; + } + } +} diff --git a/StardewModdingAPI/JsonResolver.cs b/StardewModdingAPI/JsonResolver.cs new file mode 100644 index 00000000..bd5831e0 --- /dev/null +++ b/StardewModdingAPI/JsonResolver.cs @@ -0,0 +1,215 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Design; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; +using Newtonsoft.Json.Linq; +using Newtonsoft.Json.Serialization; +using StardewModdingAPI.Inheritance; + +namespace StardewModdingAPI +{ + class JsonResolver : DefaultContractResolver + { + protected override JsonContract CreateContract(Type objectType) + { + if (objectType == typeof(Rectangle) || objectType == typeof(Rectangle?)) + { + Console.WriteLine("FOUND A RECT"); + JsonContract contract = base.CreateObjectContract(objectType); + contract.Converter = new RectangleConverter(); + return contract; + } + if (objectType == typeof(StardewValley.Object)) + { + Log.Verbose("FOUND AN OBJECT"); + JsonContract contract = base.CreateObjectContract(objectType); + contract.Converter = new ObjectConverter(); + return contract; + + } + return base.CreateContract(objectType); + } + } + + public class ObjectConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + Log.Verbose("TRYING TO WRITE"); + var obj = (StardewValley.Object)value; + Log.Verbose("TRYING TO WRITE"); + + var jObject = GetObject(obj); + Log.Verbose("TRYING TO WRITE"); + + try + { + Log.Verbose(jObject.ToString()); + } + catch (Exception ex) + { + Log.Error(ex); + } + + Console.ReadKey(); + + jObject.WriteTo(writer); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var jObject = JObject.Load(reader); + + return GetObject(jObject); + } + + public override bool CanConvert(Type objectType) + { + throw new NotImplementedException(); + } + + protected static JObject GetObject(StardewValley.Object o) + { + try + { + var parentSheetIndex = o.parentSheetIndex; + var stack = o.stack; + var isRecipe = o.isRecipe; + var price = o.price; + var quality = o.quality; + + var oo = new SBareObject(parentSheetIndex, stack, isRecipe, price, quality); + Log.Success(JsonConvert.SerializeObject(oo)); + return JObject.FromObject(oo); + } + catch (Exception ex) + { + Log.Error(ex); + Console.ReadKey(); + } + return null; + } + + protected static StardewValley.Object GetObject(JObject jObject) + { + int? parentSheetIndex = GetTokenValue(jObject, "parentSheetIndex") as int?; + int? stack = GetTokenValue(jObject, "parentSheetIndex") as int?; + bool? isRecipe = GetTokenValue(jObject, "parentSheetIndex") as bool?; + int? price = GetTokenValue(jObject, "parentSheetIndex") as int?; + int? quality = GetTokenValue(jObject, "parentSheetIndex") as int?; + + return new StardewValley.Object(parentSheetIndex ?? 0, stack ?? 0, isRecipe ?? false, price ?? -1, quality ?? 0); + } + + protected static StardewValley.Object GetObject(JToken jToken) + { + var jObject = JObject.FromObject(jToken); + + return GetObject(jObject); + } + + protected static T GetTokenValue(JObject jObject, string tokenName) where T : class + { + JToken jToken; + jObject.TryGetValue(tokenName, StringComparison.InvariantCultureIgnoreCase, out jToken); + return jToken as T; + } + } + + public class RectangleConverter : JsonConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var rectangle = (Rectangle)value; + + var jObject = GetObject(rectangle); + + jObject.WriteTo(writer); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + Console.WriteLine(reader.ReadAsString()); + var jObject = JObject.Load(reader); + + return GetRectangle(jObject); + } + + public override bool CanConvert(Type objectType) + { + throw new NotImplementedException(); + } + + protected static JObject GetObject(Rectangle rectangle) + { + var x = rectangle.X; + var y = rectangle.Y; + var width = rectangle.Width; + var height = rectangle.Height; + + return JObject.FromObject(new { x, y, width, height }); + } + + protected static Rectangle GetRectangle(JObject jObject) + { + var x = GetTokenValue(jObject, "x") ?? 0; + var y = GetTokenValue(jObject, "y") ?? 0; + var width = GetTokenValue(jObject, "width") ?? 0; + var height = GetTokenValue(jObject, "height") ?? 0; + + return new Rectangle(x, y, width, height); + } + + protected static Rectangle GetRectangle(JToken jToken) + { + var jObject = JObject.FromObject(jToken); + + return GetRectangle(jObject); + } + + protected static int? GetTokenValue(JObject jObject, string tokenName) + { + JToken jToken; + return jObject.TryGetValue(tokenName, StringComparison.InvariantCultureIgnoreCase, out jToken) ? (int)jToken : (int?)null; + } + } + + public class RectangleListConverter : RectangleConverter + { + public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) + { + var rectangleList = (IList)value; + + var jArray = new JArray(); + + foreach (var rectangle in rectangleList) + { + jArray.Add(GetObject(rectangle)); + } + + jArray.WriteTo(writer); + } + + public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) + { + var rectangleList = new List(); + + var jArray = JArray.Load(reader); + + foreach (var jToken in jArray) + { + rectangleList.Add(GetRectangle(jToken)); + } + + return rectangleList; + } + + public override bool CanConvert(Type objectType) + { + throw new NotImplementedException(); + } + } +} diff --git a/StardewModdingAPI/Log.cs b/StardewModdingAPI/Log.cs index c6294194..6c338edc 100644 --- a/StardewModdingAPI/Log.cs +++ b/StardewModdingAPI/Log.cs @@ -32,15 +32,9 @@ namespace StardewModdingAPI } } - /// - /// Print provided parameters to the console/file as applicable - /// - /// Desired message - /// When true, writes to ONLY console and not the log file. - /// Additional params to be added to the message - private static void PrintLog(object message, bool disableLogging, params object[] values) + private static void PrintLog(object message, bool disableLogging) { - string logOutput = $"[{DateTime.Now.ToLongTimeString()}] {string.Format(message.ToString(), values)}"; + string logOutput = $"[{DateTime.Now.ToLongTimeString()}] {message?.ToString()}"; Console.WriteLine(logOutput); if (_logStream != null && !disableLogging) @@ -50,15 +44,26 @@ namespace StardewModdingAPI } } + /// + /// Print provided parameters to the console/file as applicable + /// + /// Desired message + /// When true, writes to ONLY console and not the log file. + /// Deprecated. Does nothing. + private static void PrintLog(object message, bool disableLogging, params object[] values) + { + PrintLog(message, disableLogging); + } + /// /// Successful message to display to console and logging. /// /// - /// + /// Deprecated. Do not use. public static void Success(object message, params object[] values) { Console.ForegroundColor = ConsoleColor.Green; - PrintLog(message?.ToString(), false, values); + PrintLog(message?.ToString(), false); Console.ForegroundColor = ConsoleColor.Gray; } @@ -66,11 +71,11 @@ namespace StardewModdingAPI /// Generic comment to display to console and logging. /// /// - /// + /// Deprecated. Do not use. public static void Verbose(object message, params object[] values) { Console.ForegroundColor = ConsoleColor.Gray; - PrintLog(message?.ToString(), false, values); + PrintLog(message?.ToString(), false); Console.ForegroundColor = ConsoleColor.Gray; } @@ -78,11 +83,11 @@ namespace StardewModdingAPI /// Additional comment to display to console and logging. /// /// - /// + /// Deprecated. Do not use. public static void Comment(object message, params object[] values) { Console.ForegroundColor = ConsoleColor.Yellow; - PrintLog(message?.ToString(), false, values); + PrintLog(message?.ToString(), false); Console.ForegroundColor = ConsoleColor.Gray; } @@ -90,11 +95,11 @@ namespace StardewModdingAPI /// Message for only console. Does not appear in logging. /// /// - /// + /// Deprecated. Do not use. public static void Info(object message, params object[] values) { Console.ForegroundColor = ConsoleColor.Gray; - PrintLog(message?.ToString(), true, values); + PrintLog(message?.ToString(), true); Console.ForegroundColor = ConsoleColor.Gray; } @@ -102,11 +107,11 @@ namespace StardewModdingAPI /// Important message indicating an error. /// /// - /// + /// Deprecated. Do not use. public static void Error(object message, params object[] values) { Console.ForegroundColor = ConsoleColor.Red; - PrintLog(message?.ToString(), false, values); + PrintLog(message?.ToString(), false); Console.ForegroundColor = ConsoleColor.Gray; } @@ -114,12 +119,12 @@ namespace StardewModdingAPI /// A message displayed only while in DEBUG mode /// /// - /// + /// Deprecated. Do not use. public static void Debug(object message, params object[] values) { #if DEBUG Console.ForegroundColor = ConsoleColor.Yellow; - Log.PrintLog(message.ToString(), false, values); + Log.PrintLog(message.ToString(), false); Console.ForegroundColor = ConsoleColor.Gray; #endif } diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index a2dd442a..76ebd86c 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -149,7 +149,9 @@ + + -- cgit From 36fb605a7c5262a04e2752c55ae97093d26c1a73 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sat, 26 Mar 2016 21:50:47 -0400 Subject: uhhhhhh. async logging. an event i think. something or other. mid-update commit. --- StardewModdingAPI/Constants.cs | 11 +- StardewModdingAPI/Events/EventArgs.cs | 10 ++ StardewModdingAPI/Events/Graphics.cs | 8 +- StardewModdingAPI/Events/Mine.cs | 6 +- StardewModdingAPI/Inheritance/SGame.cs | 55 +++++++-- StardewModdingAPI/Log.cs | 181 ----------------------------- StardewModdingAPI/Program.cs | 40 ++++--- StardewModdingAPI/StardewModdingAPI.csproj | 2 +- 8 files changed, 99 insertions(+), 214 deletions(-) delete mode 100644 StardewModdingAPI/Log.cs (limited to 'StardewModdingAPI') diff --git a/StardewModdingAPI/Constants.cs b/StardewModdingAPI/Constants.cs index a29e5fa8..109f22f8 100644 --- a/StardewModdingAPI/Constants.cs +++ b/StardewModdingAPI/Constants.cs @@ -42,13 +42,20 @@ namespace StardewModdingAPI /// Path for log files to be output to. /// %LocalAppData%//StardewValley//ErrorLogs /// - public static string LogPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs"); + public static string LogDir => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "StardewValley", "ErrorLogs"); + public static string LogPath => Path.Combine(LogDir, "MODDED_ProgramLog.Log_LATEST.txt"); - public static readonly Version Version = new Version(0, 39, 2, "Alpha"); + public static readonly Version Version = new Version(0, 39, 3, "Alpha"); /// /// Not quite "constant", but it makes more sense for it to be here, at least for now /// public static int ModsLoaded = 0; + + /// + /// Whether or not to enable the Render Target drawing code offered by ClxS + /// Do not mark as 'const' or else 'if' checks will complain that the expression is always true in ReSharper + /// + public static bool EnableDrawingIntoRenderTarget => true; } } diff --git a/StardewModdingAPI/Events/EventArgs.cs b/StardewModdingAPI/Events/EventArgs.cs index a6de3597..59fa1bbd 100644 --- a/StardewModdingAPI/Events/EventArgs.cs +++ b/StardewModdingAPI/Events/EventArgs.cs @@ -108,6 +108,16 @@ namespace StardewModdingAPI.Events } public List NewLocations { get; private set; } } + public class EventArgsMineLevelChanged : EventArgs + { + public EventArgsMineLevelChanged(int previousMineLevel, int currentMineLevel) + { + PreviousMineLevel = previousMineLevel; + CurrentMineLevel = currentMineLevel; + } + public int PreviousMineLevel { get; private set; } + public int CurrentMineLevel { get; private set; } + } public class EventArgsLocationObjectsChanged : EventArgs { diff --git a/StardewModdingAPI/Events/Graphics.cs b/StardewModdingAPI/Events/Graphics.cs index 87ee845b..db963924 100644 --- a/StardewModdingAPI/Events/Graphics.cs +++ b/StardewModdingAPI/Events/Graphics.cs @@ -6,6 +6,7 @@ namespace StardewModdingAPI.Events { public static event EventHandler Resize = delegate { }; public static event EventHandler DrawTick = delegate { }; + public static event EventHandler DrawInRenderTargetTick = delegate { }; public static void InvokeDrawTick() { @@ -15,10 +16,15 @@ namespace StardewModdingAPI.Events } catch (Exception ex) { - Log.Error("An exception occured in XNA DrawTick: " + ex); + Log.Error("An exception occured in a Mod's DrawTick: " + ex); } } + public static void InvokeDrawInRenderTargetTick() + { + DrawInRenderTargetTick.Invoke(null, EventArgs.Empty); + } + public static void InvokeResize(object sender, EventArgs e) { Resize.Invoke(sender, e); diff --git a/StardewModdingAPI/Events/Mine.cs b/StardewModdingAPI/Events/Mine.cs index 2f4e9ba7..f48e9574 100644 --- a/StardewModdingAPI/Events/Mine.cs +++ b/StardewModdingAPI/Events/Mine.cs @@ -4,11 +4,11 @@ namespace StardewModdingAPI.Events { public static class MineEvents { - public static event EventHandler MineLevelChanged = delegate { }; + public static event EventHandler MineLevelChanged = delegate { }; - public static void InvokeLocationsChanged(int currentMineLevel) + public static void InvokeMineLevelChanged(int previousMinelevel, int currentMineLevel) { - + MineLevelChanged.Invoke(null, new EventArgsMineLevelChanged(previousMinelevel, currentMineLevel)); } } } diff --git a/StardewModdingAPI/Inheritance/SGame.cs b/StardewModdingAPI/Inheritance/SGame.cs index da6260be..ce2488d5 100644 --- a/StardewModdingAPI/Inheritance/SGame.cs +++ b/StardewModdingAPI/Inheritance/SGame.cs @@ -32,15 +32,10 @@ namespace StardewModdingAPI.Inheritance public Keys[] CurrentlyPressedKeys => KStateNow.GetPressedKeys(); public Keys[] PreviouslyPressedKeys => KStatePrior.GetPressedKeys(); - public Keys[] FramePressedKeys - { - get { return CurrentlyPressedKeys.Except(PreviouslyPressedKeys).ToArray(); } - } - public Keys[] FrameReleasedKeys - { - get { return PreviouslyPressedKeys.Except(CurrentlyPressedKeys).ToArray(); } - } - + public Keys[] FramePressedKeys => CurrentlyPressedKeys.Except(PreviouslyPressedKeys).ToArray(); + + public Keys[] FrameReleasedKeys => PreviouslyPressedKeys.Except(CurrentlyPressedKeys).ToArray(); + public Buttons[][] PreviouslyPressedButtons; private bool WasButtonJustPressed(Buttons button, ButtonState buttonState, PlayerIndex stateIndex) @@ -161,6 +156,8 @@ namespace StardewModdingAPI.Inheritance public GameLocation PreviousGameLocation { get; private set; } public IClickableMenu PreviousActiveMenu { get; private set; } + public int PreviousMineLevel { get; private set; } + public Int32 PreviousTimeOfDay { get; private set; } public Int32 PreviousDayOfMonth { get; private set; } public String PreviousSeasonOfYear { get; private set; } @@ -282,6 +279,40 @@ namespace StardewModdingAPI.Inheritance GraphicsEvents.InvokeDrawTick(); + if (Constants.EnableDrawingIntoRenderTarget) + { + if (!options.zoomLevel.Equals(1.0f)) + { + if (Screen.RenderTargetUsage == RenderTargetUsage.DiscardContents) + { + Screen = new RenderTarget2D(graphics.GraphicsDevice, Math.Min(4096, (int) (Window.ClientBounds.Width * (1.0 / options.zoomLevel))), + Math.Min(4096, (int) (Window.ClientBounds.Height * (1.0 / options.zoomLevel))), + false, SurfaceFormat.Color, DepthFormat.Depth16, 1, RenderTargetUsage.PreserveContents); + } + GraphicsDevice.SetRenderTarget(Screen); + } + + // Not beginning the batch due to inconsistancies with the standard draw tick... + //spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + + GraphicsEvents.InvokeDrawInRenderTargetTick(); + + //spriteBatch.End(); + + if (!options.zoomLevel.Equals(1.0f)) + { + GraphicsDevice.SetRenderTarget(null); + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone); + spriteBatch.Draw(Screen, Vector2.Zero, Screen.Bounds, Color.White, 0.0f, Vector2.Zero, options.zoomLevel, SpriteEffects.None, 1f); + spriteBatch.End(); + } + + //Re-draw the mouse + spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); + spriteBatch.Draw(mouseCursors, new Vector2(getMouseX(), getMouseY()), getSourceRectForStandardTileSheet(mouseCursors, mouseCursor, 16, 16), Color.White * mouseCursorTransparency, 0.0f, Vector2.Zero, pixelZoom + dialogueButtonScale / 150f, SpriteEffects.None, 1f); + spriteBatch.End(); + } + if (Debug) { spriteBatch.Begin(); @@ -490,6 +521,12 @@ namespace StardewModdingAPI.Inheritance FireLoadedGameEvent = true; PreviouslyLoadedGame = hasLoadedGame; } + + if (mine != null && PreviousMineLevel != mine.mineLevel) + { + MineEvents.InvokeMineLevelChanged(PreviousMineLevel, mine.mineLevel); + PreviousMineLevel = mine.mineLevel; + } } private bool HasInventoryChanged(List items, out List changedItems) diff --git a/StardewModdingAPI/Log.cs b/StardewModdingAPI/Log.cs deleted file mode 100644 index 6c338edc..00000000 --- a/StardewModdingAPI/Log.cs +++ /dev/null @@ -1,181 +0,0 @@ -using System; -using System.IO; -using System.Threading; - -namespace StardewModdingAPI -{ - - /// - /// Class to organize logging calls. - /// - public class Log - { - private static StreamWriter _logStream; - private static string _logPath; - - /// - /// Set up the logging stream - /// - /// - public static void Initialize(string logPath) - { - _logPath = logPath; - var logFile = string.Format("{0}\\MODDED_ProgramLog.Log_LATEST.txt", logPath); - try - { - _logStream = new StreamWriter(logFile, false); - } - catch (Exception) - { - // TODO: not use general exception - Error("Could not initialize LogStream - Logging is disabled"); - } - } - - private static void PrintLog(object message, bool disableLogging) - { - string logOutput = $"[{DateTime.Now.ToLongTimeString()}] {message?.ToString()}"; - Console.WriteLine(logOutput); - - if (_logStream != null && !disableLogging) - { - _logStream.WriteLine(logOutput); - _logStream.Flush(); - } - } - - /// - /// Print provided parameters to the console/file as applicable - /// - /// Desired message - /// When true, writes to ONLY console and not the log file. - /// Deprecated. Does nothing. - private static void PrintLog(object message, bool disableLogging, params object[] values) - { - PrintLog(message, disableLogging); - } - - /// - /// Successful message to display to console and logging. - /// - /// - /// Deprecated. Do not use. - public static void Success(object message, params object[] values) - { - Console.ForegroundColor = ConsoleColor.Green; - PrintLog(message?.ToString(), false); - Console.ForegroundColor = ConsoleColor.Gray; - } - - /// - /// Generic comment to display to console and logging. - /// - /// - /// Deprecated. Do not use. - public static void Verbose(object message, params object[] values) - { - Console.ForegroundColor = ConsoleColor.Gray; - PrintLog(message?.ToString(), false); - Console.ForegroundColor = ConsoleColor.Gray; - } - - /// - /// Additional comment to display to console and logging. - /// - /// - /// Deprecated. Do not use. - public static void Comment(object message, params object[] values) - { - Console.ForegroundColor = ConsoleColor.Yellow; - PrintLog(message?.ToString(), false); - Console.ForegroundColor = ConsoleColor.Gray; - } - - /// - /// Message for only console. Does not appear in logging. - /// - /// - /// Deprecated. Do not use. - public static void Info(object message, params object[] values) - { - Console.ForegroundColor = ConsoleColor.Gray; - PrintLog(message?.ToString(), true); - Console.ForegroundColor = ConsoleColor.Gray; - } - - /// - /// Important message indicating an error. - /// - /// - /// Deprecated. Do not use. - public static void Error(object message, params object[] values) - { - Console.ForegroundColor = ConsoleColor.Red; - PrintLog(message?.ToString(), false); - Console.ForegroundColor = ConsoleColor.Gray; - } - - /// - /// A message displayed only while in DEBUG mode - /// - /// - /// Deprecated. Do not use. - public static void Debug(object message, params object[] values) - { -#if DEBUG - Console.ForegroundColor = ConsoleColor.Yellow; - Log.PrintLog(message.ToString(), false); - Console.ForegroundColor = ConsoleColor.Gray; -#endif - } - - /// - /// Catch unhandled exception from the application - /// - /// Should be moved out of here if we do more than just log the exception. - public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) - { - Console.WriteLine("An exception has been caught"); - File.WriteAllText(_logPath + "\\MODDED_ErrorLog.Log_" + DateTime.UtcNow.Ticks + ".txt", e.ExceptionObject.ToString()); - } - - /// - /// Catch thread exception from the application - /// - /// Should be moved out of here if we do more than just log the exception. - public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) - { - Console.WriteLine("A thread exception has been caught"); - File.WriteAllText(_logPath + "\\MODDED_ErrorLog.Log_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString()); - } - - // I'm including the following for now because they have a lot of references with different uses. - // They should be removed since they do not provide any insight into actual problems, and other log methods should be used. - - public static void LogValueNotSpecified() - { - Error(" must be specified"); - } - - public static void LogObjectValueNotSpecified() - { - Error(" and must be specified"); - } - - public static void LogValueInvalid() - { - Error(" is invalid"); - } - - public static void LogObjectInvalid() - { - Error(" is invalid"); - } - - public static void LogValueNotInt32() - { - Error(" must be a whole number (Int32)"); - } - - } -} diff --git a/StardewModdingAPI/Program.cs b/StardewModdingAPI/Program.cs index 4d1d23d1..05da664c 100644 --- a/StardewModdingAPI/Program.cs +++ b/StardewModdingAPI/Program.cs @@ -59,6 +59,8 @@ namespace StardewModdingAPI catch (Exception e) { // Catch and display all exceptions. + Console.WriteLine(e); + Console.ReadKey(); Log.Error("Critical error: " + e); } @@ -99,9 +101,7 @@ namespace StardewModdingAPI //Checks that all defined modpaths exist as directories _modPaths.ForEach(path => VerifyPath(path)); //_modContentPaths.ForEach(path => VerifyPath(path)); - VerifyPath(Constants.LogPath); - - Log.Initialize(Constants.LogPath); + VerifyPath(Constants.LogDir); if (!File.Exists(Constants.ExecutionPath + "\\Stardew Valley.exe")) { @@ -267,7 +267,7 @@ namespace StardewModdingAPI string t = File.ReadAllText(s); if (string.IsNullOrEmpty(t)) { - Log.Error("Failed to read mod manifest '{0}'. Manifest is empty!", s); + Log.Error($"Failed to read mod manifest '{s}'. Manifest is empty!"); continue; } @@ -275,41 +275,47 @@ namespace StardewModdingAPI if (string.IsNullOrEmpty(manifest.EntryDll)) { - Log.Error("Failed to read mod manifest '{0}'. EntryDll is empty!", s); + Log.Error($"Failed to read mod manifest '{s}'. EntryDll is empty!"); continue; } } catch (Exception ex) { - Log.Error("Failed to read mod manifest '{0}'. Exception details:\n" + ex, s); + Log.Error($"Failed to read mod manifest '{s}'. Exception details:\n" + ex); continue; } + string targDir = Path.GetDirectoryName(s); + string psDir = Path.Combine(targDir, "psconfigs"); + Log.Info($"Created psconfigs directory @{psDir}"); try { if (manifest.PerSaveConfigs) { - if (!Directory.Exists(Path.GetDirectoryName(s))) - Directory.CreateDirectory(Path.GetDirectoryName(s)); + if (!Directory.Exists(psDir)) + { + Directory.CreateDirectory(psDir); + Log.Info($"Created psconfigs directory @{psDir}"); + } - if (!Directory.Exists(Path.GetDirectoryName(s))) + if (!Directory.Exists(psDir)) { - Log.Error("Failed to create psconfigs directory '{0}'. No exception occured.", Path.GetDirectoryName(s)); + Log.Error($"Failed to create psconfigs directory '{psDir}'. No exception occured."); continue; } } } catch (Exception ex) { - Log.Error("Failed to create psconfigs directory '{0}'. Exception details:\n" + ex, Path.GetDirectoryName(s)); + Log.Error($"Failed to create psconfigs directory '{targDir}'. Exception details:\n" + ex); continue; } string targDll = string.Empty; try { - targDll = Path.Combine(Path.GetDirectoryName(s), manifest.EntryDll); + targDll = Path.Combine(targDir, manifest.EntryDll); if (!File.Exists(targDll)) { - Log.Error("Failed to load mod '{0}'. File {1} does not exist!", manifest.EntryDll, targDll); + Log.Error($"Failed to load mod '{manifest.EntryDll}'. File {targDll} does not exist!"); continue; } @@ -320,9 +326,9 @@ namespace StardewModdingAPI Log.Verbose("Loading Mod DLL..."); TypeInfo tar = mod.DefinedTypes.First(x => x.BaseType == typeof (Mod)); Mod m = (Mod) mod.CreateInstance(tar.ToString()); - m.PathOnDisk = Path.GetDirectoryName(s); + m.PathOnDisk = targDir; m.Manifest = manifest; - Log.Success("LOADED MOD: {0} by {1} - Version {2} | Description: {3} (@ {4})", m.Manifest.Name, m.Manifest.Authour, m.Manifest.Version, m.Manifest.Description, targDll); + Log.Success($"LOADED MOD: {m.Manifest.Name} by {m.Manifest.Authour} - Version {m.Manifest.Version} | Description: {m.Manifest.Description} (@ {targDll})"); Constants.ModsLoaded += 1; m.Entry(); } @@ -333,12 +339,12 @@ namespace StardewModdingAPI } catch (Exception ex) { - Log.Error("Failed to load mod '{0}'. Exception details:\n" + ex, targDll); + Log.Error($"Failed to load mod '{targDll}'. Exception details:\n" + ex); } } } } - Log.Success("LOADED {0} MODS", Constants.ModsLoaded); + Log.Success($"LOADED {Constants.ModsLoaded} MODS"); Console.Title = Constants.ConsoleTitle; } diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index 76ebd86c..d60e2544 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -152,7 +152,7 @@ - + -- cgit From 6f64d448f937a9a2abab4a75e81491410ddbf226 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sat, 26 Mar 2016 21:57:00 -0400 Subject: commit --- StardewModdingAPI/Logger.cs | 298 +++++++++++++++++++++++++++++ StardewModdingAPI/StardewModdingAPI.csproj | 1 + 2 files changed, 299 insertions(+) create mode 100644 StardewModdingAPI/Logger.cs (limited to 'StardewModdingAPI') diff --git a/StardewModdingAPI/Logger.cs b/StardewModdingAPI/Logger.cs new file mode 100644 index 00000000..5f758994 --- /dev/null +++ b/StardewModdingAPI/Logger.cs @@ -0,0 +1,298 @@ +using System; +using System.Collections; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Configuration; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using StardewModdingAPI; + +namespace StardewModdingAPI +{ + public static class Log + { + private static readonly LogWriter _writer; + + static Log() + { + _writer = LogWriter.Instance; + } + + private static void PrintLog(LogInfo li) + { + _writer.WriteToLog(li); + } + + #region Sync Logging + + /// + /// NOTICE: Sync logging is discouraged. Please use Async instead. + /// + /// Message to log + /// Colour of message + public static void SyncColour(object message, ConsoleColor colour) + { + PrintLog(new LogInfo(message?.ToString(), colour)); + } + + #endregion + + #region Async Logging + + public static void AsyncColour(object message, ConsoleColor colour) + { + Task.Run(() => { + PrintLog(new LogInfo(message?.ToString(), colour)); + }); + } + + public static void Async(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Gray); + } + + public static void AsyncR(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Red); + } + + public static void AsyncO(object message) + { + AsyncColour(message.ToString(), ConsoleColor.DarkYellow); + } + + public static void AsyncY(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Yellow); + } + + public static void AsyncG(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Green); + } + + public static void AsyncC(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Cyan); + } + + public static void AsyncM(object message) + { + AsyncColour(message?.ToString(), ConsoleColor.Magenta); + } + + #endregion + + + + + + /// + /// Catch unhandled exception from the application + /// + /// Should be moved out of here if we do more than just log the exception. + public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Console.WriteLine("An exception has been caught"); + File.WriteAllText(Constants.LogDir + "\\MODDED_ErrorLog.Log_" + DateTime.UtcNow.Ticks + ".txt", e.ExceptionObject.ToString()); + } + + /// + /// Catch thread exception from the application + /// + /// Should be moved out of here if we do more than just log the exception. + public static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) + { + Console.WriteLine("A thread exception has been caught"); + File.WriteAllText(Constants.LogDir + "\\MODDED_ErrorLog.Log_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.Exception.ToString()); + } + + #region ToRemove + + public static void LogValueNotSpecified() + { + Error(" must be specified"); + } + + public static void LogObjectValueNotSpecified() + { + Error(" and must be specified"); + } + + public static void LogValueInvalid() + { + Error(" is invalid"); + } + + public static void LogObjectInvalid() + { + Error(" is invalid"); + } + + public static void LogValueNotInt32() + { + Error(" must be a whole number (Int32)"); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + private static void PrintLog(object message, bool disableLogging, params object[] values) + { + PrintLog(new LogInfo(message?.ToString())); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Success(object message, params object[] values) + { + AsyncG(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Verbose(object message, params object[] values) + { + Async(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Comment(object message, params object[] values) + { + AsyncC(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Info(object message, params object[] values) + { + AsyncY(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Error(object message, params object[] values) + { + AsyncR(message); + } + + [Obsolete("Parameter 'values' is no longer supported. Format before logging.")] + public static void Debug(object message, params object[] values) + { + AsyncO(message); + } + + #endregion + } + + /// + /// A Logging class implementing the Singleton pattern and an internal Queue to be flushed perdiodically + /// + public class LogWriter + { + private static LogWriter _instance; + private static ConcurrentQueue _logQueue; + private static DateTime _lastFlushTime = DateTime.Now; + private static StreamWriter _stream; + + /// + /// Private to prevent creation of other instances + /// + private LogWriter() { } + + /// + /// Exposes _instace and creates a new one if it is null + /// + internal static LogWriter Instance + { + get + { + if (_instance == null) + { + _instance = new LogWriter(); + // Field cannot be used by anything else regardless, do not surround with lock { } + // ReSharper disable once InconsistentlySynchronizedField + _logQueue = new ConcurrentQueue(); + Console.WriteLine(Constants.LogPath); + _stream = new StreamWriter(Constants.LogPath, false); + Console.WriteLine("Created log instance"); + } + return _instance; + } + } + + /// + /// Writes into the ConcurrentQueue the Message specified + /// + /// The message to write to the log + public void WriteToLog(string message) + { + lock (_logQueue) + { + LogInfo logEntry = new LogInfo(message); + _logQueue.Enqueue(logEntry); + + if (_logQueue.Any()) + { + FlushLog(); + } + } + } + + /// + /// Writes into the ConcurrentQueue the Entry specified + /// + /// The logEntry to write to the log + public void WriteToLog(LogInfo logEntry) + { + lock (_logQueue) + { + _logQueue.Enqueue(logEntry); + + if (_logQueue.Any()) + { + FlushLog(); + } + } + } + + /// + /// Flushes the ConcurrentQueue to the log file specified in Constants + /// + private void FlushLog() + { + lock (_stream) + { + LogInfo entry; + while (_logQueue.TryDequeue(out entry)) + { + string m = $"[{entry.LogTime}] {entry.Message}"; + + Console.ForegroundColor = entry.Colour; + Console.WriteLine(m); + Console.ForegroundColor = ConsoleColor.Gray; + + _stream.WriteLine(m); + } + _stream.Flush(); + } + } + } + + /// + /// A struct to store the message and the Date and Time the log entry was created + /// + public struct LogInfo + { + public string Message { get; set; } + public string LogTime { get; set; } + public string LogDate { get; set; } + public ConsoleColor Colour { get; set; } + + public LogInfo(string message, ConsoleColor colour = ConsoleColor.Gray) + { + if (string.IsNullOrEmpty(message)) + message = "[null]"; + Message = message; + LogDate = DateTime.Now.ToString("yyyy-MM-dd"); + LogTime = DateTime.Now.ToString("hh:mm:ss.fff tt"); + Colour = colour; + } + } +} \ No newline at end of file diff --git a/StardewModdingAPI/StardewModdingAPI.csproj b/StardewModdingAPI/StardewModdingAPI.csproj index d60e2544..913fb50e 100644 --- a/StardewModdingAPI/StardewModdingAPI.csproj +++ b/StardewModdingAPI/StardewModdingAPI.csproj @@ -79,6 +79,7 @@ true true + bin\x86\Debug\StardewModdingAPI.XML x86 -- cgit From 12bf4fd843be26f89b5fe3415aeec3055c54d786 Mon Sep 17 00:00:00 2001 From: Zoryn Aaron Date: Sun, 27 Mar 2016 01:09:09 -0400 Subject: someone needs to generate xml doc info im not fuck that shit --- StardewModdingAPI/App.config | 17 +- StardewModdingAPI/Command.cs | 63 +-- StardewModdingAPI/Config.cs | 55 +-- StardewModdingAPI/Constants.cs | 35 +- StardewModdingAPI/Entities/SCharacter.cs | 4 +- StardewModdingAPI/Entities/SFarm.cs | 4 +- StardewModdingAPI/Entities/SFarmAnimal.cs | 4 +- StardewModdingAPI/Entities/SNpc.cs | 4 +- StardewModdingAPI/Entities/SPlayer.cs | 50 +- StardewModdingAPI/Events/Controls.cs | 2 +- StardewModdingAPI/Events/EventArgs.cs | 47 +- StardewModdingAPI/Events/Game.cs | 29 +- StardewModdingAPI/Events/Graphics.cs | 4 +- StardewModdingAPI/Events/Location.cs | 4 +- StardewModdingAPI/Events/Menu.cs | 2 +- StardewModdingAPI/Events/Mine.cs | 2 +- StardewModdingAPI/Events/Player.cs | 2 +- StardewModdingAPI/Events/Time.cs | 10 +- StardewModdingAPI/Extensions.cs | 28 +- StardewModdingAPI/Inheritance/ItemStackChange.cs | 2 +- StardewModdingAPI/Inheritance/Menus/SBobberBar.cs | 29 +- StardewModdingAPI/Inheritance/Menus/SGameMenu.cs | 14 +- .../Inheritance/Menus/SInventoryPage.cs | 12 +- .../Inheritance/Minigames/SMinigameBase.cs | 4 +- StardewModdingAPI/Inheritance/SBareObject.cs | 11 +- StardewModdingAPI/Inheritance/SGame.cs | 397 +++++++++++---- StardewModdingAPI/Inheritance/SObject.cs | 538 +++++++++++---------- StardewModdingAPI/JsonResolver.cs | 61 ++- StardewModdingAPI/Logger.cs | 86 ++-- StardewModdingAPI/Manifest.cs | 16 +- StardewModdingAPI/Mod.cs | 24 +- StardewModdingAPI/ModItem.cs | 10 +- StardewModdingAPI/Program.cs | 149 +++--- StardewModdingAPI/Properties/AssemblyInfo.cs | 6 +- StardewModdingAPI/Version.cs | 9 +- StardewModdingAPI/packages.config | 1 + 36 files changed, 964 insertions(+), 771 deletions(-) (limited to 'StardewModdingAPI') diff --git a/StardewModdingAPI/App.config b/StardewModdingAPI/App.config index 697c237b..dc6eaae3 100644 --- a/StardewModdingAPI/App.config +++ b/StardewModdingAPI/App.config @@ -1,9 +1,10 @@ - + + - - - - - - - + + + + + + + \ No newline at end of file diff --git a/StardewModdingAPI/Command.cs b/StardewModdingAPI/Command.cs index 7cf2b67b..8bc2c0c3 100644 --- a/StardewModdingAPI/Command.cs +++ b/StardewModdingAPI/Command.cs @@ -7,27 +7,43 @@ namespace StardewModdingAPI public class Command { internal static List RegisteredCommands = new List(); + public string[] CalledArgs; + public string[] CommandArgs; + public string CommandDesc; + + public string CommandName; + + /// + /// Creates a Command from a Name, Description, and Arguments + /// + /// Name + /// Description + /// Arguments + public Command(string cname, string cdesc, string[] args = null) + { + CommandName = cname; + CommandDesc = cdesc; + if (args == null) + args = new string[0]; + CommandArgs = args; + } - public String CommandName; - public String CommandDesc; - public String[] CommandArgs; - public String[] CalledArgs; public event EventHandler CommandFired; /// - /// Calls the specified command. (It runs the command) + /// Calls the specified command. (It runs the command) /// /// The command to run public static void CallCommand(string input) { input = input.TrimEnd(' '); - string[] args = new string[0]; + var args = new string[0]; Command fnd; if (input.Contains(" ")) { args = input.Split(new[] {" "}, 2, StringSplitOptions.RemoveEmptyEntries); fnd = FindCommand(args[0]); - args = args[1].Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); + args = args[1].Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries); } else { @@ -41,12 +57,12 @@ namespace StardewModdingAPI } else { - Log.Error("Unknown Command"); + Log.AsyncR("Unknown Command"); } } /// - /// Registers a command to the list of commands properly + /// Registers a command to the list of commands properly /// /// Name of the command to register /// Description @@ -54,21 +70,21 @@ namespace StardewModdingAPI /// public static Command RegisterCommand(string command, string cdesc, string[] args = null) { - Command c = new Command(command, cdesc, args); + var c = new Command(command, cdesc, args); if (RegisteredCommands.Contains(c)) { - Log.Error("Command already registered! [{0}]", c.CommandName); + Log.AsyncR($"Command already registered! [{c.CommandName}]"); return RegisteredCommands.Find(x => x.Equals(c)); } RegisteredCommands.Add(c); - Log.Verbose("Registered command: " + command); + Log.AsyncY("Registered command: " + command); return c; } /// - /// Looks up a command in the list of registered commands. Returns null if it doesn't exist (I think) + /// Looks up a command in the list of registered commands. Returns null if it doesn't exist (I think) /// /// Name of command to find /// @@ -78,31 +94,16 @@ namespace StardewModdingAPI } /// - /// Creates a Command from a Name, Description, and Arguments - /// - /// Name - /// Description - /// Arguments - public Command(String cname, String cdesc, String[] args = null) - { - CommandName = cname; - CommandDesc = cdesc; - if (args == null) - args = new string[0]; - CommandArgs = args; - } - - /// - /// Runs a command. Fires it. Calls it. Any of those. + /// Runs a command. Fires it. Calls it. Any of those. /// public void Fire() { if (CommandFired == null) { - Log.Error("Command failed to fire because it's fire event is null: " + CommandName); + Log.AsyncR("Command failed to fire because it's fire event is null: " + CommandName); return; } CommandFired.Invoke(this, new EventArgsCommand(this)); } } -} +} \ No newline at end of file diff --git a/StardewModdingAPI/Config.cs b/StardewModdingAPI/Config.cs index d5517535..035d28d7 100644 --- a/StardewModdingAPI/Config.cs +++ b/StardewModdingAPI/Config.cs @@ -5,7 +5,6 @@ using System; using System.IO; using System.Linq; -using System.Reflection; using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -22,15 +21,7 @@ namespace StardewModdingAPI public virtual Config Instance() where T : Config => Activator.CreateInstance(); /// - /// Should never be used for anything. - /// - public Config() - { - - } - - /// - /// Loads the config from the json blob on disk, updating and re-writing to the disk if needed. + /// Loads the config from the json blob on disk, updating and re-writing to the disk if needed. /// /// /// @@ -38,7 +29,7 @@ namespace StardewModdingAPI { if (string.IsNullOrEmpty(ConfigLocation)) { - Log.Error("A config tried to load without specifying a location on the disk."); + Log.AsyncR("A config tried to load without specifying a location on the disk."); return null; } @@ -47,7 +38,7 @@ namespace StardewModdingAPI if (!File.Exists(ConfigLocation)) { //no config exists, generate default values - var c = this.GenerateDefaultConfig(); + var c = GenerateDefaultConfig(); c.ConfigLocation = ConfigLocation; ret = c; } @@ -56,7 +47,7 @@ namespace StardewModdingAPI try { //try to load the config from a json blob on disk - T c = JsonConvert.DeserializeObject(File.ReadAllText(ConfigLocation), new JsonSerializerSettings() {ContractResolver = new JsonResolver()}); + var c = JsonConvert.DeserializeObject(File.ReadAllText(ConfigLocation), new JsonSerializerSettings {ContractResolver = new JsonResolver()}); c.ConfigLocation = ConfigLocation; @@ -67,7 +58,7 @@ namespace Starde