From 62665649bdec8b1b45b04e2d48bc68da689124d4 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 23 May 2022 12:19:06 -0400 Subject: shortcut common cases in hot code paths --- src/SMAPI/Framework/Deprecations/DeprecationManager.cs | 3 +++ src/SMAPI/Framework/SCore.cs | 1 + 2 files changed, 4 insertions(+) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/Deprecations/DeprecationManager.cs b/src/SMAPI/Framework/Deprecations/DeprecationManager.cs index 3bbbd7b8..4597a764 100644 --- a/src/SMAPI/Framework/Deprecations/DeprecationManager.cs +++ b/src/SMAPI/Framework/Deprecations/DeprecationManager.cs @@ -95,6 +95,9 @@ namespace StardewModdingAPI.Framework.Deprecations /// Print any queued messages. public void PrintQueued() { + if (!this.QueuedWarnings.Any()) + return; + foreach (DeprecationWarning warning in this.QueuedWarnings.OrderBy(p => p.ModName).ThenBy(p => p.NounPhrase)) { // build message diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 7042e83a..67f78400 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -596,6 +596,7 @@ namespace StardewModdingAPI.Framework /********* ** Execute commands *********/ + if (this.ScreenCommandQueue.Value.Any()) { var commandQueue = this.ScreenCommandQueue.Value; foreach ((Command? command, string? name, string[]? args) in commandQueue) -- cgit From 9933acad35375c994ada78109eb1af957288d9ea Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 23 May 2022 12:57:33 -0400 Subject: use in watchers --- .../StateTracking/FieldWatchers/ComparableListWatcher.cs | 10 +++++----- .../StateTracking/FieldWatchers/ComparableWatcher.cs | 12 ++++++------ .../FieldWatchers/ImmutableCollectionWatcher.cs | 12 ++++++------ .../StateTracking/FieldWatchers/NetCollectionWatcher.cs | 12 ++++++------ .../StateTracking/FieldWatchers/NetDictionaryWatcher.cs | 12 ++++++------ .../Framework/StateTracking/FieldWatchers/NetListWatcher.cs | 12 ++++++------ .../Framework/StateTracking/FieldWatchers/NetValueWatcher.cs | 12 ++++++------ .../FieldWatchers/ObservableCollectionWatcher.cs | 12 ++++++------ src/SMAPI/Framework/StateTracking/LocationTracker.cs | 8 ++++---- src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs | 8 ++++---- 10 files changed, 55 insertions(+), 55 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs index 256370ce..3d178a36 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs @@ -26,13 +26,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ - /// Whether the value changed since the last reset. + /// public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; - /// The values added since the last reset. + /// public IEnumerable Added => this.AddedImpl; - /// The values removed since the last reset. + /// public IEnumerable Removed => this.RemovedImpl; @@ -48,7 +48,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers this.LastValues = new HashSet(comparer); } - /// Update the current value if needed. + /// public void Update() { this.AssertNotDisposed(); @@ -71,7 +71,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers this.LastValues = curValues; } - /// Set the current value as the baseline. + /// public void Reset() { this.AssertNotDisposed(); diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs index 5f76fe0a..e51c46c1 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs @@ -20,13 +20,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ - /// The field value at the last reset. + /// public TValue PreviousValue { get; private set; } - /// The latest value. + /// public TValue CurrentValue { get; private set; } - /// Whether the value changed since the last reset. + /// public bool IsChanged { get; private set; } @@ -44,21 +44,21 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers this.PreviousValue = this.CurrentValue; } - /// Update the current value if needed. + /// public void Update() { this.CurrentValue = this.GetValue(); this.IsChanged = !this.Comparer.Equals(this.PreviousValue, this.CurrentValue); } - /// Set the current value as the baseline. + /// public void Reset() { this.PreviousValue = this.CurrentValue; this.IsChanged = false; } - /// Release any references if needed when the field is no longer needed. + /// public void Dispose() { } } } diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs index 84340fbf..b46e0b24 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs @@ -13,26 +13,26 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// A singleton collection watcher instance. public static ImmutableCollectionWatcher Instance { get; } = new(); - /// Whether the collection changed since the last reset. + /// public bool IsChanged { get; } = false; - /// The values added since the last reset. + /// public IEnumerable Added { get; } = Array.Empty(); - /// The values removed since the last reset. + /// public IEnumerable Removed { get; } = Array.Empty(); /********* ** Public methods *********/ - /// Update the current value if needed. + /// public void Update() { } - /// Set the current value as the baseline. + /// public void Reset() { } - /// Stop watching the field and release all references. + /// public override void Dispose() { } } } diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs index 676c9fb4..e278fa99 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs @@ -24,13 +24,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ - /// Whether the collection changed since the last reset. + /// public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; - /// The values added since the last reset. + /// public IEnumerable Added => this.AddedImpl; - /// The values removed since the last reset. + /// public IEnumerable Removed => this.RemovedImpl; @@ -46,13 +46,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers field.OnValueRemoved += this.OnValueRemoved; } - /// Update the current value if needed. + /// public void Update() { this.AssertNotDisposed(); } - /// Set the current value as the baseline. + /// public void Reset() { this.AssertNotDisposed(); @@ -61,7 +61,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers this.RemovedImpl.Clear(); } - /// Stop watching the field and release all references. + /// public override void Dispose() { if (!this.IsDisposed) diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs index f55e4cea..a0fcc236 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs @@ -31,13 +31,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ - /// Whether the collection changed since the last reset. + /// public bool IsChanged => this.PairsAdded.Count > 0 || this.PairsRemoved.Count > 0; - /// The values added since the last reset. + /// public IEnumerable> Added => this.PairsAdded; - /// The values removed since the last reset. + /// public IEnumerable> Removed => this.PairsRemoved; @@ -54,13 +54,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers field.OnValueRemoved += this.OnValueRemoved; } - /// Update the current value if needed. + /// public void Update() { this.AssertNotDisposed(); } - /// Set the current value as the baseline. + /// public void Reset() { this.AssertNotDisposed(); @@ -69,7 +69,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers this.PairsRemoved.Clear(); } - /// Stop watching the field and release all references. + /// public override void Dispose() { if (!this.IsDisposed) diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs index 0b4d3030..79c3cb8b 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs @@ -25,13 +25,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ - /// Whether the collection changed since the last reset. + /// public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; - /// The values added since the last reset. + /// public IEnumerable Added => this.AddedImpl; - /// The values removed since the last reset. + /// public IEnumerable Removed => this.RemovedImpl; @@ -47,20 +47,20 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers field.OnArrayReplaced += this.OnArrayReplaced; } - /// Set the current value as the baseline. + /// public void Reset() { this.AddedImpl.Clear(); this.RemovedImpl.Clear(); } - /// Update the current value if needed. + /// public void Update() { this.AssertNotDisposed(); } - /// Stop watching the field and release all references. + /// public override void Dispose() { if (!this.IsDisposed) diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs index 48d5d681..d00f4582 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs @@ -17,13 +17,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ - /// Whether the value changed since the last reset. + /// public bool IsChanged { get; private set; } - /// The field value at the last reset. + /// public TValue PreviousValue { get; private set; } - /// The latest value. + /// public TValue CurrentValue { get; private set; } @@ -42,13 +42,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers field.fieldChangeEvent += this.OnValueChanged; } - /// Update the current value if needed. + /// public void Update() { this.AssertNotDisposed(); } - /// Set the current value as the baseline. + /// public void Reset() { this.AssertNotDisposed(); @@ -57,7 +57,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers this.IsChanged = false; } - /// Stop watching the field and release all references. + /// public override void Dispose() { if (!this.IsDisposed) diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs index 97aedca8..f503c47f 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs @@ -28,13 +28,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ - /// Whether the collection changed since the last reset. + /// public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; - /// The values added since the last reset. + /// public IEnumerable Added => this.AddedImpl; - /// The values removed since the last reset. + /// public IEnumerable Removed => this.RemovedImpl; @@ -49,13 +49,13 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers field.CollectionChanged += this.OnCollectionChanged; } - /// Update the current value if needed. + /// public void Update() { this.AssertNotDisposed(); } - /// Set the current value as the baseline. + /// public void Reset() { this.AssertNotDisposed(); @@ -64,7 +64,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers this.RemovedImpl.Clear(); } - /// Stop watching the field and release all references. + /// public override void Dispose() { if (!this.IsDisposed) diff --git a/src/SMAPI/Framework/StateTracking/LocationTracker.cs b/src/SMAPI/Framework/StateTracking/LocationTracker.cs index ff72a19b..036ed73a 100644 --- a/src/SMAPI/Framework/StateTracking/LocationTracker.cs +++ b/src/SMAPI/Framework/StateTracking/LocationTracker.cs @@ -25,7 +25,7 @@ namespace StardewModdingAPI.Framework.StateTracking /********* ** Accessors *********/ - /// Whether the value changed since the last reset. + /// public bool IsChanged => this.Watchers.Any(p => p.IsChanged); /// The tracked location. @@ -88,7 +88,7 @@ namespace StardewModdingAPI.Framework.StateTracking this.UpdateChestWatcherList(added: location.Objects.Pairs, removed: Array.Empty>()); } - /// Update the current value if needed. + /// public void Update() { foreach (IWatcher watcher in this.Watchers) @@ -100,7 +100,7 @@ namespace StardewModdingAPI.Framework.StateTracking watcher.Value.Update(); } - /// Set the current value as the baseline. + /// public void Reset() { foreach (IWatcher watcher in this.Watchers) @@ -110,7 +110,7 @@ namespace StardewModdingAPI.Framework.StateTracking watcher.Value.Reset(); } - /// Stop watching the player fields and release all references. + /// public void Dispose() { foreach (IWatcher watcher in this.Watchers) diff --git a/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs b/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs index 817a6011..f328d659 100644 --- a/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs +++ b/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs @@ -37,7 +37,7 @@ namespace StardewModdingAPI.Framework.StateTracking /// Whether locations were added or removed since the last reset. public bool IsLocationListChanged => this.Added.Any() || this.Removed.Any(); - /// Whether any tracked location data changed since the last reset. + /// public bool IsChanged => this.IsLocationListChanged || this.Locations.Any(p => p.IsChanged); /// The tracked locations. @@ -64,7 +64,7 @@ namespace StardewModdingAPI.Framework.StateTracking this.VolcanoLocationListWatcher = WatcherFactory.ForReferenceList(activeVolcanoLocations); } - /// Update the current value if needed. + /// public void Update() { // update watchers @@ -120,7 +120,7 @@ namespace StardewModdingAPI.Framework.StateTracking this.VolcanoLocationListWatcher.Reset(); } - /// Set the current value as the baseline. + /// public void Reset() { this.ResetLocationList(); @@ -135,7 +135,7 @@ namespace StardewModdingAPI.Framework.StateTracking return this.LocationDict.ContainsKey(location); } - /// Stop watching the player fields and release all references. + /// public void Dispose() { foreach (IWatcher watcher in this.GetWatchers()) -- cgit From 87ac7fc4032c1edbc246e7f7a96881f1284c04b9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 23 May 2022 12:57:33 -0400 Subject: fix nullable annotations in NetListWatcher --- src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs index 79c3cb8b..3badb533 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs @@ -102,7 +102,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// The list index which changed. /// The previous value. /// The new value. - private void OnElementChanged(NetList> list, int index, TValue oldValue, TValue newValue) + private void OnElementChanged(NetList> list, int index, TValue? oldValue, TValue? newValue) { this.Remove(oldValue); this.Add(newValue); @@ -110,7 +110,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// Track an added item. /// The value that was added. - private void Add(TValue value) + private void Add(TValue? value) { if (value == null) return; @@ -126,7 +126,7 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// Track a removed item. /// The value that was removed. - private void Remove(TValue value) + private void Remove(TValue? value) { if (value == null) return; -- cgit From 5675f9fcebfdeb03510c347712df8e9934b362c6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 23 May 2022 12:57:33 -0400 Subject: add watcher names to simplify troubleshooting --- src/SMAPI/Framework/StateTracking/ChestTracker.cs | 5 ++- .../FieldWatchers/ComparableListWatcher.cs | 7 +++- .../FieldWatchers/ComparableWatcher.cs | 7 +++- .../FieldWatchers/ImmutableCollectionWatcher.cs | 3 ++ .../FieldWatchers/NetCollectionWatcher.cs | 7 +++- .../FieldWatchers/NetDictionaryWatcher.cs | 7 +++- .../StateTracking/FieldWatchers/NetListWatcher.cs | 7 +++- .../StateTracking/FieldWatchers/NetValueWatcher.cs | 7 +++- .../FieldWatchers/ObservableCollectionWatcher.cs | 7 +++- .../StateTracking/FieldWatchers/WatcherFactory.cs | 45 +++++++++++++--------- src/SMAPI/Framework/StateTracking/IWatcher.cs | 3 ++ .../Framework/StateTracking/LocationTracker.cs | 20 ++++++---- src/SMAPI/Framework/StateTracking/PlayerTracker.cs | 14 +++---- .../StateTracking/WorldLocationsTracker.cs | 9 +++-- src/SMAPI/Framework/WatcherCore.cs | 14 +++---- 15 files changed, 110 insertions(+), 52 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/StateTracking/ChestTracker.cs b/src/SMAPI/Framework/StateTracking/ChestTracker.cs index c33a7498..2796ad54 100644 --- a/src/SMAPI/Framework/StateTracking/ChestTracker.cs +++ b/src/SMAPI/Framework/StateTracking/ChestTracker.cs @@ -39,11 +39,12 @@ namespace StardewModdingAPI.Framework.StateTracking ** Public methods *********/ /// Construct an instance. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The chest being tracked. - public ChestTracker(Chest chest) + public ChestTracker(string name, Chest chest) { this.Chest = chest; - this.InventoryWatcher = WatcherFactory.ForNetList(chest.items); + this.InventoryWatcher = WatcherFactory.ForNetList($"{name}.{nameof(chest.items)}", chest.items); this.StackSizes = this.Chest.items .Where(n => n != null) diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs index 3d178a36..0b13434a 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableListWatcher.cs @@ -26,6 +26,9 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ + /// + public string Name { get; } + /// public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; @@ -40,10 +43,12 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ** Public methods *********/ /// Construct an instance. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The collection to watch. /// The equality comparer which indicates whether two values are the same. - public ComparableListWatcher(ICollection values, IEqualityComparer comparer) + public ComparableListWatcher(string name, ICollection values, IEqualityComparer comparer) { + this.Name = name; this.CurrentValues = values; this.LastValues = new HashSet(comparer); } diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs index e51c46c1..e2f6c7fd 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ComparableWatcher.cs @@ -20,6 +20,9 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ + /// + public string Name { get; } + /// public TValue PreviousValue { get; private set; } @@ -34,10 +37,12 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ** Public methods *********/ /// Construct an instance. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// Get the current value. /// The equality comparer which indicates whether two values are the same. - public ComparableWatcher(Func getValue, IEqualityComparer comparer) + public ComparableWatcher(string name, Func getValue, IEqualityComparer comparer) { + this.Name = name; this.GetValue = getValue; this.Comparer = comparer; this.CurrentValue = getValue(); diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs index b46e0b24..9c2ba9bc 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ImmutableCollectionWatcher.cs @@ -13,6 +13,9 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// A singleton collection watcher instance. public static ImmutableCollectionWatcher Instance { get; } = new(); + /// + public string Name => nameof(ImmutableCollectionWatcher); + /// public bool IsChanged { get; } = false; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs index e278fa99..1d5e4851 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetCollectionWatcher.cs @@ -24,6 +24,9 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ + /// + public string Name { get; } + /// public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; @@ -38,9 +41,11 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ** Public methods *********/ /// Construct an instance. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The field to watch. - public NetCollectionWatcher(NetCollection field) + public NetCollectionWatcher(string name, NetCollection field) { + this.Name = name; this.Field = field; field.OnValueAdded += this.OnValueAdded; field.OnValueRemoved += this.OnValueRemoved; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs index a0fcc236..3bd8e09d 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetDictionaryWatcher.cs @@ -31,6 +31,9 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ + /// + public string Name { get; } + /// public bool IsChanged => this.PairsAdded.Count > 0 || this.PairsRemoved.Count > 0; @@ -45,9 +48,11 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ** Public methods *********/ /// Construct an instance. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The field to watch. - public NetDictionaryWatcher(NetDictionary field) + public NetDictionaryWatcher(string name, NetDictionary field) { + this.Name = name; this.Field = field; field.OnValueAdded += this.OnValueAdded; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs index 3badb533..5b6a3e1f 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetListWatcher.cs @@ -25,6 +25,9 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ + /// + public string Name { get; } + /// public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; @@ -39,9 +42,11 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ** Public methods *********/ /// Construct an instance. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The field to watch. - public NetListWatcher(NetList> field) + public NetListWatcher(string name, NetList> field) { + this.Name = name; this.Field = field; field.OnElementChanged += this.OnElementChanged; field.OnArrayReplaced += this.OnArrayReplaced; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs index d00f4582..e4219dda 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/NetValueWatcher.cs @@ -17,6 +17,9 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ + /// + public string Name { get; } + /// public bool IsChanged { get; private set; } @@ -31,9 +34,11 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ** Public methods *********/ /// Construct an instance. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The field to watch. - public NetValueWatcher(NetFieldBase field) + public NetValueWatcher(string name, NetFieldBase field) { + this.Name = name; this.Field = field; this.PreviousValue = field.Value; this.CurrentValue = field.Value; diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs index f503c47f..1f95ac89 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/ObservableCollectionWatcher.cs @@ -28,6 +28,9 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /********* ** Accessors *********/ + /// + public string Name { get; } + /// public bool IsChanged => this.AddedImpl.Count > 0 || this.RemovedImpl.Count > 0; @@ -42,9 +45,11 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ** Public methods *********/ /// Construct an instance. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The field to watch. - public ObservableCollectionWatcher(ObservableCollection field) + public ObservableCollectionWatcher(string name, ObservableCollection field) { + this.Name = name; this.Field = field; field.CollectionChanged += this.OnCollectionChanged; } diff --git a/src/SMAPI/Framework/StateTracking/FieldWatchers/WatcherFactory.cs b/src/SMAPI/Framework/StateTracking/FieldWatchers/WatcherFactory.cs index c4a4d0b9..c31be1fc 100644 --- a/src/SMAPI/Framework/StateTracking/FieldWatchers/WatcherFactory.cs +++ b/src/SMAPI/Framework/StateTracking/FieldWatchers/WatcherFactory.cs @@ -17,37 +17,41 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ****/ /// Get a watcher which compares values using their method. This method should only be used when won't work, since this doesn't validate whether they're comparable. /// The value type. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// Get the current value. - public static IValueWatcher ForGenericEquality(Func getValue) + public static IValueWatcher ForGenericEquality(string name, Func getValue) where T : struct { - return new ComparableWatcher(getValue, new GenericEqualsComparer()); + return new ComparableWatcher(name, getValue, new GenericEqualsComparer()); } /// Get a watcher for an value. /// The value type. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// Get the current value. - public static IValueWatcher ForEquatable(Func getValue) + public static IValueWatcher ForEquatable(string name, Func getValue) where T : IEquatable { - return new ComparableWatcher(getValue, new EquatableComparer()); + return new ComparableWatcher(name, getValue, new EquatableComparer()); } /// Get a watcher which detects when an object reference changes. /// The value type. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// Get the current value. - public static IValueWatcher ForReference(Func getValue) + public static IValueWatcher ForReference(string name, Func getValue) { - return new ComparableWatcher(getValue, new ObjectReferenceComparer()); + return new ComparableWatcher(name, getValue, new ObjectReferenceComparer()); } /// Get a watcher for a net collection. /// The value type. /// The net field instance type. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The net collection. - public static IValueWatcher ForNetValue(NetFieldBase field) where TSelf : NetFieldBase + public static IValueWatcher ForNetValue(string name, NetFieldBase field) where TSelf : NetFieldBase { - return new NetValueWatcher(field); + return new NetValueWatcher(name, field); } /**** @@ -55,18 +59,20 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers ****/ /// Get a watcher which detects when an object reference in a collection changes. /// The value type. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The observable collection. - public static ICollectionWatcher ForReferenceList(ICollection collection) + public static ICollectionWatcher ForReferenceList(string name, ICollection collection) { - return new ComparableListWatcher(collection, new ObjectReferenceComparer()); + return new ComparableListWatcher(name, collection, new ObjectReferenceComparer()); } /// Get a watcher for an observable collection. /// The value type. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The observable collection. - public static ICollectionWatcher ForObservableCollection(ObservableCollection collection) + public static ICollectionWatcher ForObservableCollection(string name, ObservableCollection collection) { - return new ObservableCollectionWatcher(collection); + return new ObservableCollectionWatcher(name, collection); } /// Get a watcher for a collection that never changes. @@ -78,36 +84,39 @@ namespace StardewModdingAPI.Framework.StateTracking.FieldWatchers /// Get a watcher for a net collection. /// The value type. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The net collection. - public static ICollectionWatcher ForNetCollection(NetCollection collection) + public static ICollectionWatcher ForNetCollection(string name, NetCollection collection) where T : class, INetObject { - return new NetCollectionWatcher(collection); + return new NetCollectionWatcher(name, collection); } /// Get a watcher for a net list. /// The value type. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The net list. - public static ICollectionWatcher ForNetList(NetList> collection) + public static ICollectionWatcher ForNetList(string name, NetList> collection) where T : class, INetObject { - return new NetListWatcher(collection); + return new NetListWatcher(name, collection); } /// Get a watcher for a net dictionary. + /// A name which identifies what the watcher is watching, used for troubleshooting. /// The dictionary key type. /// The dictionary value type. /// The net type equivalent to . /// The serializable dictionary type that can store the keys and values. /// The net field instance type. /// The net field. - public static NetDictionaryWatcher ForNetDictionary(NetDictionary field) + public static NetDictionaryWatcher ForNetDictionary(string name, NetDictionary field) where TKey : notnull where TField : class, INetObject, new() where TSerialDict : IDictionary, new() where TSelf : NetDictionary { - return new NetDictionaryWatcher(field); + return new NetDictionaryWatcher(name, field); } } } diff --git a/src/SMAPI/Framework/StateTracking/IWatcher.cs b/src/SMAPI/Framework/StateTracking/IWatcher.cs index 8c7fa51c..4a0e3998 100644 --- a/src/SMAPI/Framework/StateTracking/IWatcher.cs +++ b/src/SMAPI/Framework/StateTracking/IWatcher.cs @@ -8,6 +8,9 @@ namespace StardewModdingAPI.Framework.StateTracking /********* ** Accessors *********/ + /// A name which identifies what the watcher is watching, used for troubleshooting. + string Name { get; } + /// Whether the value changed since the last reset. bool IsChanged { get; } diff --git a/src/SMAPI/Framework/StateTracking/LocationTracker.cs b/src/SMAPI/Framework/StateTracking/LocationTracker.cs index 036ed73a..790c71dd 100644 --- a/src/SMAPI/Framework/StateTracking/LocationTracker.cs +++ b/src/SMAPI/Framework/StateTracking/LocationTracker.cs @@ -25,6 +25,9 @@ namespace StardewModdingAPI.Framework.StateTracking /********* ** Accessors *********/ + /// + public string Name { get; } + /// public bool IsChanged => this.Watchers.Any(p => p.IsChanged); @@ -63,16 +66,17 @@ namespace StardewModdingAPI.Framework.StateTracking /// The location to track. public LocationTracker(GameLocation location) { + this.Name = $"Locations.{location.NameOrUniqueName}"; this.Location = location; // init watchers - this.BuildingsWatcher = location is BuildableGameLocation buildableLocation ? WatcherFactory.ForNetCollection(buildableLocation.buildings) : WatcherFactory.ForImmutableCollection(); - this.DebrisWatcher = WatcherFactory.ForNetCollection(location.debris); - this.LargeTerrainFeaturesWatcher = WatcherFactory.ForNetCollection(location.largeTerrainFeatures); - this.NpcsWatcher = WatcherFactory.ForNetCollection(location.characters); - this.ObjectsWatcher = WatcherFactory.ForNetDictionary(location.netObjects); - this.TerrainFeaturesWatcher = WatcherFactory.ForNetDictionary(location.terrainFeatures); - this.FurnitureWatcher = WatcherFactory.ForNetCollection(location.furniture); + this.BuildingsWatcher = location is BuildableGameLocation buildableLocation ? WatcherFactory.ForNetCollection($"{this.Name}.{nameof(buildableLocation.buildings)}", buildableLocation.buildings) : WatcherFactory.ForImmutableCollection(); + this.DebrisWatcher = WatcherFactory.ForNetCollection($"{this.Name}.{nameof(location.debris)}", location.debris); + this.LargeTerrainFeaturesWatcher = WatcherFactory.ForNetCollection($"{this.Name}.{nameof(location.largeTerrainFeatures)}", location.largeTerrainFeatures); + this.NpcsWatcher = WatcherFactory.ForNetCollection($"{this.Name}.{nameof(location.characters)}", location.characters); + this.ObjectsWatcher = WatcherFactory.ForNetDictionary($"{this.Name}.{nameof(location.netObjects)}", location.netObjects); + this.TerrainFeaturesWatcher = WatcherFactory.ForNetDictionary($"{this.Name}.{nameof(location.terrainFeatures)}", location.terrainFeatures); + this.FurnitureWatcher = WatcherFactory.ForNetCollection($"{this.Name}.{nameof(location.furniture)}", location.furniture); this.Watchers.AddRange(new IWatcher[] { @@ -143,7 +147,7 @@ namespace StardewModdingAPI.Framework.StateTracking foreach ((Vector2 tile, SObject? obj) in added) { if (obj is Chest chest && !this.ChestWatchers.ContainsKey(tile)) - this.ChestWatchers.Add(tile, new ChestTracker(chest)); + this.ChestWatchers.Add(tile, new ChestTracker($"{this.Name}.chest({tile})", chest)); } } } diff --git a/src/SMAPI/Framework/StateTracking/PlayerTracker.cs b/src/SMAPI/Framework/StateTracking/PlayerTracker.cs index 5433ac8e..fae90678 100644 --- a/src/SMAPI/Framework/StateTracking/PlayerTracker.cs +++ b/src/SMAPI/Framework/StateTracking/PlayerTracker.cs @@ -54,15 +54,15 @@ namespace StardewModdingAPI.Framework.StateTracking this.PreviousInventory = new Dictionary(this.CurrentInventory); // init trackers - this.LocationWatcher = WatcherFactory.ForReference(this.GetCurrentLocation); + this.LocationWatcher = WatcherFactory.ForReference($"player.{nameof(player.currentLocation)}", this.GetCurrentLocation); this.SkillWatchers = new Dictionary> { - [SkillType.Combat] = WatcherFactory.ForNetValue(player.combatLevel), - [SkillType.Farming] = WatcherFactory.ForNetValue(player.farmingLevel), - [SkillType.Fishing] = WatcherFactory.ForNetValue(player.fishingLevel), - [SkillType.Foraging] = WatcherFactory.ForNetValue(player.foragingLevel), - [SkillType.Luck] = WatcherFactory.ForNetValue(player.luckLevel), - [SkillType.Mining] = WatcherFactory.ForNetValue(player.miningLevel) + [SkillType.Combat] = WatcherFactory.ForNetValue($"player.{nameof(player.combatLevel)}", player.combatLevel), + [SkillType.Farming] = WatcherFactory.ForNetValue($"player.{nameof(player.farmingLevel)}", player.farmingLevel), + [SkillType.Fishing] = WatcherFactory.ForNetValue($"player.{nameof(player.fishingLevel)}", player.fishingLevel), + [SkillType.Foraging] = WatcherFactory.ForNetValue($"player.{nameof(player.foragingLevel)}", player.foragingLevel), + [SkillType.Luck] = WatcherFactory.ForNetValue($"player.{nameof(player.luckLevel)}", player.luckLevel), + [SkillType.Mining] = WatcherFactory.ForNetValue($"player.{nameof(player.miningLevel)}", player.miningLevel) }; // track watchers for convenience diff --git a/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs b/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs index f328d659..ca6988ad 100644 --- a/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs +++ b/src/SMAPI/Framework/StateTracking/WorldLocationsTracker.cs @@ -34,6 +34,9 @@ namespace StardewModdingAPI.Framework.StateTracking /********* ** Accessors *********/ + /// + public string Name => nameof(WorldLocationsTracker); + /// Whether locations were added or removed since the last reset. public bool IsLocationListChanged => this.Added.Any() || this.Removed.Any(); @@ -59,9 +62,9 @@ namespace StardewModdingAPI.Framework.StateTracking /// The game's list of active volcano locations. public WorldLocationsTracker(ObservableCollection locations, IList activeMineLocations, IList activeVolcanoLocations) { - this.LocationListWatcher = WatcherFactory.ForObservableCollection(locations); - this.MineLocationListWatcher = WatcherFactory.ForReferenceList(activeMineLocations); - this.VolcanoLocationListWatcher = WatcherFactory.ForReferenceList(activeVolcanoLocations); + this.LocationListWatcher = WatcherFactory.ForObservableCollection($"{this.Name}.{nameof(locations)}", locations); + this.MineLocationListWatcher = WatcherFactory.ForReferenceList($"{this.Name}.{nameof(activeMineLocations)}", activeMineLocations); + this.VolcanoLocationListWatcher = WatcherFactory.ForReferenceList($"{this.Name}.{nameof(activeVolcanoLocations)}", activeVolcanoLocations); } /// diff --git a/src/SMAPI/Framework/WatcherCore.cs b/src/SMAPI/Framework/WatcherCore.cs index 5e20ac7b..35f27cc7 100644 --- a/src/SMAPI/Framework/WatcherCore.cs +++ b/src/SMAPI/Framework/WatcherCore.cs @@ -60,14 +60,14 @@ namespace StardewModdingAPI.Framework public WatcherCore(SInputState inputState, ObservableCollection gameLocations) { // init watchers - this.CursorWatcher = WatcherFactory.ForEquatable(() => inputState.CursorPosition); - this.MouseWheelScrollWatcher = WatcherFactory.ForEquatable(() => inputState.MouseState.ScrollWheelValue); - this.SaveIdWatcher = WatcherFactory.ForEquatable(() => Game1.hasLoadedGame ? Game1.uniqueIDForThisGame : 0); - this.WindowSizeWatcher = WatcherFactory.ForEquatable(() => new Point(Game1.viewport.Width, Game1.viewport.Height)); - this.TimeWatcher = WatcherFactory.ForEquatable(() => Game1.timeOfDay); - this.ActiveMenuWatcher = WatcherFactory.ForReference(() => Game1.activeClickableMenu); + this.CursorWatcher = WatcherFactory.ForEquatable(nameof(inputState.CursorPosition), () => inputState.CursorPosition); + this.MouseWheelScrollWatcher = WatcherFactory.ForEquatable(nameof(inputState.MouseState.ScrollWheelValue), () => inputState.MouseState.ScrollWheelValue); + this.SaveIdWatcher = WatcherFactory.ForEquatable(nameof(Game1.uniqueIDForThisGame), () => Game1.hasLoadedGame ? Game1.uniqueIDForThisGame : 0); + this.WindowSizeWatcher = WatcherFactory.ForEquatable(nameof(Game1.viewport), () => new Point(Game1.viewport.Width, Game1.viewport.Height)); + this.TimeWatcher = WatcherFactory.ForEquatable(nameof(Game1.timeOfDay), () => Game1.timeOfDay); + this.ActiveMenuWatcher = WatcherFactory.ForReference(nameof(Game1.activeClickableMenu), () => Game1.activeClickableMenu); this.LocationsWatcher = new WorldLocationsTracker(gameLocations, MineShaft.activeMines, VolcanoDungeon.activeLevels); - this.LocaleWatcher = WatcherFactory.ForGenericEquality(() => LocalizedContentManager.CurrentLanguageCode); + this.LocaleWatcher = WatcherFactory.ForGenericEquality(nameof(LocalizedContentManager.CurrentLanguageCode), () => LocalizedContentManager.CurrentLanguageCode); this.Watchers.AddRange(new IWatcher[] { this.CursorWatcher, -- cgit From 064346594d2239b1dceb9ddbc78e147c555d63d7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 24 May 2022 18:12:06 -0400 Subject: fix split-screen error when a mod provides a localized asset in one screen but not another --- docs/release-notes.md | 4 ++++ src/SMAPI/Framework/ContentCoordinator.cs | 24 +++++++++++++++++----- .../ContentManagers/BaseContentManager.cs | 12 ++++++----- 3 files changed, 30 insertions(+), 10 deletions(-) (limited to 'src/SMAPI/Framework') diff --git a/docs/release-notes.md b/docs/release-notes.md index cd177f61..91ff0618 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,6 +1,10 @@ ← [README](README.md) # Release notes +## Upcoming release +* For players: + * Fixed error in split-screen mode when a mod provides a localized asset in one screen but not another. + ## 3.14.5 Released 22 May 2022 for Stardew Valley 1.5.6 or later. diff --git a/src/SMAPI/Framework/ContentCoordinator.cs b/src/SMAPI/Framework/ContentCoordinator.cs index fc61b44b..cfeb35c8 100644 --- a/src/SMAPI/Framework/ContentCoordinator.cs +++ b/src/SMAPI/Framework/ContentCoordinator.cs @@ -15,8 +15,8 @@ using StardewModdingAPI.Framework.Utilities; using StardewModdingAPI.Internal; using StardewModdingAPI.Metadata; using StardewModdingAPI.Toolkit.Serialization; -using StardewModdingAPI.Toolkit.Utilities; using StardewModdingAPI.Toolkit.Utilities.PathLookups; +using StardewModdingAPI.Utilities; using StardewValley; using StardewValley.GameData; using xTile; @@ -110,6 +110,10 @@ namespace StardewModdingAPI.Framework /// The absolute path to the . public string FullRootDirectory { get; } + /// A lookup which tracks whether each given asset name has a localized form. + /// This is a per-screen equivalent to the base game's field, since mods may provide different assets per-screen. + public PerScreen> LocalizedAssetNames { get; } = new(() => new()); + /********* ** Public methods @@ -245,6 +249,9 @@ namespace StardewModdingAPI.Framework { this.VanillaContentManager.Unload(); }); + + // forget localized flags (to match the logic in Game1.TranslateFields, which is called on language change) + this.LocalizedAssetNames.Value.Clear(); } /// Clean up when the player is returning to the title screen. @@ -275,6 +282,10 @@ namespace StardewModdingAPI.Framework // their changes, the assets won't be found in the cache so no changes will be propagated. if (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.en) this.InvalidateCache((contentManager, _, _) => contentManager is GameContentManager); + + // clear the localized assets lookup (to match the logic in Game1.CleanupReturningToTitle) + foreach ((_, Dictionary localizedAssets) in this.LocalizedAssetNames.GetActiveValues()) + localizedAssets.Clear(); } /// Parse a raw asset name. @@ -411,12 +422,15 @@ namespace StardewModdingAPI.Framework // A mod might provide a localized variant of a normally non-localized asset (like // `Maps/MovieTheater.fr-FR`). When the asset is invalidated, we need to recheck // whether the asset is localized in case it stops providing it. - foreach (IAssetName assetName in invalidatedAssets.Keys) { - LocalizedContentManager.localizedAssetNames.Remove(assetName.Name); + Dictionary localizedAssetNames = this.LocalizedAssetNames.Value; + foreach (IAssetName assetName in invalidatedAssets.Keys) + { + localizedAssetNames.Remove(assetName.Name); - if (LocalizedContentManager.localizedAssetNames.TryGetValue(assetName.BaseName, out string? targetForBaseKey) && targetForBaseKey == assetName.Name) - LocalizedContentManager.localizedAssetNames.Remove(assetName.BaseName); + if (localizedAssetNames.TryGetValue(assetName.BaseName, out string? targetForBaseKey) && targetForBaseKey == assetName.Name) + localizedAssetNames.Remove(assetName.BaseName); + } } // special case: maps may be loaded through a temporary content manager that's removed while the map is still in use. diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs index ddc02a8c..d7be0c37 100644 --- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs @@ -153,7 +153,9 @@ namespace StardewModdingAPI.Framework.ContentManagers return this.LoadExact(assetName, useCache: useCache); // check for localized asset - if (!LocalizedContentManager.localizedAssetNames.TryGetValue(assetName.Name, out _)) + // ReSharper disable once LocalVariableHidesMember -- this is deliberate + Dictionary localizedAssetNames = this.Coordinator.LocalizedAssetNames.Value; + if (!localizedAssetNames.TryGetValue(assetName.Name, out _)) { string localeCode = this.LanguageCodeString(language); IAssetName localizedName = new AssetName(baseName: assetName.BaseName, localeCode: localeCode, languageCode: language); @@ -161,7 +163,7 @@ namespace StardewModdingAPI.Framework.ContentManagers try { T data = this.LoadExact(localizedName, useCache: useCache); - LocalizedContentManager.localizedAssetNames[assetName.Name] = localizedName.Name; + localizedAssetNames[assetName.Name] = localizedName.Name; return data; } catch (ContentLoadException) @@ -170,18 +172,18 @@ namespace StardewModdingAPI.Framework.ContentManagers try { T data = this.LoadExact(localizedName, useCache: useCache); - LocalizedContentManager.localizedAssetNames[assetName.Name] = localizedName.Name; + localizedAssetNames[assetName.Name] = localizedName.Name; return data; } catch (ContentLoadException) { - LocalizedContentManager.localizedAssetNames[assetName.Name] = assetName.Name; + localizedAssetNames[assetName.Name] = assetName.Name; } } } // use cached key - string rawName = LocalizedContentManager.localizedAssetNames[assetName.Name]; + string rawName = localizedAssetNames[assetName.Name]; if (assetName.Name != rawName) assetName = this.Coordinator.ParseAssetName(rawName, allowLocales: this.TryLocalizeKeys); return this.LoadExact(assetName, useCache: useCache); -- cgit From e8c6221d967fd3b7387ecce879a082e7dead92da Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 26 May 2022 01:53:39 -0400 Subject: fix typo --- src/SMAPI/Framework/ContentManagers/ModContentManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI/Framework') diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs index 38a21383..1b94b8c6 100644 --- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs +++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs @@ -176,7 +176,7 @@ namespace StardewModdingAPI.Framework.ContentManagers return asset; } - /// Load an unpacked image file (.json). + /// Load an unpacked image file (.png). /// The type of asset to load. /// The asset name relative to the loader root directory. /// The file to load. -- cgit