summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-03-08 15:25:30 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-03-08 15:25:30 -0500
commitb2e88bccf63545d950f4cbf47a0466321c614245 (patch)
treee7c96f0129322a9b6df2e1bef064580f45bd4056 /src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs
parentdfaed472b0e7f1e35ad07eea427fe5034b40ddc7 (diff)
downloadSMAPI-b2e88bccf63545d950f4cbf47a0466321c614245.tar.gz
SMAPI-b2e88bccf63545d950f4cbf47a0466321c614245.tar.bz2
SMAPI-b2e88bccf63545d950f4cbf47a0466321c614245.zip
add dictionary/image content helpers for more intuitive usage (#173)
Diffstat (limited to 'src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs')
-rw-r--r--src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs
new file mode 100644
index 00000000..8fcaae3c
--- /dev/null
+++ b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs
@@ -0,0 +1,36 @@
+using System;
+using System.Collections.Generic;
+
+namespace StardewModdingAPI.Framework.Content
+{
+ /// <summary>Encapsulates access and changes to dictionary content being read from a data file.</summary>
+ internal class ContentEventHelperForDictionary<TKey, TValue> : ContentEventBaseHelper<IDictionary<TKey, TValue>>, IContentEventHelperForDictionary<TKey, TValue>
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Construct an instance.</summary>
+ /// <param name="locale">The content's locale code, if the content is localised.</param>
+ /// <param name="assetName">The normalised asset name being read.</param>
+ /// <param name="data">The content data being read.</param>
+ /// <param name="getNormalisedPath">Normalises an asset key to match the cache key.</param>
+ public ContentEventHelperForDictionary(string locale, string assetName, IDictionary<TKey, TValue> data, Func<string, string> getNormalisedPath)
+ : base(locale, assetName, data, getNormalisedPath) { }
+
+ /// <summary>Add or replace an entry in the dictionary data.</summary>
+ /// <param name="key">The entry key.</param>
+ /// <param name="value">The entry value.</param>
+ public void SetEntry(TKey key, TValue value)
+ {
+ this.Data[key] = value;
+ }
+
+ /// <summary>Add or replace an entry in the dictionary data.</summary>
+ /// <param name="key">The entry key.</param>
+ /// <param name="value">A callback which accepts the current value and returns the new value.</param>
+ public void SetEntry(TKey key, Func<TValue, TValue> value)
+ {
+ this.Data[key] = value(this.Data[key]);
+ }
+ }
+}