From dea646bf8ee612c9c77a38dbc5dabc9e3d2246e9 Mon Sep 17 00:00:00 2001 From: xen-42 Date: Mon, 6 Jan 2025 22:08:43 -0500 Subject: [PATCH] Fix the randomize rotation and gravity alignment stuff with the new weird stuff --- NewHorizons/Builder/Props/QuantumBuilder.cs | 27 ++++++++++++------- .../SnapshotLockableVisiblityObject.cs | 21 ++++++++++++++- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/NewHorizons/Builder/Props/QuantumBuilder.cs b/NewHorizons/Builder/Props/QuantumBuilder.cs index 461b06d5..8935f54d 100644 --- a/NewHorizons/Builder/Props/QuantumBuilder.cs +++ b/NewHorizons/Builder/Props/QuantumBuilder.cs @@ -71,7 +71,7 @@ namespace NewHorizons.Builder.Props { if (quantumGroup is SocketQuantumGroupInfo socketGroup) { - MakeSocketGroup(planetGO, sector, socketGroup, propsInGroup.Select(x => x.go).ToArray()); + MakeSocketGroup(planetGO, sector, socketGroup, propsInGroup); } else if (quantumGroup is StateQuantumGroupInfo stateGroup) { @@ -112,13 +112,15 @@ namespace NewHorizons.Builder.Props } // Nice to have: socket groups that specify a filledSocketObject and an emptySocketObject (eg the archway in the giant's deep tower) - public static void MakeSocketGroup(GameObject planetGO, Sector sector, SocketQuantumGroupInfo quantumGroup, GameObject[] propsInGroup) + public static void MakeSocketGroup(GameObject planetGO, Sector sector, SocketQuantumGroupInfo quantumGroup, (GameObject go, DetailInfo detail)[] propsInGroup) { GameObject specialProp = null; + DetailInfo specialInfo = null; if (propsInGroup.Length == quantumGroup.sockets.Length) { // Special case! - specialProp = propsInGroup.Last(); + specialProp = propsInGroup.Last().go; + specialInfo = propsInGroup.Last().detail; var propsInGroupList = propsInGroup.ToList(); propsInGroupList.RemoveAt(propsInGroup.Length - 1); propsInGroup = propsInGroupList.ToArray(); @@ -143,8 +145,8 @@ namespace NewHorizons.Builder.Props foreach (var prop in propsInGroup) { - prop.SetActive(false); - var quantumObject = prop.AddComponent(); + prop.go.SetActive(false); + var quantumObject = prop.go.AddComponent(); quantumObject._socketRoot = groupRoot; quantumObject._socketList = sockets.ToList(); quantumObject._sockets = sockets; @@ -153,12 +155,11 @@ namespace NewHorizons.Builder.Props quantumObject._randomYRotation = prop.detail.quantumRandomizeYRotation; quantumObject._alignWithGravity = prop.detail.quantumAlignWithGravity; quantumObject._childSockets = new List(); - // TODO: support _alignWithGravity? - if (prop.GetComponentInChildren() == null) + if (prop.go.GetComponentInChildren() == null) { - BoundsUtilities.AddBoundsVisibility(prop); + BoundsUtilities.AddBoundsVisibility(prop.go); } - prop.SetActive(true); + prop.go.SetActive(true); } if (specialProp != null) @@ -186,7 +187,13 @@ namespace NewHorizons.Builder.Props box.center = new Vector3(0, 0.3f, 0); tracker.AddComponent(); // Using a quantum object bc it can be locked by camera - socket._visibilityObject = socket.gameObject.AddComponent(); + var quantumObject = socket.gameObject.AddComponent(); + quantumObject._alignWithSocket = !specialInfo.quantumAlignWithGravity; + quantumObject._randomYRotation = specialInfo.quantumRandomizeYRotation; + quantumObject._alignWithGravity = specialInfo.quantumAlignWithGravity; + quantumObject.emptySocketObject = emptySocketObject; + socket._visibilityObject = quantumObject; + socket.SetActive(true); } } diff --git a/NewHorizons/Components/Quantum/SnapshotLockableVisiblityObject.cs b/NewHorizons/Components/Quantum/SnapshotLockableVisiblityObject.cs index 4fb52a4c..86a8d039 100644 --- a/NewHorizons/Components/Quantum/SnapshotLockableVisiblityObject.cs +++ b/NewHorizons/Components/Quantum/SnapshotLockableVisiblityObject.cs @@ -1,13 +1,16 @@ using HarmonyLib; using System.Linq; +using UnityEngine; namespace NewHorizons.Components.Quantum; /// /// A quantum object that does nothing but track if its been photographed /// -internal class SnapshotLockableVisibilityObject : QuantumObject +internal class SnapshotLockableVisibilityObject : SocketedQuantumObject { + public GameObject emptySocketObject; + public override bool ChangeQuantumState(bool skipInstantVisibilityCheck) => true; } @@ -20,6 +23,22 @@ public static class SocketedQuantumObjectPatches [HarmonyPatch(typeof(SocketedQuantumObject), nameof(SocketedQuantumObject.MoveToSocket))] private static bool SocketedQuantumObject_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket) { + // Double check this is a normal allowed move, then do rotation stuff + if (socket.GetVisibilityObject() is SnapshotLockableVisibilityObject qObj1 && (!qObj1.IsLocked() || _skipPatch)) + { + if (qObj1._gravityVolume != null && qObj1._alignWithGravity) + { + Vector3 toDirection = qObj1.emptySocketObject.transform.position - qObj1._gravityVolume.GetCenterPosition(); + Quaternion lhs = Quaternion.FromToRotation(qObj1.emptySocketObject.transform.up, toDirection); + qObj1.emptySocketObject.transform.rotation = lhs * qObj1.emptySocketObject.transform.rotation; + } + if (qObj1._randomYRotation) + { + float d = Random.Range(0f, 360f); + qObj1.emptySocketObject.transform.localRotation *= Quaternion.Euler(Vector3.up * d); + } + } + if (_skipPatch) { return true;