diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-14 11:44:02 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-10-14 11:44:02 -0400 |
commit | 79118316065a01322d8ea12a14589ec016794c32 (patch) | |
tree | 7a26668a66ea0630a2b9367ac820fe7a6d99ac77 /src/StardewModdingAPI/Framework/Content/AssetDataForObject.cs | |
parent | af1a2bde8219c5d4b8660b13702725626a4a5647 (diff) | |
parent | 8aec1eff99858716afe7b8604b512181f78c214f (diff) | |
download | SMAPI-79118316065a01322d8ea12a14589ec016794c32.tar.gz SMAPI-79118316065a01322d8ea12a14589ec016794c32.tar.bz2 SMAPI-79118316065a01322d8ea12a14589ec016794c32.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/StardewModdingAPI/Framework/Content/AssetDataForObject.cs')
-rw-r--r-- | src/StardewModdingAPI/Framework/Content/AssetDataForObject.cs | 54 |
1 files changed, 0 insertions, 54 deletions
diff --git a/src/StardewModdingAPI/Framework/Content/AssetDataForObject.cs b/src/StardewModdingAPI/Framework/Content/AssetDataForObject.cs deleted file mode 100644 index f30003e4..00000000 --- a/src/StardewModdingAPI/Framework/Content/AssetDataForObject.cs +++ /dev/null @@ -1,54 +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 AssetDataForObject : AssetData<object>, IAssetData - { - /********* - ** 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 AssetDataForObject(string locale, string assetName, object data, Func<string, string> getNormalisedPath) - : base(locale, assetName, data, getNormalisedPath) { } - - /// <summary>Construct an instance.</summary> - /// <param name="info">The asset metadata.</param> - /// <param name="data">The content data being read.</param> - /// <param name="getNormalisedPath">Normalises an asset key to match the cache key.</param> - public AssetDataForObject(IAssetInfo info, object data, Func<string, string> getNormalisedPath) - : this(info.Locale, info.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 IAssetDataForDictionary<TKey, TValue> AsDictionary<TKey, TValue>() - { - return new AssetDataForDictionary<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 IAssetDataForImage AsImage() - { - return new AssetDataForImage(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; - } - } -} |