summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-01-15 18:48:30 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-01-15 18:48:30 -0500
commit95ad954fa4b761dd32eefa072622cb1168c4d028 (patch)
treeb5a5c4ed7e670d1738f2cc7de1bfa0b472b9c096
parent70edec65678fc07200cd817b99f812389d1e97b0 (diff)
downloadSMAPI-95ad954fa4b761dd32eefa072622cb1168c4d028.tar.gz
SMAPI-95ad954fa4b761dd32eefa072622cb1168c4d028.tar.bz2
SMAPI-95ad954fa4b761dd32eefa072622cb1168c4d028.zip
allow get/setting PerScreen<T> values by screen ID
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Utilities/PerScreen.cs23
2 files changed, 12 insertions, 12 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 5409d9ff..be34e653 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -9,6 +9,7 @@
## Upcoming release
* For modders:
+ * Expanded `PerScreen<T>` API: you can now get/set the value for any screen.
* Added an option to disable rewriting mods for compatibility (thanks to Bpendragon!). This may prevent older mods from loading, but bypasses a Visual Studio crash when debugging.
* For the Error Handler mod:
diff --git a/src/SMAPI/Utilities/PerScreen.cs b/src/SMAPI/Utilities/PerScreen.cs
index 89d08e87..1498488b 100644
--- a/src/SMAPI/Utilities/PerScreen.cs
+++ b/src/SMAPI/Utilities/PerScreen.cs
@@ -49,20 +49,20 @@ namespace StardewModdingAPI.Utilities
/// <summary>Get the value for a given screen ID, creating it if needed.</summary>
/// <param name="screenId">The screen ID to check.</param>
- internal T GetValueForScreen(int screenId)
+ public T GetValueForScreen(int screenId)
{
- this.RemoveDeadPlayers();
+ this.RemoveDeadScreens();
return this.States.TryGetValue(screenId, out T state)
? state
: this.States[screenId] = this.CreateNewState();
}
- /// <summary>Set the value for a given screen ID, creating it if needed.</summary>
+ /// <summary>Set the value for a given screen ID.</summary>
/// <param name="screenId">The screen ID whose value set.</param>
/// <param name="value">The value to set.</param>
- internal void SetValueForScreen(int screenId, T value)
+ public void SetValueForScreen(int screenId, T value)
{
- this.RemoveDeadPlayers();
+ this.RemoveDeadScreens();
this.States[screenId] = value;
}
@@ -70,18 +70,17 @@ namespace StardewModdingAPI.Utilities
/*********
** Private methods
*********/
- /// <summary>Remove players who are no longer have a split-screen index.</summary>
- /// <returns>Returns whether any players were removed.</returns>
- private void RemoveDeadPlayers()
+ /// <summary>Remove screens which are no longer active.</summary>
+ private void RemoveDeadScreens()
{
if (this.LastRemovedScreenId == Context.LastRemovedScreenId)
return;
-
this.LastRemovedScreenId = Context.LastRemovedScreenId;
- foreach (int id in this.States.Keys.ToArray())
+
+ foreach (var pair in this.States.ToArray())
{
- if (!Context.HasScreenId(id))
- this.States.Remove(id);
+ if (!Context.HasScreenId(pair.Key))
+ this.States.Remove(pair.Key);
}
}
}