diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-11-14 17:28:59 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-11-14 17:28:59 -0500 |
commit | ae5829a3ee5ab1bde79735c6f3a0004f6047a922 (patch) | |
tree | 0c459b0e06fbbad1928e703b2dff12af4d4aad34 /src/SMAPI/Framework/Content | |
parent | e2c1d2b1c9ff03853e77faf6d36b2a27f219b488 (diff) | |
download | SMAPI-ae5829a3ee5ab1bde79735c6f3a0004f6047a922.tar.gz SMAPI-ae5829a3ee5ab1bde79735c6f3a0004f6047a922.tar.bz2 SMAPI-ae5829a3ee5ab1bde79735c6f3a0004f6047a922.zip |
tweak variables for clarity
Diffstat (limited to 'src/SMAPI/Framework/Content')
-rw-r--r-- | src/SMAPI/Framework/Content/AssetDataForImage.cs | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/SMAPI/Framework/Content/AssetDataForImage.cs b/src/SMAPI/Framework/Content/AssetDataForImage.cs index 5832570b..89ced1ba 100644 --- a/src/SMAPI/Framework/Content/AssetDataForImage.cs +++ b/src/SMAPI/Framework/Content/AssetDataForImage.cs @@ -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,37 +157,34 @@ 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 = firstPixel; i <= lastPixel; i++) { - int endPixel = pixelCount + startRow * sourceArea.Width; - for (int i = startRow * sourceArea.Width; i < endPixel; i++) + if (sourceData[i].A >= AssetDataForImage.MinOpacity) { - if (sourceData[i].A >= AssetDataForImage.MinOpacity) - { - startIndex = i; - break; - } + startIndex = i; + break; } - if (startIndex == -1) - return; // blank texture + } + if (startIndex == -1) + return; // blank texture - for (int i = endPixel - 1; i >= startIndex; i--) + for (int i = lastPixel; i >= startIndex; i--) + { + if (sourceData[i].A >= AssetDataForImage.MinOpacity) { - if (sourceData[i].A >= AssetDataForImage.MinOpacity) - { - endIndex = i; - break; - } + endIndex = i; + break; } - if (endIndex == -1) - return; // ??? } + if (endIndex == -1) + return; // ??? // update target rectangle int sourceOffset; |