add support for getting a patch helper for arbitrary data

This commit is contained in:
Jesse Plamondon-Willard 2020-04-24 17:53:58 -04:00
parent 4fae0158ed
commit beccea7efd
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
3 changed files with 21 additions and 0 deletions

View File

@ -17,6 +17,7 @@
* For modders:
* Added map patching to the content API (via `asset.AsMap()`).
* Added support for using patch helpers (e.g. for image/map patching) with arbitrary data (via `helper.Content.GetPatchHelper`).
* Added `SDate` fields/methods: `SeasonIndex`, `FromDaysSinceStart`, `FromWorldDate`, `ToWorldDate`, and `ToLocaleString` (thanks to kdau!).
* Added `SDate` translations taken from the Lookup Anything mod.¹
* Fixed asset propagation on Linux/Mac for monster sprites, NPC dialogue, and NPC schedules.

View File

@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI.Framework.Content;
using StardewModdingAPI.Framework.ContentManagers;
using StardewModdingAPI.Framework.Exceptions;
using StardewValley;
@ -164,6 +165,19 @@ namespace StardewModdingAPI.Framework.ModHelpers
return this.ContentCore.InvalidateCache(predicate).Any();
}
/// <summary>Get a patch helper for arbitrary data.</summary>
/// <typeparam name="T">The data type.</typeparam>
/// <param name="data">The asset data.</param>
/// <param name="assetName">The asset name. This is only used for tracking purposes and has no effect on the patch helper.</param>
public IAssetData GetPatchHelper<T>(T data, string assetName = null)
{
if (data == null)
throw new ArgumentNullException(nameof(data), "Can't get a patch helper for a null value.");
assetName ??= $"temp/{Guid.NewGuid():N}";
return new AssetDataForObject(this.CurrentLocale, assetName, data, this.NormalizeAssetName);
}
/*********
** Private methods

View File

@ -64,5 +64,11 @@ namespace StardewModdingAPI
/// <param name="predicate">A predicate matching the assets to invalidate.</param>
/// <returns>Returns whether any cache entries were invalidated.</returns>
bool InvalidateCache(Func<IAssetInfo, bool> predicate);
/// <summary>Get a patch helper for arbitrary data.</summary>
/// <typeparam name="T">The data type.</typeparam>
/// <param name="data">The asset data.</param>
/// <param name="assetName">The asset name. This is only used for tracking purposes and has no effect on the patch helper.</param>
IAssetData GetPatchHelper<T>(T data, string assetName = null);
}
}