set texture name earlier to support mods like SpriteMaster
This commit is contained in:
parent
9a15da5a17
commit
037d7e357b
|
@ -22,6 +22,7 @@
|
|||
* When [providing a mod API for a C# mod](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Integrations), you can now get an optional parameter with the mod requesting the API (thanks to KhloeLeclair!). This avoids needing the pattern where each method needs the requesting mod's manifest.
|
||||
* SMAPI now treats square brackets in the manifest `Name` field as round ones to avoid breaking tools which parse log files.
|
||||
* Made deprecation message wording stronger for the upcoming SMAPI 4.0.0 release.
|
||||
* The `Texture2D.Name` field is now set earlier to support mods like SpriteMaster.
|
||||
* Updated dependencies: [Harmony](https://harmony.pardeike.net) 2.2.2 (see [changes](https://github.com/pardeike/Harmony/releases/tag/v2.2.2.0)) and [FluentHttpClient](https://github.com/Pathoschild/FluentHttpClient#readme) 4.2.0 (see [changes](https://github.com/Pathoschild/FluentHttpClient/blob/develop/RELEASE-NOTES.md#420)).
|
||||
* Fixed `LocationListChanged` event not raised & memory leak occurring when a generated mine/volcano is removed (thanks to tylergibbs2!).
|
||||
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace StardewModdingAPI.Framework.Content
|
|||
return false;
|
||||
|
||||
Texture2D original = this.Data;
|
||||
Texture2D texture = new(Game1.graphics.GraphicsDevice, Math.Max(original.Width, minWidth), Math.Max(original.Height, minHeight));
|
||||
Texture2D texture = new Texture2D(Game1.graphics.GraphicsDevice, Math.Max(original.Width, minWidth), Math.Max(original.Height, minHeight)).SetName(original.Name);
|
||||
this.ReplaceWith(texture);
|
||||
this.PatchImage(original);
|
||||
return true;
|
||||
|
|
|
@ -336,7 +336,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
|||
{
|
||||
// track asset key
|
||||
if (value is Texture2D texture)
|
||||
texture.Name = assetName.Name;
|
||||
texture.SetName(assetName);
|
||||
|
||||
// save to cache
|
||||
// Note: even if the asset was loaded and cached right before this method was called,
|
||||
|
|
|
@ -232,7 +232,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
|||
return (T)raw;
|
||||
else
|
||||
{
|
||||
Texture2D texture = new(Game1.graphics.GraphicsDevice, raw.Width, raw.Height);
|
||||
Texture2D texture = new Texture2D(Game1.graphics.GraphicsDevice, raw.Width, raw.Height).SetName(assetName);
|
||||
texture.SetData(raw.Data);
|
||||
return (T)(object)texture;
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ namespace StardewModdingAPI.Framework.ContentManagers
|
|||
else
|
||||
{
|
||||
using FileStream stream = File.OpenRead(file.FullName);
|
||||
Texture2D texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, stream);
|
||||
Texture2D texture = Texture2D.FromStream(Game1.graphics.GraphicsDevice, stream).SetName(assetName);
|
||||
this.PremultiplyTransparency(texture);
|
||||
return (T)(object)texture;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
@ -163,5 +164,34 @@ namespace StardewModdingAPI.Framework
|
|||
{
|
||||
return reflection.GetField<bool>(spriteBatch, "_beginCalled").GetValue();
|
||||
}
|
||||
|
||||
/****
|
||||
** Texture2D
|
||||
****/
|
||||
/// <summary>Set the texture name field.</summary>
|
||||
/// <param name="texture">The texture whose name to set.</param>
|
||||
/// <param name="assetName">The asset name to set.</param>
|
||||
/// <returns>Returns the texture for chaining.</returns>
|
||||
[return: NotNullIfNotNull("texture")]
|
||||
public static Texture2D? SetName(this Texture2D? texture, IAssetName assetName)
|
||||
{
|
||||
if (texture != null)
|
||||
texture.Name = assetName.Name;
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
/// <summary>Set the texture name field.</summary>
|
||||
/// <param name="texture">The texture whose name to set.</param>
|
||||
/// <param name="assetName">The asset name to set.</param>
|
||||
/// <returns>Returns the texture for chaining.</returns>
|
||||
[return: NotNullIfNotNull("texture")]
|
||||
public static Texture2D? SetName(this Texture2D? texture, string assetName)
|
||||
{
|
||||
if (texture != null)
|
||||
texture.Name = assetName;
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue