summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'src/StardewModdingAPI/Framework')
-rw-r--r--src/StardewModdingAPI/Framework/AssemblyLoader.cs2
-rw-r--r--src/StardewModdingAPI/Framework/InternalExtensions.cs12
-rw-r--r--src/StardewModdingAPI/Framework/Monitor.cs5
-rw-r--r--src/StardewModdingAPI/Framework/SGame.cs26
4 files changed, 17 insertions, 28 deletions
diff --git a/src/StardewModdingAPI/Framework/AssemblyLoader.cs b/src/StardewModdingAPI/Framework/AssemblyLoader.cs
index f6fe89f5..2c9973c1 100644
--- a/src/StardewModdingAPI/Framework/AssemblyLoader.cs
+++ b/src/StardewModdingAPI/Framework/AssemblyLoader.cs
@@ -284,7 +284,7 @@ namespace StardewModdingAPI.Framework
{
if (!hash.Contains(message))
{
- this.Monitor.Log(message, level);
+ monitor.Log(message, level);
hash.Add(message);
}
}
diff --git a/src/StardewModdingAPI/Framework/InternalExtensions.cs b/src/StardewModdingAPI/Framework/InternalExtensions.cs
index 4ca79518..a2d589ff 100644
--- a/src/StardewModdingAPI/Framework/InternalExtensions.cs
+++ b/src/StardewModdingAPI/Framework/InternalExtensions.cs
@@ -39,7 +39,7 @@ namespace StardewModdingAPI.Framework
if (handlers == null)
return;
- foreach (EventHandler handler in Enumerable.Cast<EventHandler>(handlers))
+ foreach (EventHandler handler in handlers.Cast<EventHandler>())
{
try
{
@@ -64,7 +64,7 @@ namespace StardewModdingAPI.Framework
if (handlers == null)
return;
- foreach (EventHandler<TEventArgs> handler in Enumerable.Cast<EventHandler<TEventArgs>>(handlers))
+ foreach (EventHandler<TEventArgs> handler in handlers.Cast<EventHandler<TEventArgs>>())
{
try
{
@@ -85,14 +85,14 @@ namespace StardewModdingAPI.Framework
public static string GetLogSummary(this Exception exception)
{
// type load exception
- if (exception is TypeLoadException)
- return $"Failed loading type: {((TypeLoadException)exception).TypeName}: {exception}";
+ if (exception is TypeLoadException typeLoadEx)
+ return $"Failed loading type: {typeLoadEx.TypeName}: {exception}";
// reflection type load exception
- if (exception is ReflectionTypeLoadException)
+ if (exception is ReflectionTypeLoadException reflectionTypeLoadEx)
{
string summary = exception.ToString();
- foreach (Exception childEx in ((ReflectionTypeLoadException)exception).LoaderExceptions)
+ foreach (Exception childEx in reflectionTypeLoadEx.LoaderExceptions)
summary += $"\n\n{childEx.GetLogSummary()}";
return summary;
}
diff --git a/src/StardewModdingAPI/Framework/Monitor.cs b/src/StardewModdingAPI/Framework/Monitor.cs
index 64075f2f..76793bbf 100644
--- a/src/StardewModdingAPI/Framework/Monitor.cs
+++ b/src/StardewModdingAPI/Framework/Monitor.cs
@@ -21,7 +21,7 @@ namespace StardewModdingAPI.Framework
private readonly LogFileManager LogFile;
/// <summary>The maximum length of the <see cref="LogLevel"/> values.</summary>
- private static readonly int MaxLevelLength = (from level in Enumerable.Cast<LogLevel>(Enum.GetValues(typeof(LogLevel))) select level.ToString().Length).Max();
+ private static readonly int MaxLevelLength = (from level in Enum.GetValues(typeof(LogLevel)).Cast<LogLevel>() select level.ToString().Length).Max();
/// <summary>The console text color for each log level.</summary>
private static readonly Dictionary<LogLevel, ConsoleColor> Colors = new Dictionary<LogLevel, ConsoleColor>
@@ -71,6 +71,7 @@ namespace StardewModdingAPI.Framework
this.Source = source;
this.LogFile = logFile;
this.ConsoleManager = consoleManager;
+ this.RequestExit = requestExitDelegate;
}
/// <summary>Log a message for the player or developer.</summary>
@@ -129,6 +130,8 @@ namespace StardewModdingAPI.Framework
{
if (this.ConsoleManager.SupportsColor)
{
+ if (background.HasValue)
+ Console.BackgroundColor = background.Value;
Console.ForegroundColor = color;
Console.WriteLine(message);
Console.ResetColor();
diff --git a/src/StardewModdingAPI/Framework/SGame.cs b/src/StardewModdingAPI/Framework/SGame.cs
index c16bf1cf..b262d4dd 100644
--- a/src/StardewModdingAPI/Framework/SGame.cs
+++ b/src/StardewModdingAPI/Framework/SGame.cs
@@ -50,7 +50,7 @@ namespace StardewModdingAPI.Framework
** Game state
****/
/// <summary>Arrays of pressed controller buttons indexed by <see cref="PlayerIndex"/>.</summary>
- private Buttons[][] PreviouslyPressedButtons;
+ private readonly Buttons[][] PreviouslyPressedButtons = { new Buttons[0], new Buttons[0], new Buttons[0], new Buttons[0] };
/// <summary>A record of the keyboard state (i.e. the up/down state for each button) as of the latest tick.</summary>
private KeyboardState KStateNow;
@@ -186,17 +186,6 @@ namespace StardewModdingAPI.Framework
/****
** Intercepted methods & events
****/
- /// <summary>The method called during game launch after configuring XNA or MonoGame. The game window hasn't been opened by this point.</summary>
- protected override void Initialize()
- {
- this.PreviouslyPressedButtons = new Buttons[4][];
- for (var i = 0; i < 4; ++i)
- this.PreviouslyPressedButtons[i] = new Buttons[0];
-
- base.Initialize();
- GameEvents.InvokeInitialize(this.Monitor);
- }
-
/// <summary>Constructor a content manager to read XNB files.</summary>
/// <param name="serviceProvider">The service provider to use to locate services.</param>
/// <param name="rootDirectory">The root directory to search for content.</param>
@@ -205,13 +194,6 @@ namespace StardewModdingAPI.Framework
return new SContentManager(this.Content.ServiceProvider, this.Content.RootDirectory, this.Monitor);
}
- /// <summary>The method called before XNA or MonoGame loads or reloads graphics resources.</summary>
- protected override void LoadContent()
- {
- base.LoadContent();
- GameEvents.InvokeLoadContent(this.Monitor);
- }
-
/// <summary>The method called when the game is updating its state. This happens roughly 60 times per second.</summary>
/// <param name="gameTime">A snapshot of the game timing state.</param>
protected override void Update(GameTime gameTime)
@@ -234,7 +216,11 @@ namespace StardewModdingAPI.Framework
// raise game loaded
if (this.FirstUpdate)
+ {
+ GameEvents.InvokeInitialize(this.Monitor);
+ GameEvents.InvokeLoadContent(this.Monitor);
GameEvents.InvokeGameLoaded(this.Monitor);
+ }
// update SMAPI events
this.UpdateEventCalls();
@@ -1159,7 +1145,7 @@ namespace StardewModdingAPI.Framework
{
ControlEvents.InvokeMouseChanged(this.Monitor, this.MStatePrior, this.MStateNow, this.MPositionPrior, this.MPositionNow);
this.MStatePrior = this.MStateNow;
- this.MPositionPrior = this.MPositionPrior;
+ this.MPositionPrior = this.MPositionNow;
}
}