diff options
Diffstat (limited to 'src/StardewModdingAPI/Framework/Content')
-rw-r--r-- | src/StardewModdingAPI/Framework/Content/ContentEventData.cs (renamed from src/StardewModdingAPI/Framework/Content/ContentEventBaseHelper.cs) | 21 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs | 2 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs | 2 | ||||
-rw-r--r-- | src/StardewModdingAPI/Framework/Content/ContentEventHelperForImage.cs | 2 |
4 files changed, 20 insertions, 7 deletions
diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventBaseHelper.cs b/src/StardewModdingAPI/Framework/Content/ContentEventData.cs index a89fe337..1a1779d4 100644 --- a/src/StardewModdingAPI/Framework/Content/ContentEventBaseHelper.cs +++ b/src/StardewModdingAPI/Framework/Content/ContentEventData.cs @@ -6,7 +6,7 @@ namespace StardewModdingAPI.Framework.Content { /// <summary>Base implementation for a content helper which encapsulates access and changes to content being read from a data file.</summary> /// <typeparam name="TValue">The interface value type.</typeparam> - internal class ContentEventBaseHelper<TValue> : EventArgs, IContentEventData<TValue> + internal class ContentEventData<TValue> : EventArgs, IContentEventData<TValue> { /********* ** Properties @@ -27,6 +27,9 @@ namespace StardewModdingAPI.Framework.Content /// <summary>The content data being read.</summary> public TValue Data { get; protected set; } + /// <summary>The content data type.</summary> + public Type DataType { get; } + /********* ** Public methods @@ -36,11 +39,21 @@ namespace StardewModdingAPI.Framework.Content /// <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 ContentEventBaseHelper(string locale, string assetName, TValue data, Func<string, string> getNormalisedPath) + public ContentEventData(string locale, string assetName, TValue data, Func<string, string> getNormalisedPath) + : this(locale, assetName, data, data.GetType(), getNormalisedPath) { } + + /// <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="dataType">The content data type being read.</param> + /// <param name="getNormalisedPath">Normalises an asset key to match the cache key.</param> + public ContentEventData(string locale, string assetName, TValue data, Type dataType, Func<string, string> getNormalisedPath) { this.Locale = locale; this.AssetName = assetName; this.Data = data; + this.DataType = dataType; this.GetNormalisedPath = getNormalisedPath; } @@ -60,8 +73,8 @@ namespace StardewModdingAPI.Framework.Content { if (value == null) throw new ArgumentNullException(nameof(value), "Can't set a loaded asset to a null value."); - if (!this.Data.GetType().IsInstanceOfType(value)) - throw new InvalidCastException($"Can't replace loaded asset of type {this.GetFriendlyTypeName(this.Data.GetType())} with value of type {this.GetFriendlyTypeName(value.GetType())}. The new type must be compatible to prevent game errors."); + if (!this.DataType.IsInstanceOfType(value)) + throw new InvalidCastException($"Can't replace loaded asset of type {this.GetFriendlyTypeName(this.DataType)} with value of type {this.GetFriendlyTypeName(value.GetType())}. The new type must be compatible to prevent game errors."); this.Data = value; } diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs b/src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs index 26292cab..9bf1ea17 100644 --- a/src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs +++ b/src/StardewModdingAPI/Framework/Content/ContentEventHelper.cs @@ -5,7 +5,7 @@ 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 : ContentEventBaseHelper<object>, IContentEventHelper + internal class ContentEventHelper : ContentEventData<object>, IContentEventHelper { /********* ** Public methods diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs index 8a8a4845..26f059e4 100644 --- a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs +++ b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForDictionary.cs @@ -5,7 +5,7 @@ using System.Linq; 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> + internal class ContentEventHelperForDictionary<TKey, TValue> : ContentEventData<IDictionary<TKey, TValue>>, IContentEventHelperForDictionary<TKey, TValue> { /********* ** Public methods diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForImage.cs b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForImage.cs index 23760f0f..da30590b 100644 --- a/src/StardewModdingAPI/Framework/Content/ContentEventHelperForImage.cs +++ b/src/StardewModdingAPI/Framework/Content/ContentEventHelperForImage.cs @@ -5,7 +5,7 @@ using Microsoft.Xna.Framework.Graphics; namespace StardewModdingAPI.Framework.Content { /// <summary>Encapsulates access and changes to dictionary content being read from a data file.</summary> - internal class ContentEventHelperForImage : ContentEventBaseHelper<Texture2D>, IContentEventHelperForImage + internal class ContentEventHelperForImage : ContentEventData<Texture2D>, IContentEventHelperForImage { /********* ** Public methods |