summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-06-09 21:13:01 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-07-01 12:18:41 -0400
commit49c75de5fc139144b152207ba05f2936a2d25904 (patch)
tree537234c4f7c3d99323edbc77ae9f4619d4fcc568 /src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs
parent7b6b2742f65ac1d2590357babc517b6cd9b69d04 (diff)
downloadSMAPI-49c75de5fc139144b152207ba05f2936a2d25904.tar.gz
SMAPI-49c75de5fc139144b152207ba05f2936a2d25904.tar.bz2
SMAPI-49c75de5fc139144b152207ba05f2936a2d25904.zip
rewrite content interception using latest proposed API (#255)
Diffstat (limited to 'src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs')
-rw-r--r--src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs47
1 files changed, 0 insertions, 47 deletions
diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs b/src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs
deleted file mode 100644
index 9bf1ea17..00000000
--- a/src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs
+++ /dev/null
@@ -1,47 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Microsoft.Xna.Framework.Graphics;
-
-namespace StardewModdingAPI.Framework.Content
-{
- /// <summary>Encapsulates access and changes to content being read from a data file.</summary>
- internal class ContentEventHelper : ContentEventData<object>, IContentEventHelper
- {
- /*********
- ** 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 ContentEventHelper(string locale, string assetName, object data, Func<string, string> getNormalisedPath)
- : base(locale, assetName, data, getNormalisedPath) { }
-
- /// <summary>Get a helper to manipulate the data as a dictionary.</summary>
- /// <typeparam name="TKey">The expected dictionary key.</typeparam>
- /// <typeparam name="TValue">The expected dictionary balue.</typeparam>
- /// <exception cref="InvalidOperationException">The content being read isn't a dictionary.</exception>
- public IContentEventHelperForDictionary<TKey, TValue> AsDictionary<TKey, TValue>()
- {
- return new ContentEventHelperForDictionary<TKey, TValue>(this.Locale, this.AssetName, this.GetData<IDictionary<TKey, TValue>>(), this.GetNormalisedPath);
- }
-
- /// <summary>Get a helper to manipulate the data as an image.</summary>
- /// <exception cref="InvalidOperationException">The content being read isn't an image.</exception>
- public IContentEventHelperForImage AsImage()
- {
- return new ContentEventHelperForImage(this.Locale, this.AssetName, this.GetData<Texture2D>(), this.GetNormalisedPath);
- }
-
- /// <summary>Get the data as a given type.</summary>
- /// <typeparam name="TData">The expected data type.</typeparam>
- /// <exception cref="InvalidCastException">The data can't be converted to <typeparamref name="TData"/>.</exception>
- public TData GetData<TData>()
- {
- if (!(this.Data is TData))
- throw new InvalidCastException($"The content data of type {this.Data.GetType().FullName} can't be converted to the requested {typeof(TData).FullName}.");
- return (TData)this.Data;
- }
- }
-}