diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-10 11:05:17 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-03-10 11:05:17 -0500 |
commit | ff39e9b1716104e02c92dfd56bb919887873bd3d (patch) | |
tree | f6de4195f2647dbfa5a416f3dfd9ac9a5e120377 | |
parent | edbbb7cff41ba0656bd17774a3d5d99dd321dd9b (diff) | |
download | SMAPI-ff39e9b1716104e02c92dfd56bb919887873bd3d.tar.gz SMAPI-ff39e9b1716104e02c92dfd56bb919887873bd3d.tar.bz2 SMAPI-ff39e9b1716104e02c92dfd56bb919887873bd3d.zip |
move generic content properties & methods into separate interface (#173)
6 files changed, 40 insertions, 71 deletions
diff --git a/src/StardewModdingAPI/Framework/Content/ContentEventBaseHelper.cs b/src/StardewModdingAPI/Framework/Content/ContentEventBaseHelper.cs index 736cdc70..a89fe337 100644 --- a/src/StardewModdingAPI/Framework/Content/ContentEventBaseHelper.cs +++ b/src/StardewModdingAPI/Framework/Content/ContentEventBaseHelper.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 + internal class ContentEventBaseHelper<TValue> : EventArgs, IContentEventData<TValue> { /********* ** Properties diff --git a/src/StardewModdingAPI/IContentEventData.cs b/src/StardewModdingAPI/IContentEventData.cs new file mode 100644 index 00000000..a21861d2 --- /dev/null +++ b/src/StardewModdingAPI/IContentEventData.cs @@ -0,0 +1,35 @@ +using System; + +namespace StardewModdingAPI +{ + /// <summary>Generic metadata and methods for a content asset being loaded.</summary> + /// <typeparam name="TValue">The expected data type.</typeparam> + public interface IContentEventData<TValue> + { + /********* + ** Accessors + *********/ + /// <summary>The content's locale code, if the content is localised.</summary> + string Locale { get; } + + /// <summary>The normalised asset name being read. The format may change between platforms; see <see cref="IsAssetName"/> to compare with a known path.</summary> + string AssetName { get; } + + /// <summary>The content data being read.</summary> + TValue Data { get; } + + + /********* + ** Public methods + *********/ + /// <summary>Get whether the asset name being loaded matches a given name after normalisation.</summary> + /// <param name="path">The expected asset path, relative to the game's content folder and without the .xnb extension or locale suffix (like 'Data\ObjectInformation').</param> + bool IsAssetName(string path); + + /// <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> + /// <exception cref="InvalidCastException">The <paramref name="value"/>'s type is not compatible with the loaded asset's type.</exception> + void ReplaceWith(TValue value); + } +} diff --git a/src/StardewModdingAPI/IContentEventHelper.cs b/src/StardewModdingAPI/IContentEventHelper.cs index 341778b4..421a1e06 100644 --- a/src/StardewModdingAPI/IContentEventHelper.cs +++ b/src/StardewModdingAPI/IContentEventHelper.cs @@ -3,28 +3,11 @@ namespace StardewModdingAPI { /// <summary>Encapsulates access and changes to content being read from a data file.</summary> - public interface IContentEventHelper + public interface IContentEventHelper : IContentEventData<object> { /********* - ** Accessors - *********/ - /// <summary>The content's locale code, if the content is localised.</summary> - string Locale { get; } - - /// <summary>The normalised asset name being read. The format may change between platforms; see <see cref="IsAssetName"/> to compare with a known path.</summary> - string AssetName { get; } - - /// <summary>The content data being read.</summary> - object Data { get; } - - - /********* ** Public methods *********/ - /// <summary>Get whether the asset name being loaded matches a given name after normalisation.</summary> - /// <param name="path">The expected asset path, relative to the game's content folder and without the .xnb extension or locale suffix (like 'Data\ObjectInformation').</param> - bool IsAssetName(string path); - /// <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> @@ -39,11 +22,5 @@ namespace StardewModdingAPI /// <typeparam name="TData">The expected data type.</typeparam> /// <exception cref="InvalidCastException">The data can't be converted to <typeparamref name="TData"/>.</exception> TData GetData<TData>(); - - /// <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> - /// <exception cref="InvalidCastException">The <paramref name="value"/>'s type is not compatible with the loaded asset's type.</exception> - void ReplaceWith(object value); } } diff --git a/src/StardewModdingAPI/IContentEventHelperForDictionary.cs b/src/StardewModdingAPI/IContentEventHelperForDictionary.cs index 34e69d42..2f9d5a65 100644 --- a/src/StardewModdingAPI/IContentEventHelperForDictionary.cs +++ b/src/StardewModdingAPI/IContentEventHelperForDictionary.cs @@ -4,28 +4,11 @@ using System.Collections.Generic; namespace StardewModdingAPI { /// <summary>Encapsulates access and changes to dictionary content being read from a data file.</summary> - public interface IContentEventHelperForDictionary<TKey, TValue> + public interface IContentEventHelperForDictionary<TKey, TValue> : IContentEventData<IDictionary<TKey, TValue>> { /********* - ** Accessors - *********/ - /// <summary>The content's locale code, if the content is localised.</summary> - string Locale { get; } - - /// <summary>The normalised asset name being read. The format may change between platforms; see <see cref="IsAssetName"/> to compare with a known path.</summary> - string AssetName { get; } - - /// <summary>The content data being read.</summary> - IDictionary<TKey, TValue> Data { get; } - - - /********* ** Public methods *********/ - /// <summary>Get whether the asset name being loaded matches a given name after normalisation.</summary> - /// <param name="path">The expected asset path, relative to the game's content folder and without the .xnb extension or locale suffix (like 'Data\ObjectInformation').</param> - bool IsAssetName(string path); - /// <summary>Add or replace an entry in the dictionary.</summary> /// <param name="key">The entry key.</param> /// <param name="value">The entry value.</param> @@ -39,10 +22,5 @@ namespace StardewModdingAPI /// <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 Set(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> - void ReplaceWith(IDictionary<TKey, TValue> value); } } diff --git a/src/StardewModdingAPI/IContentEventHelperForImage.cs b/src/StardewModdingAPI/IContentEventHelperForImage.cs index 14bc23a4..1158c868 100644 --- a/src/StardewModdingAPI/IContentEventHelperForImage.cs +++ b/src/StardewModdingAPI/IContentEventHelperForImage.cs @@ -5,28 +5,11 @@ using Microsoft.Xna.Framework.Graphics; namespace StardewModdingAPI { /// <summary>Encapsulates access and changes to dictionary content being read from a data file.</summary> - public interface IContentEventHelperForImage + public interface IContentEventHelperForImage : IContentEventData<Texture2D> { /********* - ** Accessors - *********/ - /// <summary>The content's locale code, if the content is localised.</summary> - string Locale { get; } - - /// <summary>The normalised asset name being read. The format may change between platforms; see <see cref="IsAssetName"/> to compare with a known path.</summary> - string AssetName { get; } - - /// <summary>The content data being read.</summary> - Texture2D Data { get; } - - - /********* ** Public methods *********/ - /// <summary>Get whether the asset name being loaded matches a given name after normalisation.</summary> - /// <param name="path">The expected asset path, relative to the game's content folder and without the .xnb extension or locale suffix (like 'Data\ObjectInformation').</param> - bool IsAssetName(string path); - /// <summary>Overwrite part of the image.</summary> /// <param name="source">The image to patch into the content.</param> /// <param name="sourceArea">The part of the <paramref name="source"/> to copy (or <c>null</c> to take the whole texture). This must be within the bounds of the <paramref name="source"/> texture.</param> @@ -36,10 +19,5 @@ namespace StardewModdingAPI /// <exception cref="ArgumentOutOfRangeException">The <paramref name="targetArea"/> is outside the bounds of the spritesheet.</exception> /// <exception cref="InvalidOperationException">The content being read isn't an image.</exception> void PatchImage(Texture2D source, Rectangle? sourceArea = null, Rectangle? targetArea = null, PatchMode patchMode = PatchMode.Replace); - - /// <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> - void ReplaceWith(Texture2D value); } } diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 478d1af0..445f6f37 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -168,6 +168,7 @@ <Compile Include="IContentEventHelper.cs" /> <Compile Include="IContentEventHelperForDictionary.cs" /> <Compile Include="IContentEventHelperForImage.cs" /> + <Compile Include="IContentEventData.cs" /> <Compile Include="IModRegistry.cs" /> <Compile Include="Events\LocationEvents.cs" /> <Compile Include="Events\MenuEvents.cs" /> |