Merge pull request #886 from atravita-mods/develop
Fix overlay transparency crop not always starting at end of pixel area
This commit is contained in:
commit
0f7026c1b1
|
@ -140,9 +140,11 @@ namespace StardewModdingAPI.Framework.Content
|
|||
/// <exception cref="InvalidOperationException">The content being read isn't an image.</exception>
|
||||
private void PatchImageImpl(Color[] sourceData, int sourceWidth, int sourceHeight, Rectangle sourceArea, Rectangle targetArea, PatchMode patchMode, int startRow = 0)
|
||||
{
|
||||
// get texture
|
||||
// get texture info
|
||||
Texture2D target = this.Data;
|
||||
int pixelCount = sourceArea.Width * sourceArea.Height;
|
||||
int firstPixel = startRow * sourceArea.Width;
|
||||
int lastPixel = firstPixel + pixelCount - 1;
|
||||
|
||||
// validate
|
||||
if (sourceArea.X < 0 || sourceArea.Y < 0 || sourceArea.Right > sourceWidth || sourceArea.Bottom > sourceHeight)
|
||||
|
@ -155,15 +157,14 @@ namespace StardewModdingAPI.Framework.Content
|
|||
// shortcut: replace the entire area
|
||||
if (patchMode == PatchMode.Replace)
|
||||
{
|
||||
target.SetData(0, targetArea, sourceData, startRow * sourceArea.Width, pixelCount);
|
||||
target.SetData(0, targetArea, sourceData, firstPixel, pixelCount);
|
||||
return;
|
||||
}
|
||||
|
||||
// skip transparent pixels at the start & end (e.g. large spritesheet with a few sprites replaced)
|
||||
int startIndex = -1;
|
||||
int endIndex = -1;
|
||||
{
|
||||
for (int i = startRow * sourceArea.Width; i < pixelCount; i++)
|
||||
for (int i = firstPixel; i <= lastPixel; i++)
|
||||
{
|
||||
if (sourceData[i].A >= AssetDataForImage.MinOpacity)
|
||||
{
|
||||
|
@ -174,7 +175,7 @@ namespace StardewModdingAPI.Framework.Content
|
|||
if (startIndex == -1)
|
||||
return; // blank texture
|
||||
|
||||
for (int i = startRow * sourceArea.Width + pixelCount - 1; i >= startIndex; i--)
|
||||
for (int i = lastPixel; i >= startIndex; i--)
|
||||
{
|
||||
if (sourceData[i].A >= AssetDataForImage.MinOpacity)
|
||||
{
|
||||
|
@ -184,7 +185,6 @@ namespace StardewModdingAPI.Framework.Content
|
|||
}
|
||||
if (endIndex == -1)
|
||||
return; // ???
|
||||
}
|
||||
|
||||
// update target rectangle
|
||||
int sourceOffset;
|
||||
|
|
Loading…
Reference in New Issue