summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-10-09 17:39:11 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-10-09 17:39:11 -0400
commit037d7e357b169936fa858f6c8b9c1388ca75840b (patch)
treec197acab05a908d2ce36d35e981866715020644c /src/SMAPI
parent9a15da5a173e5e218c16e2e4ef0af0c98968e1cb (diff)
downloadSMAPI-037d7e357b169936fa858f6c8b9c1388ca75840b.tar.gz
SMAPI-037d7e357b169936fa858f6c8b9c1388ca75840b.tar.bz2
SMAPI-037d7e357b169936fa858f6c8b9c1388ca75840b.zip
set texture name earlier to support mods like SpriteMaster
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/Content/AssetDataForImage.cs2
-rw-r--r--src/SMAPI/Framework/ContentManagers/BaseContentManager.cs2
-rw-r--r--src/SMAPI/Framework/ContentManagers/ModContentManager.cs4
-rw-r--r--src/SMAPI/Framework/InternalExtensions.cs30
4 files changed, 34 insertions, 4 deletions
diff --git a/src/SMAPI/Framework/Content/AssetDataForImage.cs b/src/SMAPI/Framework/Content/AssetDataForImage.cs
index 0380dd9e..241c09a8 100644
--- a/src/SMAPI/Framework/Content/AssetDataForImage.cs
+++ b/src/SMAPI/Framework/Content/AssetDataForImage.cs
@@ -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;
diff --git a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
index 54f8e2a2..1e9f4ffe 100644
--- a/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/BaseContentManager.cs
@@ -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,
diff --git a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
index 72dcf6e1..30dd4215 100644
--- a/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
+++ b/src/SMAPI/Framework/ContentManagers/ModContentManager.cs
@@ -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;
}
diff --git a/src/SMAPI/Framework/InternalExtensions.cs b/src/SMAPI/Framework/InternalExtensions.cs
index ba9bbcec..7ad30d35 100644
--- a/src/SMAPI/Framework/InternalExtensions.cs
+++ b/src/SMAPI/Framework/InternalExtensions.cs
@@ -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;
+ }
}
}