passing a reference to the cache to the text builder

This commit is contained in:
FreezeDriedMangoes 2023-01-31 15:00:31 -05:00
parent 151d935b59
commit a99054f0d4
3 changed files with 19 additions and 24 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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
}