From a99054f0d415a7a8f945d9a44c28f81594f5e673 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Tue, 31 Jan 2023 15:00:31 -0500 Subject: [PATCH] passing a reference to the cache to the text builder --- .../Props/NomaiText/NomaiTextBuilder.cs | 25 +++++++++++++------ .../Utility/DebugMenu/DebugMenuNomaiText.cs | 16 +----------- NewHorizons/Utility/NewHorizonBody.cs | 2 +- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/NewHorizons/Builder/Props/NomaiText/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiText/NomaiTextBuilder.cs index 437b98fb..ccf664db 100644 --- a/NewHorizons/Builder/Props/NomaiText/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiText/NomaiTextBuilder.cs @@ -118,7 +118,7 @@ namespace NewHorizons.Builder.Props } } - public static GameObject Make(GameObject planetGO, Sector sector, PropModule.NomaiTextInfo info, IModBehaviour mod) + public static GameObject Make(GameObject planetGO, Sector sector, PropModule.NomaiTextInfo info, NewHorizonsBody body, IModBehaviour mod) { InitPrefabs(); @@ -128,7 +128,7 @@ namespace NewHorizons.Builder.Props { case PropModule.NomaiTextInfo.NomaiTextType.Wall: { - var nomaiWallTextObj = MakeWallText(planetGO, sector, info, xmlPath).gameObject; + var nomaiWallTextObj = MakeWallText(planetGO, sector, info, xmlPath, body).gameObject; if (!string.IsNullOrEmpty(info.rename)) { @@ -209,7 +209,7 @@ namespace NewHorizons.Builder.Props customScroll.name = _scrollPrefab.name; } - var nomaiWallText = MakeWallText(planetGO, sector, info, xmlPath); + var nomaiWallText = MakeWallText(planetGO, sector, info, xmlPath, body); nomaiWallText.transform.parent = customScroll.transform; nomaiWallText.transform.localPosition = Vector3.zero; nomaiWallText.transform.localRotation = Quaternion.identity; @@ -570,7 +570,7 @@ namespace NewHorizons.Builder.Props } } - private static NomaiWallText MakeWallText(GameObject go, Sector sector, PropModule.NomaiTextInfo info, string xmlPath) + private static NomaiWallText MakeWallText(GameObject go, Sector sector, PropModule.NomaiTextInfo info, string xmlPath, NewHorizonsBody body) { GameObject nomaiWallTextObj = new GameObject("NomaiWallText"); nomaiWallTextObj.SetActive(false); @@ -592,7 +592,7 @@ namespace NewHorizons.Builder.Props // Text assets need a name to be used with VoiceMod text.name = Path.GetFileNameWithoutExtension(info.xmlFile); - BuildArcs(xmlPath, nomaiWallText, nomaiWallTextObj, info); + BuildArcs(xmlPath, nomaiWallText, nomaiWallTextObj, info, body); AddTranslation(xmlPath); nomaiWallText._nomaiTextAsset = text; @@ -607,16 +607,16 @@ namespace NewHorizons.Builder.Props return nomaiWallText; } - internal static void BuildArcs(string xml, NomaiWallText nomaiWallText, GameObject conversationZone, PropModule.NomaiTextInfo info) + internal static void BuildArcs(string xml, NomaiWallText nomaiWallText, GameObject conversationZone, PropModule.NomaiTextInfo info, NewHorizonsBody body) { var dict = MakeNomaiTextDict(xml); nomaiWallText._dictNomaiTextData = dict; - RefreshArcs(nomaiWallText, conversationZone, info); + RefreshArcs(nomaiWallText, conversationZone, info, body); } - internal static void RefreshArcs(NomaiWallText nomaiWallText, GameObject conversationZone, PropModule.NomaiTextInfo info) + internal static void RefreshArcs(NomaiWallText nomaiWallText, GameObject conversationZone, PropModule.NomaiTextInfo info, NewHorizonsBody body) { var dict = nomaiWallText._dictNomaiTextData; Random.InitState(info.seed == 0 ? info.xmlFile.GetHashCode() : info.seed); @@ -633,6 +633,13 @@ namespace NewHorizons.Builder.Props // Generate spiral meshes/GOs + var cacheKey = ""; // info.tojson.stringhashcode + "-" + xmlContents.stringhashcode + if (body.Cache?[cacheKey] != null) + { + // TODO: use cache data + // return; + } + var i = 0; foreach (var textData in dict.Values) { @@ -679,6 +686,8 @@ namespace NewHorizons.Builder.Props if (arcInfo.mirror) arc.transform.localScale = new Vector3(-1, 1, 1); else arc.transform.localScale = new Vector3( 1, 1, 1); } + + // TODO: body.Cache?[cacheKey] = cacheData; } internal static GameObject MakeArc(PropModule.NomaiTextArcInfo arcInfo, GameObject conversationZone, GameObject parent, int textEntryID) diff --git a/NewHorizons/Utility/DebugMenu/DebugMenuNomaiText.cs b/NewHorizons/Utility/DebugMenu/DebugMenuNomaiText.cs index 99843836..2ebcc329 100644 --- a/NewHorizons/Utility/DebugMenu/DebugMenuNomaiText.cs +++ b/NewHorizons/Utility/DebugMenu/DebugMenuNomaiText.cs @@ -266,7 +266,7 @@ namespace NewHorizons.Utility.DebugMenu GUILayout.Label("Variation"); GUILayout.BeginHorizontal(); - var varietyCount = GetVarietyCountForType(spiralMeta.spiral.type); + var varietyCount = 1; //var newVariation = int.Parse(GUILayout.TextField(spiralMeta.spiral.variation+"")); //newVariation = Mathf.Min(Mathf.Max(0, newVariation), varietyCount); //if (newVariation != spiralMeta.spiral.variation) changed = true; @@ -469,20 +469,6 @@ namespace NewHorizons.Utility.DebugMenu }); } - private int GetVarietyCountForType(NomaiTextArcInfo.NomaiTextArcType type) - { - switch(type) - { - case NomaiTextArcInfo.NomaiTextArcType.Stranger: - return NomaiTextBuilder.GetGhostArcPrefabs().Count(); - case NomaiTextArcInfo.NomaiTextArcType.Child: - return NomaiTextBuilder.GetChildArcPrefabs().Count(); - default: - case NomaiTextArcInfo.NomaiTextArcType.Adult: - return NomaiTextBuilder.GetArcPrefabs().Count(); - } - } - void UpdateConversationTransform(ConversationMetadata conversationMetadata, GameObject sectorParent) { var nomaiWallTextObj = conversationMetadata.conversationGo; diff --git a/NewHorizons/Utility/NewHorizonBody.cs b/NewHorizons/Utility/NewHorizonBody.cs index 8eff0b9a..9bc88027 100644 --- a/NewHorizons/Utility/NewHorizonBody.cs +++ b/NewHorizons/Utility/NewHorizonBody.cs @@ -30,7 +30,7 @@ namespace NewHorizons.Utility public void UnloadCache(bool writeBeforeUnload=false) { - if (writeBeforeUnload) Cache.WriteToFile(); + if (writeBeforeUnload) Cache?.WriteToFile(); Cache = null; // garbage collection will take care of it }