diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs | 9 | ||||
-rw-r--r-- | src/StardewModdingAPI/IContentEventHelperForDictionary.cs | 4 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs index 8fcaae3c..9bfc16d8 100644 --- a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs +++ b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; namespace StardewModdingAPI.Framework.Content { @@ -32,5 +33,13 @@ namespace StardewModdingAPI.Framework.Content { this.Data[key] = value(this.Data[key]); } + + /// <summary>Dynamically replace values in the dictionary.</summary> + /// <param name="replacer">A lambda which takes the current key and value for an entry, and returns the new value.</param> + public void Replace(Func<TKey, TValue, TValue> replacer) + { + foreach (var pair in this.Data.ToArray()) + this.Data[pair.Key] = replacer(pair.Key, pair.Value); + } } } diff --git a/src/StardewModdingAPI/IContentEventHelperForDictionary.cs b/src/StardewModdingAPI/IContentEventHelperForDictionary.cs index 1f259920..34796d5c 100644 --- a/src/StardewModdingAPI/IContentEventHelperForDictionary.cs +++ b/src/StardewModdingAPI/IContentEventHelperForDictionary.cs @@ -36,6 +36,10 @@ namespace StardewModdingAPI /// <param name="value">A callback which accepts the current value and returns the new value.</param> void SetEntry(TKey key, Func<TValue, TValue> value); + /// <summary>Dynamically replace values in the dictionary.</summary> + /// <param name="replacer">A lambda which takes the current key and value for an entry, and returns the new value.</param> + void Replace(Func<TKey, TValue, TValue> replacer); + /// <summary>Replace the entire content value with the given value. This is generally not recommended, since it may break compatibility with other mods or different versions of the game.</summary> /// <param name="value">The new content value.</param> /// <exception cref="ArgumentNullException">The <paramref name="value"/> is null.</exception> |