summaryrefslogtreecommitdiff
path: root/src/SMAPI/Utilities
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-07-06 22:26:09 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-07-06 22:26:09 -0400
commitd51ffe58f7b7450cd4c4a7ee3d8b4da1cf55e7e4 (patch)
treeec19cdd7567125e47cfd49c7c044fc09f09f6b2f /src/SMAPI/Utilities
parent8e9237bdd7ec179975c9be5e28c811b42007e707 (diff)
parentbcb9e25d8666d2c1384515063ffbf987c36b8b0e (diff)
downloadSMAPI-d51ffe58f7b7450cd4c4a7ee3d8b4da1cf55e7e4.tar.gz
SMAPI-d51ffe58f7b7450cd4c4a7ee3d8b4da1cf55e7e4.tar.bz2
SMAPI-d51ffe58f7b7450cd4c4a7ee3d8b4da1cf55e7e4.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Utilities')
-rw-r--r--src/SMAPI/Utilities/PerScreen.cs49
-rw-r--r--src/SMAPI/Utilities/SDate.cs6
2 files changed, 26 insertions, 29 deletions
diff --git a/src/SMAPI/Utilities/PerScreen.cs b/src/SMAPI/Utilities/PerScreen.cs
index b86310b8..54657ade 100644
--- a/src/SMAPI/Utilities/PerScreen.cs
+++ b/src/SMAPI/Utilities/PerScreen.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if SMAPI_DEPRECATED
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Deprecations;
+#endif
namespace StardewModdingAPI.Utilities
{
@@ -41,12 +43,31 @@ namespace StardewModdingAPI.Utilities
/// <summary>Construct an instance.</summary>
/// <remarks><strong>Limitation with nullable reference types:</strong> when the underlying type <typeparamref name="T"/> is nullable, this sets the default value to null regardless of whether you marked the type parameter nullable. To avoid that, set the default value with the 'createNewState' argument instead.</remarks>
public PerScreen()
- : this(null, nullExpected: true) { }
+ {
+ this.CreateNewState = (() => default!);
+ }
/// <summary>Construct an instance.</summary>
/// <param name="createNewState">Create the initial state for a screen.</param>
public PerScreen(Func<T> createNewState)
- : this(createNewState, nullExpected: false) { }
+ {
+ if (createNewState is null)
+ {
+#if SMAPI_DEPRECATED
+ createNewState = (() => default!);
+ SCore.DeprecationManager.Warn(
+ null,
+ $"calling the {nameof(PerScreen<T>)} constructor with null",
+ "3.14.0",
+ DeprecationLevel.Notice
+ );
+#else
+ throw new ArgumentNullException(nameof(createNewState));
+#endif
+ }
+
+ this.CreateNewState = createNewState;
+ }
/// <summary>Get all active values by screen ID. This doesn't initialize the value for a screen ID if it's not created yet.</summary>
public IEnumerable<KeyValuePair<int, T>> GetActiveValues()
@@ -84,30 +105,6 @@ namespace StardewModdingAPI.Utilities
/*********
** Private methods
*********/
- /// <summary>Construct an instance.</summary>
- /// <param name="createNewState">Create the initial state for a screen.</param>
- /// <param name="nullExpected">Whether a null <paramref name="createNewState"/> value is expected.</param>
- /// <remarks>This constructor only exists to maintain backwards compatibility. In SMAPI 4.0.0, the overload that passes <c>nullExpected: false</c> should throw an exception instead.</remarks>
- private PerScreen(Func<T>? createNewState, bool nullExpected)
- {
- if (createNewState is null)
- {
- createNewState = (() => default!);
-
- if (!nullExpected)
- {
- SCore.DeprecationManager.Warn(
- null,
- $"calling the {nameof(PerScreen<T>)} constructor with null",
- "3.14.0",
- DeprecationLevel.Notice
- );
- }
- }
-
- this.CreateNewState = createNewState;
- }
-
/// <summary>Remove screens which are no longer active.</summary>
private void RemoveDeadScreens()
{
diff --git a/src/SMAPI/Utilities/SDate.cs b/src/SMAPI/Utilities/SDate.cs
index 1d4e4489..06ee8b91 100644
--- a/src/SMAPI/Utilities/SDate.cs
+++ b/src/SMAPI/Utilities/SDate.cs
@@ -250,7 +250,7 @@ namespace StardewModdingAPI.Utilities
/// <param name="year">The year.</param>
/// <param name="allowDayZero">Whether to allow 0 spring Y1 as a valid date.</param>
/// <exception cref="ArgumentException">One of the arguments has an invalid value (like day 35).</exception>
- [SuppressMessage("ReSharper", "ConstantConditionalAccessQualifier", Justification = "The nullability is validated in this constructor.")]
+ [SuppressMessage("ReSharper", "ConditionalAccessQualifierIsNonNullableAccordingToAPIContract", Justification = "The nullability is validated in this constructor.")]
private SDate(int day, string season, int year, bool allowDayZero)
{
season = season?.Trim().ToLowerInvariant()!; // null-checked below
@@ -278,11 +278,11 @@ namespace StardewModdingAPI.Utilities
/// <summary>Get whether a date represents 0 spring Y1, which is the date during the in-game intro.</summary>
/// <param name="day">The day of month.</param>
- /// <param name="season">The season name.</param>
+ /// <param name="season">The normalized season name.</param>
/// <param name="year">The year.</param>
private bool IsDayZero(int day, string season, int year)
{
- return day == 0 && season?.Trim().ToLower() == "spring" && year == 1;
+ return day == 0 && season == "spring" && year == 1;
}
/// <summary>Get the day of week for a given date.</summary>