summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md1
-rw-r--r--src/SMAPI/Framework/Content/AssetDataForImage.cs17
-rw-r--r--src/SMAPI/IAssetDataForImage.cs6
3 files changed, 24 insertions, 0 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index ea1f0bfb..f258caf8 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -15,6 +15,7 @@
* For modders:
* Added support for [message sending](https://stardewvalleywiki.com/Modding:Modder_Guide/APIs/Integrations#Message_sending) to mods on the current computer.
+ * Added `ExtendImage` method to content API when editing files to resize textures.
* Added `helper.Input.GetStatus` to get the low-level status of a button.
* **[Breaking change]** Map tilesheets are no loaded from `Content` if they can't be found in `Content/Maps`. This reflects an upcoming change in the game to delete map tilesheets under `Content`.
* Improved map tilesheet errors so they provide more info.
diff --git a/src/SMAPI/Framework/Content/AssetDataForImage.cs b/src/SMAPI/Framework/Content/AssetDataForImage.cs
index aa615a0b..44a97136 100644
--- a/src/SMAPI/Framework/Content/AssetDataForImage.cs
+++ b/src/SMAPI/Framework/Content/AssetDataForImage.cs
@@ -1,6 +1,7 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
+using StardewValley;
namespace StardewModdingAPI.Framework.Content
{
@@ -102,5 +103,21 @@ namespace StardewModdingAPI.Framework.Content
// patch target texture
target.SetData(0, targetArea, sourceData, 0, pixelCount);
}
+
+ /// <summary>Extend the image if needed to fit the given size. Note that this is an expensive operation, creates a new texture instance, and that extending a spritesheet horizontally may cause game errors or bugs.</summary>
+ /// <param name="minWidth">The minimum texture width.</param>
+ /// <param name="minHeight">The minimum texture height.</param>
+ /// <returns>Whether the texture was resized.</returns>
+ public bool ExtendImage(int minWidth, int minHeight)
+ {
+ if (this.Data.Width >= minWidth && this.Data.Height >= minHeight)
+ return false;
+
+ Texture2D original = this.Data;
+ Texture2D texture = new Texture2D(Game1.graphics.GraphicsDevice, Math.Max(original.Width, minWidth), Math.Max(original.Height, minHeight));
+ this.ReplaceWith(texture);
+ this.PatchImage(original);
+ return true;
+ }
}
}
diff --git a/src/SMAPI/IAssetDataForImage.cs b/src/SMAPI/IAssetDataForImage.cs
index 1109194f..27ed9267 100644
--- a/src/SMAPI/IAssetDataForImage.cs
+++ b/src/SMAPI/IAssetDataForImage.cs
@@ -19,5 +19,11 @@ 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>Extend the image if needed to fit the given size. Note that this is an expensive operation, creates a new texture instance, and that extending a spritesheet horizontally may cause game errors or bugs.</summary>
+ /// <param name="minWidth">The minimum texture width.</param>
+ /// <param name="minHeight">The minimum texture height.</param>
+ /// <returns>Whether the texture was resized.</returns>
+ bool ExtendImage(int minWidth, int minHeight);
}
}