summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework/SGame.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-05-01 18:16:09 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-05-01 18:16:09 -0400
commitc8ad50dad1d706a1901798f9396f6becfea36c0e (patch)
tree28bd818a5db39ec5ece1bd141a28de955950463b /src/SMAPI/Framework/SGame.cs
parent451b70953ff4c0b1b27ae0de203ad99379b45b2a (diff)
parentf78093bdb58d477b400cde3f19b70ffd6ddf833d (diff)
downloadSMAPI-c8ad50dad1d706a1901798f9396f6becfea36c0e.tar.gz
SMAPI-c8ad50dad1d706a1901798f9396f6becfea36c0e.tar.bz2
SMAPI-c8ad50dad1d706a1901798f9396f6becfea36c0e.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework/SGame.cs')
-rw-r--r--src/SMAPI/Framework/SGame.cs37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/SMAPI/Framework/SGame.cs b/src/SMAPI/Framework/SGame.cs
index 104cf330..0a8a068f 100644
--- a/src/SMAPI/Framework/SGame.cs
+++ b/src/SMAPI/Framework/SGame.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Text;
-using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Events;
@@ -37,7 +36,7 @@ namespace StardewModdingAPI.Framework
private readonly EventManager Events;
/// <summary>The maximum number of consecutive attempts SMAPI should make to recover from a draw error.</summary>
- private readonly Countdown DrawCrashTimer = new Countdown(60); // 60 ticks = roughly one second
+ private readonly Countdown DrawCrashTimer = new(60); // 60 ticks = roughly one second
/// <summary>Simplifies access to private game code.</summary>
private readonly Reflector Reflection;
@@ -46,10 +45,10 @@ namespace StardewModdingAPI.Framework
private readonly Action<string> ExitGameImmediately;
/// <summary>The initial override for <see cref="Input"/>. This value is null after initialization.</summary>
- private SInputState InitialInput;
+ private SInputState? InitialInput;
/// <summary>The initial override for <see cref="Multiplayer"/>. This value is null after initialization.</summary>
- private SMultiplayer InitialMultiplayer;
+ private SMultiplayer? InitialMultiplayer;
/// <summary>Raised when the instance is updating its state (roughly 60 times per second).</summary>
private readonly Action<SGame, GameTime, Action> OnUpdating;
@@ -64,21 +63,18 @@ namespace StardewModdingAPI.Framework
/// <summary>Manages input visible to the game.</summary>
public SInputState Input => (SInputState)Game1.input;
- /// <summary>The game background task which initializes a new day.</summary>
- public Task NewDayTask => Game1._newDayTask;
-
/// <summary>Monitors the entire game state for changes.</summary>
- public WatcherCore Watchers { get; private set; }
+ public WatcherCore Watchers { get; private set; } = null!; // initialized on first update tick
/// <summary>A snapshot of the current <see cref="Watchers"/> state.</summary>
- public WatcherSnapshot WatcherSnapshot { get; } = new WatcherSnapshot();
+ public WatcherSnapshot WatcherSnapshot { get; } = new();
/// <summary>Whether the current update tick is the first one for this instance.</summary>
public bool IsFirstTick = true;
/// <summary>The number of ticks until SMAPI should notify mods that the game has loaded.</summary>
/// <remarks>Skipping a few frames ensures the game finishes initializing the world before mods try to change it.</remarks>
- public Countdown AfterLoadTimer { get; } = new Countdown(5);
+ public Countdown AfterLoadTimer { get; } = new(5);
/// <summary>Whether the game is saving and SMAPI has already raised <see cref="IGameLoopEvents.Saving"/>.</summary>
public bool IsBetweenSaveEvents { get; set; }
@@ -92,7 +88,7 @@ namespace StardewModdingAPI.Framework
/// <summary>Construct a content manager to read game content files.</summary>
/// <remarks>This must be static because the game accesses it before the <see cref="SGame"/> constructor is called.</remarks>
[NonInstancedStatic]
- public static Func<IServiceProvider, string, LocalizedContentManager> CreateContentManagerImpl;
+ public static Func<IServiceProvider, string, LocalizedContentManager>? CreateContentManagerImpl;
/*********
@@ -136,11 +132,10 @@ namespace StardewModdingAPI.Framework
/// <remarks>This is intended for use by <see cref="Keybind"/> and shouldn't be used directly in most cases.</remarks>
internal static SButtonState GetInputState(SButton button)
{
- SInputState input = Game1.input as SInputState;
- if (input == null)
+ if (Game1.input is not SInputState inputHandler)
throw new InvalidOperationException("SMAPI's input state is not in a ready state yet.");
- return input.GetState(button);
+ return inputHandler.GetState(button);
}
/// <inheritdoc />
@@ -170,13 +165,11 @@ namespace StardewModdingAPI.Framework
{
base.Initialize();
- // The game resets public static fields after the class is constructed (see
- // GameRunner.SetInstanceDefaults), so SMAPI needs to re-override them here.
+ // The game resets public static fields after the class is constructed (see GameRunner.SetInstanceDefaults), so SMAPI needs to re-override them here.
Game1.input = this.InitialInput;
Game1.multiplayer = this.InitialMultiplayer;
- // The Initial* fields should no longer be used after this point, since mods may
- // further override them after initialization.
+ // The Initial* fields should no longer be used after this point, since mods may further override them after initialization.
this.InitialInput = null;
this.InitialMultiplayer = null;
}
@@ -249,6 +242,7 @@ namespace StardewModdingAPI.Framework
Context.IsInDrawLoop = false;
}
+#nullable disable
/// <summary>Replicate the game's draw logic with some changes for SMAPI.</summary>
/// <param name="gameTime">A snapshot of the game timing state.</param>
/// <param name="target_screen">The render target, if any.</param>
@@ -256,6 +250,7 @@ namespace StardewModdingAPI.Framework
[SuppressMessage("ReSharper", "CompareOfFloatsByEqualityOperator", Justification = "copied from game code as-is")]
[SuppressMessage("ReSharper", "InconsistentNaming", Justification = "copied from game code as-is")]
[SuppressMessage("ReSharper", "LocalVariableHidesMember", Justification = "copied from game code as-is")]
+ [SuppressMessage("ReSharper", "MergeIntoPattern", Justification = "copied from game code as-is")]
[SuppressMessage("ReSharper", "PossibleLossOfFraction", Justification = "copied from game code as-is")]
[SuppressMessage("ReSharper", "RedundantArgumentDefaultValue", Justification = "copied from game code as-is")]
[SuppressMessage("ReSharper", "RedundantBaseQualifier", Justification = "copied from game code as-is")]
@@ -263,8 +258,9 @@ namespace StardewModdingAPI.Framework
[SuppressMessage("ReSharper", "RedundantExplicitNullableCreation", Justification = "copied from game code as-is")]
[SuppressMessage("ReSharper", "RedundantTypeArgumentsOfMethod", Justification = "copied from game code as-is")]
[SuppressMessage("ReSharper", "IdentifierTypo", Justification = "copied from game code as-is")]
- [SuppressMessage("SMAPI.CommonErrors", "AvoidNetField", Justification = "copied from game code as-is")]
+ [SuppressMessage("ReSharper", "MergeIntoPattern", Justification = "copied from game code as-is")]
[SuppressMessage("SMAPI.CommonErrors", "AvoidImplicitNetFieldCast", Justification = "copied from game code as-is")]
+ [SuppressMessage("SMAPI.CommonErrors", "AvoidNetField", Justification = "copied from game code as-is")]
private void DrawImpl(GameTime gameTime, RenderTarget2D target_screen)
{
var events = this.Events;
@@ -624,7 +620,7 @@ namespace StardewModdingAPI.Framework
if (tile != null)
{
Vector2 vector_draw_position = Game1.GlobalToLocal(Game1.viewport, tile_position * 64f);
- Location draw_location = new Location((int)vector_draw_position.X, (int)vector_draw_position.Y);
+ Location draw_location = new((int)vector_draw_position.X, (int)vector_draw_position.Y);
Game1.mapDisplayDevice.DrawTile(tile, draw_location, (tile_position.Y * 64f - 1f) / 10000f);
}
}
@@ -950,5 +946,6 @@ namespace StardewModdingAPI.Framework
this.drawOverlays(Game1.spriteBatch);
Game1.PopUIMode();
}
+#nullable enable
}
}