From 6a9bf10a81f4557d44668666117d99440d99d873 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 20 Feb 2020 21:12:00 -0500 Subject: [PATCH] migrate to new method in SMAPI 3.3 --- docs/release-notes.md | 1 + .../Framework/Content/AssetDataForImage.cs | 17 +++++++++++++++++ src/SMAPI/IAssetDataForImage.cs | 6 ++++++ 3 files changed, 24 insertions(+) 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); } + + /// 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. + /// The minimum texture width. + /// The minimum texture height. + /// Whether the texture was resized. + 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 /// The is outside the bounds of the spritesheet. /// The content being read isn't an image. void PatchImage(Texture2D source, Rectangle? sourceArea = null, Rectangle? targetArea = null, PatchMode patchMode = PatchMode.Replace); + + /// 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. + /// The minimum texture width. + /// The minimum texture height. + /// Whether the texture was resized. + bool ExtendImage(int minWidth, int minHeight); } }