Fix the randomize rotation and gravity alignment stuff with the new weird stuff

This commit is contained in:
xen-42 2025-01-06 22:08:43 -05:00
parent e701e21881
commit dea646bf8e
2 changed files with 37 additions and 11 deletions

View File

@ -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<SocketedQuantumObject>();
prop.go.SetActive(false);
var quantumObject = prop.go.AddComponent<SocketedQuantumObject>();
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<QuantumSocket>();
// TODO: support _alignWithGravity?
if (prop.GetComponentInChildren<VisibilityTracker>() == null)
if (prop.go.GetComponentInChildren<VisibilityTracker>() == 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<ShapeVisibilityTracker>();
// Using a quantum object bc it can be locked by camera
socket._visibilityObject = socket.gameObject.AddComponent<SnapshotLockableVisibilityObject>();
var quantumObject = socket.gameObject.AddComponent<SnapshotLockableVisibilityObject>();
quantumObject._alignWithSocket = !specialInfo.quantumAlignWithGravity;
quantumObject._randomYRotation = specialInfo.quantumRandomizeYRotation;
quantumObject._alignWithGravity = specialInfo.quantumAlignWithGravity;
quantumObject.emptySocketObject = emptySocketObject;
socket._visibilityObject = quantumObject;
socket.SetActive(true);
}
}

View File

@ -1,13 +1,16 @@
using HarmonyLib;
using System.Linq;
using UnityEngine;
namespace NewHorizons.Components.Quantum;
/// <summary>
/// A quantum object that does nothing but track if its been photographed
/// </summary>
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;