From 51de495ae4c1b9da13cce24dc15ac844b24f657e Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Jan 2021 23:43:48 -0500 Subject: add a way to send console commands to a specific screen --- src/SMAPI/Utilities/PerScreen.cs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'src/SMAPI/Utilities') diff --git a/src/SMAPI/Utilities/PerScreen.cs b/src/SMAPI/Utilities/PerScreen.cs index 55dae0d8..89d08e87 100644 --- a/src/SMAPI/Utilities/PerScreen.cs +++ b/src/SMAPI/Utilities/PerScreen.cs @@ -28,18 +28,8 @@ namespace StardewModdingAPI.Utilities /// The value is initialized the first time it's requested for that player, unless it's set manually first. public T Value { - get - { - this.RemoveDeadPlayers(); - return this.States.TryGetValue(Context.ScreenId, out T state) - ? state - : this.States[Context.ScreenId] = this.CreateNewState(); - } - set - { - this.RemoveDeadPlayers(); - this.States[Context.ScreenId] = value; - } + get => this.GetValueForScreen(Context.ScreenId); + set => this.SetValueForScreen(Context.ScreenId, value); } @@ -57,6 +47,25 @@ namespace StardewModdingAPI.Utilities this.CreateNewState = createNewState ?? (() => default); } + /// Get the value for a given screen ID, creating it if needed. + /// The screen ID to check. + internal T GetValueForScreen(int screenId) + { + this.RemoveDeadPlayers(); + return this.States.TryGetValue(screenId, out T state) + ? state + : this.States[screenId] = this.CreateNewState(); + } + + /// Set the value for a given screen ID, creating it if needed. + /// The screen ID whose value set. + /// The value to set. + internal void SetValueForScreen(int screenId, T value) + { + this.RemoveDeadPlayers(); + this.States[screenId] = value; + } + /********* ** Private methods -- cgit