From cbffa8f5b4e2e8094f0e4ff4197bc83e342d6c0e Mon Sep 17 00:00:00 2001 From: xen-42 Date: Fri, 4 Oct 2024 21:25:43 -0400 Subject: [PATCH] Fix caches in other systems --- NewHorizons/Builder/Props/ProjectionBuilder.cs | 11 ++++++----- NewHorizons/Utility/Files/ImageUtilities.cs | 4 ++-- .../Utility/Files/SlideReelAsyncImageLoader.cs | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 7a55d891..8d9eaca6 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -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 { diff --git a/NewHorizons/Utility/Files/ImageUtilities.cs b/NewHorizons/Utility/Files/ImageUtilities.cs index 3f9d8497..1ed96114 100644 --- a/NewHorizons/Utility/Files/ImageUtilities.cs +++ b/NewHorizons/Utility/Files/ImageUtilities.cs @@ -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()); diff --git a/NewHorizons/Utility/Files/SlideReelAsyncImageLoader.cs b/NewHorizons/Utility/Files/SlideReelAsyncImageLoader.cs index 7674ccdc..e81d8298 100644 --- a/NewHorizons/Utility/Files/SlideReelAsyncImageLoader.cs +++ b/NewHorizons/Utility/Files/SlideReelAsyncImageLoader.cs @@ -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."); }