fix PyTK compatibility mode not handling some edge cases

This commit is contained in:
Jesse Plamondon-Willard 2022-07-05 19:01:28 -04:00
parent bd88727948
commit f3a4b316b7
No known key found for this signature in database
GPG Key ID: CF8B1456B3E29F49
2 changed files with 8 additions and 21 deletions

View File

@ -11,6 +11,8 @@
* For players:
* Fixed lag which occurred for some players since Stardew Valley 1.5.5.
* Fixed `smapi-internal/config.user.json` overrides not applied after SMAPI 3.14.0.
* Fixed PyTK not rescaling images correctly in some cases.
_When PyTK 1.23.0 or earlier is installed, this will disable the main performance improvements in SMAPI 3.15.0._
* For mod authors:
* The [FluentHttpClient package](https://github.com/Pathoschild/FluentHttpClient#readme) is now loaded by SMAPI.

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
@ -47,9 +46,6 @@ namespace StardewModdingAPI.Framework.ContentManagers
/// <summary>If a map tilesheet's image source has no file extensions, the file extensions to check for in the local mod folder.</summary>
private static readonly string[] LocalTilesheetExtensions = { ".png", ".xnb" };
/// <summary>A lookup of image file paths to whether they have PyTK scaling information.</summary>
private static readonly Dictionary<string, bool> IsPyTkScaled = new(StringComparer.OrdinalIgnoreCase);
/*********
** Accessors
@ -211,24 +207,13 @@ namespace StardewModdingAPI.Framework.ContentManagers
{
if (ModContentManager.EnablePyTkLegacyMode)
{
if (!ModContentManager.IsPyTkScaled.TryGetValue(file.FullName, out bool isScaled))
{
string? dirPath = file.DirectoryName;
string fileName = $"{Path.GetFileNameWithoutExtension(file.Name)}.pytk.json";
string path = dirPath is not null
? Path.Combine(dirPath, fileName)
: fileName;
ModContentManager.IsPyTkScaled[file.FullName] = isScaled = File.Exists(path);
// PyTK intercepts Texture2D file loads to rescale them (e.g. for HD portraits),
// but doesn't support IRawTextureData loads yet. We can't just check if the
// current file has a '.pytk.json' rescale file though, since PyTK may still
// rescale it if the original asset or another edit gets rescaled.
asRawData = false;
this.Monitor.LogOnce("Enabled compatibility mode for PyTK 1.23.0 or earlier. This won't cause any issues, but may impact performance.", LogLevel.Warn);
}
asRawData = !isScaled;
if (!asRawData)
this.Monitor.LogOnce("Enabled compatibility mode for PyTK scaled textures. This won't cause any issues, but may impact performance.", LogLevel.Warn);
}
else
asRawData = true;
}
// load