Fix caches in other systems (#950)

## Bug fixes

- Fixed slide reel caches in multi-system mods
This commit is contained in:
xen-42 2024-10-04 21:27:31 -04:00 committed by GitHub
commit 490b168364
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 8 deletions

View File

@ -18,8 +18,9 @@ namespace NewHorizons.Builder.Props
{
public static class ProjectionBuilder
{
public const string INVERTED_SLIDE_CACHE_FOLDER = "SlideReelCache/Inverted";
public const string ATLAS_SLIDE_CACHE_FOLDER = "SlideReelCache/Atlas";
public static string CurrentSlideReelFolder => "SlideReelCache_" + Main.Instance.CurrentStarSystem;
public static string InvertedSlideReelCacheFolder => CurrentSlideReelFolder + "/Inverted";
public static string AtlasSlideReelCacheFolder => CurrentSlideReelFolder + "/Atlas";
public static GameObject SlideReelWholePrefab { get; private set; }
public static GameObject SlideReelWholePristinePrefab { get; private set; }
@ -45,7 +46,7 @@ namespace NewHorizons.Builder.Props
private static bool _isInit;
public static bool CacheExists(IModBehaviour mod) => Directory.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ATLAS_SLIDE_CACHE_FOLDER));
public static bool CacheExists(IModBehaviour mod) => Directory.Exists(Path.Combine(mod.ModHelper.Manifest.ModFolderPath, AtlasSlideReelCacheFolder));
internal static void InitPrefabs()
{
@ -521,7 +522,7 @@ namespace NewHorizons.Builder.Props
{
NHLogger.LogVerbose($"The atlas cache for slide reel containing [{slides.FirstOrDefault(x => !string.IsNullOrEmpty(x.imagePath))?.imagePath}] is {atlasKey}");
// Load the atlas texture used to draw onto the physical slide reel object
atlasImageLoader.PathsToLoad.Add((0, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ATLAS_SLIDE_CACHE_FOLDER, $"{atlasKey}.png")));
atlasImageLoader.PathsToLoad.Add((0, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, AtlasSlideReelCacheFolder, $"{atlasKey}.png")));
}
for (int i = 0; i < slides.Length; i++)
@ -548,7 +549,7 @@ namespace NewHorizons.Builder.Props
if (useInvertedCache && cacheExists)
{
// Load the inverted images used when displaying slide reels to a screen
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, INVERTED_SLIDE_CACHE_FOLDER, slideInfo.imagePath)));
invertedImageLoader.PathsToLoad.Add((i, Path.Combine(mod.ModHelper.Manifest.ModFolderPath, InvertedSlideReelCacheFolder, slideInfo.imagePath)));
}
else
{

View File

@ -114,7 +114,7 @@ namespace NewHorizons.Utility.Files
// Not sure why we check if the originalPath is null but it did that before so
if (!string.IsNullOrEmpty(originalPath))
{
cachedPath = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ProjectionBuilder.INVERTED_SLIDE_CACHE_FOLDER, originalPath.Replace(mod.ModHelper.Manifest.ModFolderPath, ""));
cachedPath = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ProjectionBuilder.InvertedSlideReelCacheFolder, originalPath.Replace(mod.ModHelper.Manifest.ModFolderPath, ""));
key = GetKey(cachedPath);
}
@ -216,7 +216,7 @@ namespace NewHorizons.Utility.Files
// Since doing this is expensive we cache the results to the disk
// Preloading cached values is done in ProjectionBuilder
var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ProjectionBuilder.ATLAS_SLIDE_CACHE_FOLDER, $"{uniqueSlideReelID}.png");
var path = Path.Combine(mod.ModHelper.Manifest.ModFolderPath, ProjectionBuilder.AtlasSlideReelCacheFolder, $"{uniqueSlideReelID}.png");
NHLogger.LogVerbose($"Caching atlas image to {path}");
Directory.CreateDirectory(Path.GetDirectoryName(path));
File.WriteAllBytes(path, texture.EncodeToPNG());

View File

@ -1,3 +1,4 @@
using NewHorizons.Builder.Props;
using NewHorizons.Utility.OWML;
using System;
using System.Collections;
@ -115,7 +116,7 @@ public class SlideReelAsyncImageLoader
if (hasError)
{
NHLogger.LogError($"Failed to load {index}:{url} - {uwr.error}");
if (url.Contains("SlideReelCache"))
if (url.Contains(ProjectionBuilder.CurrentSlideReelFolder))
{
NHLogger.LogError("Missing image in SlideReelCache: If you are a dev, try deleting the folder so that New Horizons can regenerate the cache. If you are a player: do that and then complain to the mod dev.");
}