From bf2043a80b0a063dba703976079e412dba856f38 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Wed, 1 Feb 2023 13:02:21 -0500 Subject: [PATCH] added mirror status to spiral cache and fixed bugs with loading cache --- .../Props/NomaiText/NomaiTextBuilder.cs | 5 ++++- NewHorizons/Utility/Cache.cs | 21 ++++++++----------- NewHorizons/Utility/NewHorizonBody.cs | 13 ++++++++++-- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/NewHorizons/Builder/Props/NomaiText/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiText/NomaiTextBuilder.cs index e14c261b..efa7aa7b 100644 --- a/NewHorizons/Builder/Props/NomaiText/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiText/NomaiTextBuilder.cs @@ -626,6 +626,7 @@ namespace NewHorizons.Builder.Props public MVector3[] skeletonPoints; public MVector3 position; public float zRotation; + public bool mirrored; } internal static void RefreshArcs(NomaiWallText nomaiWallText, GameObject conversationZone, PropModule.NomaiTextInfo info, NewHorizonsBody nhBody, string cacheKey) @@ -671,6 +672,7 @@ namespace NewHorizons.Builder.Props var skeletonPoints = cachedData[i].skeletonPoints.Select(mv => (Vector3)mv).ToArray(); arcReadFromCache = NomaiTextArcBuilder.BuildSpiralGameObject(skeletonPoints, cachedData[i].mesh); arcReadFromCache.transform.parent = arranger.transform; + arcReadFromCache.transform.localScale = new Vector3(cachedData[i].mirrored? -1 : 1, 1, 1); arcReadFromCache.transform.localPosition = cachedData[i].position; arcReadFromCache.transform.localEulerAngles = new Vector3(0, 0, cachedData[i].zRotation); } @@ -727,7 +729,8 @@ namespace NewHorizons.Builder.Props mesh = spiralManipulator.GetComponent().sharedMesh, // TODO: create a serializable version of Mesh and pass this: spiralManipulator.GetComponent().mesh skeletonPoints = spiralManipulator.NomaiTextLine._points.Select(v => (MVector3)v).ToArray(), position = spiralManipulator.transform.localPosition, - zRotation = spiralManipulator.transform.localEulerAngles.z + zRotation = spiralManipulator.transform.localEulerAngles.z, + mirrored = spiralManipulator.transform.localScale.x < 0 }).ToArray(); nhBody.Cache.Set(cacheKey, cacheData); diff --git a/NewHorizons/Utility/Cache.cs b/NewHorizons/Utility/Cache.cs index 5860cc9e..2b382d80 100644 --- a/NewHorizons/Utility/Cache.cs +++ b/NewHorizons/Utility/Cache.cs @@ -17,23 +17,20 @@ namespace NewHorizons.Utility public Cache(IModBehaviour mod, string cacheFilePath) { this.mod = mod; - - filepath = cacheFilePath; + this.filepath = cacheFilePath; + var fullPath = mod.ModHelper.Manifest.ModFolderPath + cacheFilePath; - var json = File.ReadAllText(mod.ModHelper.Manifest.ModFolderPath + cacheFilePath); - data = JsonConvert.DeserializeObject>(json); - // the above is exactly the same thing that the below does, but the below for some reason always returns null. no clue why - // data = mod.ModHelper.Storage.Load>(filepath); - - if (data == null) + if (!File.Exists(fullPath)) { - Logger.LogWarning("Failed to load cache! Cache path: " + cacheFilePath); + Logger.LogWarning("Cache file not found! Cache path: " + cacheFilePath); data = new Dictionary(); + return; } - Logger.LogWarning("CACHE DEBUG: Cache path: " + cacheFilePath); - Logger.LogWarning("CACHE DEBUG: Loaded cache == null? " + (data == null)); - Logger.LogWarning("CACHE DEBUG: Loaded cache keys: " + String.Join(",", data?.Keys ?? new Dictionary().Keys)); + var json = File.ReadAllText(fullPath); + data = JsonConvert.DeserializeObject>(json); + // the code above does exactly the same thing that the code below does, but the below for some reason always returns null. no clue why + // data = mod.ModHelper.Storage.Load>(filepath); } public void WriteToFile() diff --git a/NewHorizons/Utility/NewHorizonBody.cs b/NewHorizons/Utility/NewHorizonBody.cs index 2bd4370d..f96fe4b0 100644 --- a/NewHorizons/Utility/NewHorizonBody.cs +++ b/NewHorizons/Utility/NewHorizonBody.cs @@ -1,5 +1,6 @@ using NewHorizons.External.Configs; using OWML.Common; +using System; using System.Linq; using UnityEngine; namespace NewHorizons.Utility @@ -33,8 +34,16 @@ namespace NewHorizons.Utility return; } - var pathWithoutExtension = RelativePath.Substring(0, RelativePath.LastIndexOf('.')); - Cache = new Cache(Mod, pathWithoutExtension+".nhcache"); + try + { + var pathWithoutExtension = RelativePath.Substring(0, RelativePath.LastIndexOf('.')); + Cache = new Cache(Mod, pathWithoutExtension+".nhcache"); + } + catch (Exception e) + { + Logger.LogError("Cache failed to load: " + e.Message); + Cache = null; + } } public void UnloadCache(bool writeBeforeUnload=false)