From a06b2dadcadbf4c527635a35ca6e37ebde10b89b Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 24 Aug 2022 20:21:23 -0400 Subject: [PATCH] Add trailmarker --- NewHorizons/Builder/Props/NomaiTextBuilder.cs | 76 +++++++++++++++++++ NewHorizons/External/Modules/PropModule.cs | 4 +- 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiTextBuilder.cs index 9ea62e16..7743d754 100644 --- a/NewHorizons/Builder/Props/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiTextBuilder.cs @@ -23,6 +23,7 @@ namespace NewHorizons.Builder.Props private static GameObject _cairnPrefab; private static GameObject _recorderPrefab; private static GameObject _preCrashRecorderPrefab; + private static GameObject _trailmarkerPrefab; private static Dictionary arcInfoToCorrespondingSpawnedGameObject = new Dictionary(); public static GameObject GetSpawnedGameObjectByNomaiTextArcInfo(PropModule.NomaiTextArcInfo arc) @@ -97,6 +98,10 @@ namespace NewHorizons.Builder.Props _preCrashRecorderPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_EscapePodCrashSite/Sector_CrashFragment/Interactables_CrashFragment/Prefab_NOM_Recorder").InstantiateInactive(); _preCrashRecorderPrefab.name = "Prefab_NOM_Recorder_Vessel"; _preCrashRecorderPrefab.transform.rotation = Quaternion.identity; + + _trailmarkerPrefab = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_HangingCity/Sector_HangingCity_District2/Interactables_HangingCity_District2/Prefab_NOM_Sign"); + _trailmarkerPrefab.name = "Prefab_NOM_Trailmarker"; + _trailmarkerPrefab.transform.rotation = Quaternion.identity; } public static GameObject Make(GameObject planetGO, Sector sector, PropModule.NomaiTextInfo info, IModBehaviour mod) @@ -159,6 +164,10 @@ namespace NewHorizons.Builder.Props { customScroll.name = info.rename; } + else + { + customScroll.name = _scrollPrefab.name; + } var nomaiWallText = MakeWallText(planetGO, sector, info, xmlPath); nomaiWallText.transform.parent = customScroll.transform; @@ -235,6 +244,10 @@ namespace NewHorizons.Builder.Props { computerObject.name = info.rename; } + else + { + computerObject.name = _computerPrefab.name; + } computerObject.transform.parent = sector?.transform ?? planetGO.transform; @@ -347,6 +360,10 @@ namespace NewHorizons.Builder.Props { cairnObject.name = info.rename; } + else + { + cairnObject.name = _cairnPrefab.name; + } cairnObject.transform.parent = sector?.transform ?? planetGO.transform; @@ -445,6 +462,65 @@ namespace NewHorizons.Builder.Props conversationInfoToCorrespondingSpawnedGameObject[info] = recorderObject; return recorderObject; } + case PropModule.NomaiTextInfo.NomaiTextType.Trailmarker: + { + var trailmarkerObject = _trailmarkerPrefab.InstantiateInactive(); + + if (!string.IsNullOrEmpty(info.rename)) + { + trailmarkerObject.name = info.rename; + } + else + { + trailmarkerObject.name = _trailmarkerPrefab.name; + } + + trailmarkerObject.transform.parent = sector?.transform ?? planetGO.transform; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + trailmarkerObject.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + + trailmarkerObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero); + + if (info.rotation != null) + { + trailmarkerObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(info.rotation)); + } + else + { + // By default align it to normal + var up = (trailmarkerObject.transform.position - planetGO.transform.position).normalized; + trailmarkerObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, up) * trailmarkerObject.transform.rotation; + } + + // Idk do we have to set it active before finding things? + trailmarkerObject.SetActive(true); + + var nomaiWallText = trailmarkerObject.transform.Find("Arc_Short").GetComponent(); + nomaiWallText.SetSector(sector); + + nomaiWallText._location = (NomaiText.Location)Enum.Parse(typeof(NomaiText.Location), Enum.GetName(typeof(PropModule.NomaiTextInfo.NomaiTextLocation), info.location)); + nomaiWallText._dictNomaiTextData = MakeNomaiTextDict(xmlPath); + nomaiWallText._nomaiTextAsset = new TextAsset(xmlPath); + nomaiWallText._nomaiTextAsset.name = Path.GetFileNameWithoutExtension(info.xmlFile); + AddTranslation(xmlPath); + + // Make sure the model is loaded + StreamingHandler.SetUpStreaming(trailmarkerObject, sector); + conversationInfoToCorrespondingSpawnedGameObject[info] = trailmarkerObject; + + return trailmarkerObject; + } default: Logger.LogError($"Unsupported NomaiText type {info.type}"); return null; diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 70ebc244..95843e11 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -514,7 +514,9 @@ namespace NewHorizons.External.Modules [EnumMember(Value = @"preCrashRecorder")] PreCrashRecorder = 5, - [EnumMember(Value = @"preCrashComputer")] PreCrashComputer = 6 + [EnumMember(Value = @"preCrashComputer")] PreCrashComputer = 6, + + [EnumMember(Value = @"trailmarker")] Trailmarker = 7, } [JsonConverter(typeof(StringEnumConverter))]