mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
Fix the randomize rotation and gravity alignment stuff with the new weird stuff
This commit is contained in:
parent
e701e21881
commit
dea646bf8e
@ -71,7 +71,7 @@ namespace NewHorizons.Builder.Props
|
|||||||
{
|
{
|
||||||
if (quantumGroup is SocketQuantumGroupInfo socketGroup)
|
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)
|
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)
|
// 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;
|
GameObject specialProp = null;
|
||||||
|
DetailInfo specialInfo = null;
|
||||||
if (propsInGroup.Length == quantumGroup.sockets.Length)
|
if (propsInGroup.Length == quantumGroup.sockets.Length)
|
||||||
{
|
{
|
||||||
// Special case!
|
// Special case!
|
||||||
specialProp = propsInGroup.Last();
|
specialProp = propsInGroup.Last().go;
|
||||||
|
specialInfo = propsInGroup.Last().detail;
|
||||||
var propsInGroupList = propsInGroup.ToList();
|
var propsInGroupList = propsInGroup.ToList();
|
||||||
propsInGroupList.RemoveAt(propsInGroup.Length - 1);
|
propsInGroupList.RemoveAt(propsInGroup.Length - 1);
|
||||||
propsInGroup = propsInGroupList.ToArray();
|
propsInGroup = propsInGroupList.ToArray();
|
||||||
@ -143,8 +145,8 @@ namespace NewHorizons.Builder.Props
|
|||||||
|
|
||||||
foreach (var prop in propsInGroup)
|
foreach (var prop in propsInGroup)
|
||||||
{
|
{
|
||||||
prop.SetActive(false);
|
prop.go.SetActive(false);
|
||||||
var quantumObject = prop.AddComponent<SocketedQuantumObject>();
|
var quantumObject = prop.go.AddComponent<SocketedQuantumObject>();
|
||||||
quantumObject._socketRoot = groupRoot;
|
quantumObject._socketRoot = groupRoot;
|
||||||
quantumObject._socketList = sockets.ToList();
|
quantumObject._socketList = sockets.ToList();
|
||||||
quantumObject._sockets = sockets;
|
quantumObject._sockets = sockets;
|
||||||
@ -153,12 +155,11 @@ namespace NewHorizons.Builder.Props
|
|||||||
quantumObject._randomYRotation = prop.detail.quantumRandomizeYRotation;
|
quantumObject._randomYRotation = prop.detail.quantumRandomizeYRotation;
|
||||||
quantumObject._alignWithGravity = prop.detail.quantumAlignWithGravity;
|
quantumObject._alignWithGravity = prop.detail.quantumAlignWithGravity;
|
||||||
quantumObject._childSockets = new List<QuantumSocket>();
|
quantumObject._childSockets = new List<QuantumSocket>();
|
||||||
// TODO: support _alignWithGravity?
|
if (prop.go.GetComponentInChildren<VisibilityTracker>() == null)
|
||||||
if (prop.GetComponentInChildren<VisibilityTracker>() == null)
|
|
||||||
{
|
{
|
||||||
BoundsUtilities.AddBoundsVisibility(prop);
|
BoundsUtilities.AddBoundsVisibility(prop.go);
|
||||||
}
|
}
|
||||||
prop.SetActive(true);
|
prop.go.SetActive(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (specialProp != null)
|
if (specialProp != null)
|
||||||
@ -186,7 +187,13 @@ namespace NewHorizons.Builder.Props
|
|||||||
box.center = new Vector3(0, 0.3f, 0);
|
box.center = new Vector3(0, 0.3f, 0);
|
||||||
tracker.AddComponent<ShapeVisibilityTracker>();
|
tracker.AddComponent<ShapeVisibilityTracker>();
|
||||||
// Using a quantum object bc it can be locked by camera
|
// 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);
|
socket.SetActive(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,16 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace NewHorizons.Components.Quantum;
|
namespace NewHorizons.Components.Quantum;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A quantum object that does nothing but track if its been photographed
|
/// A quantum object that does nothing but track if its been photographed
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal class SnapshotLockableVisibilityObject : QuantumObject
|
internal class SnapshotLockableVisibilityObject : SocketedQuantumObject
|
||||||
{
|
{
|
||||||
|
public GameObject emptySocketObject;
|
||||||
|
|
||||||
public override bool ChangeQuantumState(bool skipInstantVisibilityCheck) => true;
|
public override bool ChangeQuantumState(bool skipInstantVisibilityCheck) => true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,6 +23,22 @@ public static class SocketedQuantumObjectPatches
|
|||||||
[HarmonyPatch(typeof(SocketedQuantumObject), nameof(SocketedQuantumObject.MoveToSocket))]
|
[HarmonyPatch(typeof(SocketedQuantumObject), nameof(SocketedQuantumObject.MoveToSocket))]
|
||||||
private static bool SocketedQuantumObject_MoveToSocket(SocketedQuantumObject __instance, QuantumSocket socket)
|
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)
|
if (_skipPatch)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user