From 56ce08f82bd5c6b3efd7226475a5d3f73eb14472 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Fri, 1 Jul 2022 23:19:19 -0400 Subject: [PATCH 1/7] readded scale and radius properties and started adding support for them --- .../Builder/Props/BrambleNodeBuilder.cs | 71 +++++++++++++++++++ NewHorizons/External/Modules/BrambleModule.cs | 5 ++ 2 files changed, 76 insertions(+) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index a907989a..27676475 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -18,6 +18,68 @@ namespace NewHorizons.Builder.Props //3) support for existing dimensions? //5) test whether nodes can lead to vanilla dimensions + + + [HarmonyPatch] + public static class TestPatches + { + [HarmonyPrefix] + [HarmonyPatch(typeof(PlayerFogWarpDetector), nameof(PlayerFogWarpDetector.LateUpdate))] + private static void PlayerFogWarpDetector_LateUpdate(PlayerFogWarpDetector __instance) + { + if (!(PlanetaryFogController.GetActiveFogSphere() != null)) + { + return; + } + float num = __instance._targetFogFraction; + if (PlayerState.IsInsideShip()) + { + num = Mathf.Max(__instance._shipFogDetector.GetTargetFogFraction(), num); + } + if (num < __instance._fogFraction) + { + float num2 = (__instance._closestFogWarp.UseFastFogFade() ? 1f : 0.2f); + __instance._fogFraction = Mathf.MoveTowards(__instance._fogFraction, num, Time.deltaTime * num2); + } + else + { + __instance._fogFraction = num; + } + if (__instance._targetFogColorWarpVolume != __instance._closestFogWarp) + { + __instance._targetFogColorWarpVolume = __instance._closestFogWarp; + __instance._startColorCrossfadeTime = Time.time; + __instance._startCrossfadeColor = __instance._fogColor; + } + if (__instance._targetFogColorWarpVolume != null) + { + Color fogColor = __instance._targetFogColorWarpVolume.GetFogColor(); + if (__instance._fogFraction <= 0f) + { + __instance._fogColor = fogColor; + } + else + { + float t = Mathf.InverseLerp(__instance._startColorCrossfadeTime, __instance._startColorCrossfadeTime + 1f, Time.time); + __instance._fogColor = Color.Lerp(__instance._startCrossfadeColor, fogColor, t); + } + } + if (__instance._playerEffectBubbleController != null) + { + __instance._playerEffectBubbleController.SetFogFade(__instance._fogFraction, __instance._fogColor); + } + if (__instance._shipLandingCamEffectBubbleController != null) + { + __instance._shipLandingCamEffectBubbleController.SetFogFade(__instance._fogFraction, __instance._fogColor); + } + } + } + + + + + + public static class BrambleNodeBuilder { // keys are all dimension names that have been referenced by at least one node but do not (yet) exist @@ -115,6 +177,15 @@ namespace NewHorizons.Builder.Props // this node comes with Feldspar's signal, we don't want that though GameObject.Destroy(brambleNode.FindChild("Signal_Harmonica")); + + + // + // Set the scale + // + brambleNode.transform.localScale = Vector3.one * config.scale; + warpController._warpRadius *= config.scale; + warpController._exitRadius *= config.scale; + // // change the colors diff --git a/NewHorizons/External/Modules/BrambleModule.cs b/NewHorizons/External/Modules/BrambleModule.cs index db1856eb..71fbb1ed 100644 --- a/NewHorizons/External/Modules/BrambleModule.cs +++ b/NewHorizons/External/Modules/BrambleModule.cs @@ -52,6 +52,11 @@ namespace NewHorizons.External.Modules /// public MVector3 rotation; + /// + /// The physical scale of the node + /// + [DefaultValue(1f)] public float scale = 1f; + /// /// The name of the planet that hosts the dimension this node links to /// From d91727b6886b9309716cfe8acc0623fd2516c826 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Wed, 6 Jul 2022 08:41:47 -0400 Subject: [PATCH 2/7] now changing color of fog backdrop --- .../Builder/Props/BrambleNodeBuilder.cs | 69 ++----------------- 1 file changed, 7 insertions(+), 62 deletions(-) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index e1fb1345..6d3d5c3f 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -15,68 +15,6 @@ namespace NewHorizons.Builder.Props //3) support for existing dimensions? //5) test whether nodes can lead to vanilla dimensions - - - [HarmonyPatch] - public static class TestPatches - { - [HarmonyPrefix] - [HarmonyPatch(typeof(PlayerFogWarpDetector), nameof(PlayerFogWarpDetector.LateUpdate))] - private static void PlayerFogWarpDetector_LateUpdate(PlayerFogWarpDetector __instance) - { - if (!(PlanetaryFogController.GetActiveFogSphere() != null)) - { - return; - } - float num = __instance._targetFogFraction; - if (PlayerState.IsInsideShip()) - { - num = Mathf.Max(__instance._shipFogDetector.GetTargetFogFraction(), num); - } - if (num < __instance._fogFraction) - { - float num2 = (__instance._closestFogWarp.UseFastFogFade() ? 1f : 0.2f); - __instance._fogFraction = Mathf.MoveTowards(__instance._fogFraction, num, Time.deltaTime * num2); - } - else - { - __instance._fogFraction = num; - } - if (__instance._targetFogColorWarpVolume != __instance._closestFogWarp) - { - __instance._targetFogColorWarpVolume = __instance._closestFogWarp; - __instance._startColorCrossfadeTime = Time.time; - __instance._startCrossfadeColor = __instance._fogColor; - } - if (__instance._targetFogColorWarpVolume != null) - { - Color fogColor = __instance._targetFogColorWarpVolume.GetFogColor(); - if (__instance._fogFraction <= 0f) - { - __instance._fogColor = fogColor; - } - else - { - float t = Mathf.InverseLerp(__instance._startColorCrossfadeTime, __instance._startColorCrossfadeTime + 1f, Time.time); - __instance._fogColor = Color.Lerp(__instance._startCrossfadeColor, fogColor, t); - } - } - if (__instance._playerEffectBubbleController != null) - { - __instance._playerEffectBubbleController.SetFogFade(__instance._fogFraction, __instance._fogColor); - } - if (__instance._shipLandingCamEffectBubbleController != null) - { - __instance._shipLandingCamEffectBubbleController.SetFogFade(__instance._fogFraction, __instance._fogColor); - } - } - } - - - - - - public static class BrambleNodeBuilder { // keys are all dimension names that have been referenced by at least one node but do not (yet) exist @@ -244,6 +182,10 @@ namespace NewHorizons.Builder.Props brambleNode.transform.localScale = Vector3.one * config.scale; warpController._warpRadius *= config.scale; warpController._exitRadius *= config.scale; + // Effects/InnerWarpFogSphere.transform.localScale /= config.scale; + // Effects/InnerWarpFogSphere.MeshRenderer.material.SetFloat("_Radius", GetFloat("_Radius") * scale) + // Effects/InnerWarpFogSphere.MeshRenderer.material.SetFloat("_Density", GetFloat("_Density") / scale) + // @@ -299,6 +241,9 @@ namespace NewHorizons.Builder.Props fogRenderer._fogColor = fogTint; fogRenderer._useFarFogColor = false; + + var fogBackdrop = brambleNode.FindChild("Terrain_DB_BrambleSphere_Inner_v2")?.FindChild("fogbackdrop_v2"); + if (fogBackdrop != null) fogBackdrop.GetComponent().sharedMaterial.color = fogTint; } if (lightTint != null) From 3a72e9208b18a79f70855deb02c742854acc12a0 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Fri, 8 Jul 2022 17:37:17 -0400 Subject: [PATCH 3/7] fixed nodes' fog volume scaling, added comments for leads on fixing screen fog --- .../Builder/Props/BrambleNodeBuilder.cs | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 6d3d5c3f..cfab3e51 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -182,11 +182,32 @@ namespace NewHorizons.Builder.Props brambleNode.transform.localScale = Vector3.one * config.scale; warpController._warpRadius *= config.scale; warpController._exitRadius *= config.scale; - // Effects/InnerWarpFogSphere.transform.localScale /= config.scale; - // Effects/InnerWarpFogSphere.MeshRenderer.material.SetFloat("_Radius", GetFloat("_Radius") * scale) - // Effects/InnerWarpFogSphere.MeshRenderer.material.SetFloat("_Density", GetFloat("_Density") / scale) - + // seed fog works differently, so it doesn't need to be fixed (it's also located on a different child path, so the below FindChild calls wouldn't work) + if (!config.isSeed) + { + var fog = brambleNode.FindChild("Effects").FindChild("InnerWarpFogSphere"); + var fogMaterial = fog.GetComponent().sharedMaterial; + fog.transform.localScale /= config.scale; + fogMaterial.SetFloat("_Radius", fogMaterial.GetFloat("_Radius") * config.scale); + fogMaterial.SetFloat("_Density", fogMaterial.GetFloat("_Density") / config.scale); + } + + // issue: when exiting a scaled bramblenode, the screen fog effect uses the original bramble node radius + // it's controlled by this class FogWarpEffectBubbleController which is on a game object under Player_Camera + + // found under PlayerFogWarpDetector.LateUpdate() + // _playerEffectBubbleController.SetFogFade(_fogFraction, _fogColor); // where _fogFraction is basically _targetFogFraction, but lerped into over time + + // found under FogWarpDetector.FixedUpdate() + // FogWarpVolume fogWarpVolume = _warpVolumes[i]; + // float num2 = Mathf.Abs(fogWarpVolume.CheckWarpProximity(this)); + // float b = Mathf.Clamp01(1f - Mathf.Abs(num2) / fogWarpVolume.GetFogThickness()); + // _targetFogFraction = Mathf.Max(_targetFogFraction, b); + + // this means that either CheckWarpProximity() or GetFogThickness() is incorrect for the InnerWarpFogSpheres. + // most likely it's CheckWarpProximity() + // // change the colors From 7bfaadb3a9f2617573c03a542a9aecaa23617461 Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Fri, 8 Jul 2022 17:39:07 -0400 Subject: [PATCH 4/7] added cast required for some versions of C# --- NewHorizons/Builder/Props/BrambleNodeBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 3dad6e7f..071e0e1a 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -264,7 +264,7 @@ namespace NewHorizons.Builder.Props fogRenderer._useFarFogColor = false; var fogBackdrop = brambleNode.FindChild("Terrain_DB_BrambleSphere_Inner_v2")?.FindChild("fogbackdrop_v2"); - if (fogBackdrop != null) fogBackdrop.GetComponent().sharedMaterial.color = fogTint; + if (fogBackdrop != null) fogBackdrop.GetComponent().sharedMaterial.color = (Color)fogTint; } if (lightTint != null) From ca391a1458052f08d67a6b390b5e0c48b67e2e0e Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Fri, 8 Jul 2022 18:13:29 -0400 Subject: [PATCH 5/7] fixed fog lights and planet staticPosition setting --- .../Builder/Body/BrambleDimensionBuilder.cs | 3 +++ .../Builder/General/AstroObjectBuilder.cs | 2 +- NewHorizons/Builder/Props/BrambleNodeBuilder.cs | 16 ++++++++++++++++ NewHorizons/Handlers/PlanetCreationHandler.cs | 5 +++-- 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs index 4796405e..1a7fa141 100644 --- a/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs +++ b/NewHorizons/Builder/Body/BrambleDimensionBuilder.cs @@ -89,6 +89,9 @@ namespace NewHorizons.Builder.Body fog.fogTint = body.Config.Bramble.dimension.fogTint.ToColor(); } + // clear base game fog lights + dimensionSector.GetComponent()._fogLightsInSector = null; + dimension.SetActive(true); return dimension; diff --git a/NewHorizons/Builder/General/AstroObjectBuilder.cs b/NewHorizons/Builder/General/AstroObjectBuilder.cs index 0e17e777..09a76181 100644 --- a/NewHorizons/Builder/General/AstroObjectBuilder.cs +++ b/NewHorizons/Builder/General/AstroObjectBuilder.cs @@ -51,7 +51,7 @@ namespace NewHorizons.Builder.General { Logger.Log($"Setting center of universe to {config.name}"); // By the time it runs we'll be able to get the OWRB with the method - Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => Locator.GetCenterOfTheUniverse()._staticReferenceFrame = astroObject.GetAttachedOWRigidbody(), 2); + Locator.GetCenterOfTheUniverse()._staticReferenceFrame = astroObject.gameObject.GetComponent(); } return astroObject; diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 071e0e1a..4cd64f75 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -142,6 +142,9 @@ namespace NewHorizons.Builder.Props nodeWarp._linkedOuterWarpVolume = destination; destination.RegisterSenderWarp(nodeWarp); + + var fogLight = nodeWarp.GetComponent(); + fogLight._linkedSector = destinationAO._rootSector; return true; } @@ -176,6 +179,19 @@ namespace NewHorizons.Builder.Props GameObject.Destroy(brambleNode.FindChild("Signal_Harmonica")); + // + // Fix some components + // + + var fogLight = brambleNode.GetComponent(); + fogLight._parentBody = go.GetComponent(); + fogLight._sector = sector; + fogLight._linkedFogLights.Clear(); + fogLight._linkedLightData.Clear(); + fogLight._linkedSector = null; + + sector.RegisterFogLight(fogLight); + // // Set the scale // diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 7dbe1f88..e9c2e256 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -411,8 +411,9 @@ namespace NewHorizons.Handlers DetectorBuilder.Make(go, owRigidBody, primaryBody, ao, body.Config); } else if (body.Config.Orbit.staticPosition != null) - { - ao.transform.position = body.Config.Orbit.staticPosition; + { + // NH doesn't set the value of _centerOfTheUniverse for a few frames + ao.transform.position = body.Config.Orbit.staticPosition + Locator._centerOfTheUniverse._staticReferenceFrame._lastPosition; } if (ao.GetAstroObjectName() == AstroObject.Name.CustomString) From 33a397a768a9409fc14f5b296cea2a473e2de5cd Mon Sep 17 00:00:00 2001 From: FreezeDriedMangoes Date: Fri, 8 Jul 2022 22:52:16 -0400 Subject: [PATCH 6/7] some fixes for warp volume tracking --- .../Builder/Props/BrambleNodeBuilder.cs | 27 ++++++++++++++++--- NewHorizons/Builder/Props/DetailBuilder.cs | 8 +++--- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 4cd64f75..cc03e52f 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -7,6 +7,7 @@ using System.Linq; using UnityEngine; using static NewHorizons.External.Modules.BrambleModule; using static NewHorizons.External.Modules.SignalModule; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Props { @@ -34,12 +35,23 @@ namespace NewHorizons.Builder.Props BuiltBrambleNodes = new(); } + + // how warping works + // every frame, each FogWarpDetector loops over all FogWarpVolume instances it has in _warpVolumes. Each instance gets CheckWarpProximity called + // (pretty much every FogWarpVolume in the game is a SphericalFogWarpVolume. that's where CheckWarpProximity is called) + // if CheckWarpProximity would return 0, it calls its own WarpDetector() function + // + + public static void FinishPairingNodesForDimension(string dimensionName, AstroObject dimensionAO = null) { + Logger.LogWarning($"Pairing missed for {dimensionName}"); if (!_unpairedNodes.ContainsKey(dimensionName)) return; - + + Logger.LogWarning("proceeding"); foreach (var nodeWarpController in _unpairedNodes[dimensionName]) { + Logger.LogWarning($"Pairing node {nodeWarpController.gameObject.name} links to {dimensionName}"); PairEntrance(nodeWarpController, dimensionName, dimensionAO); } @@ -50,6 +62,8 @@ namespace NewHorizons.Builder.Props { if (!_unpairedNodes.ContainsKey(linksTo)) _unpairedNodes[linksTo] = new(); + Logger.LogWarning($"Recording node {warpVolume.gameObject.name} links to {linksTo}"); + _unpairedNodes[linksTo].Add(warpVolume); } @@ -132,13 +146,19 @@ namespace NewHorizons.Builder.Props } private static bool PairEntrance(InnerFogWarpVolume nodeWarp, string destinationName, AstroObject dimensionAO = null) - { + { + Logger.LogWarning($"Pairing node {nodeWarp.gameObject.name} to {destinationName}"); + var destinationAO = dimensionAO ?? AstroObjectLocator.GetAstroObject(destinationName); // find child "Sector/OuterWarp" if (destinationAO == null) return false; + Logger.LogWarning($"Found {destinationName} as gameobject {destinationAO.gameObject.name} (was passed in: {dimensionAO != null})"); + // link the node's warp volume to the destination's var destination = GetOuterFogWarpVolumeFromAstroObject(destinationAO.gameObject); if (destination == null) return false; + + Logger.LogWarning($"Proceeding with pairing node {nodeWarp.gameObject.name} to {destinationName}. Path to outer fog warp volume: {destination.transform.GetPath()}"); nodeWarp._linkedOuterWarpVolume = destination; destination.RegisterSenderWarp(nodeWarp); @@ -171,7 +191,7 @@ namespace NewHorizons.Builder.Props var brambleNodePrefabPath = "DB_HubDimension_Body/Sector_HubDimension/Interactables_HubDimension/InnerWarp_ToCluster"; var path = config.isSeed ? brambleSeedPrefabPath : brambleNodePrefabPath; - var brambleNode = DetailBuilder.MakeDetail(go, sector, path, config.position, config.rotation, 1, false); + var brambleNode = DetailBuilder.MakeDetail(go, sector, path, config.position, config.rotation, 1, false, leaveInactive:true); brambleNode.name = "Bramble Node to " + config.linksTo; var warpController = brambleNode.GetComponent(); @@ -267,6 +287,7 @@ namespace NewHorizons.Builder.Props } // Done! + brambleNode.SetActive(true); return brambleNode; } diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 0d1c8c7a..7fabe376 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -94,14 +94,14 @@ namespace NewHorizons.Builder.Props detailInfoToCorrespondingSpawnedGameObject[detail] = detailGO; } - public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal) + public static GameObject MakeDetail(GameObject go, Sector sector, string propToClone, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal, bool leaveInactive=false) { var prefab = SearchUtilities.Find(propToClone); if (prefab == null) Logger.LogError($"Couldn't find detail {propToClone}"); - return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal); + return MakeDetail(go, sector, prefab, position, rotation, scale, alignWithNormal, leaveInactive); } - public static GameObject MakeDetail(GameObject planetGO, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal) + public static GameObject MakeDetail(GameObject planetGO, Sector sector, GameObject prefab, MVector3 position, MVector3 rotation, float scale, bool alignWithNormal, bool leaveInactive=false) { if (prefab == null) return null; @@ -271,7 +271,7 @@ namespace NewHorizons.Builder.Props prop.transform.localScale = scale != 0 ? Vector3.one * scale : prefab.transform.localScale; - prop.SetActive(true); + if (!leaveInactive) prop.SetActive(true); return prop; } From 0bfd7393dbb4b28005e870aa92206011ea7b4ebf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 9 Jul 2022 17:58:09 +0000 Subject: [PATCH 7/7] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index e4e8db3e..c38394df 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -531,6 +531,12 @@ "description": "The physical rotation of the node", "$ref": "#/definitions/MVector3" }, + "scale": { + "type": "number", + "description": "The physical scale of the node", + "format": "float", + "default": 1.0 + }, "linksTo": { "type": "string", "description": "The name of the planet that hosts the dimension this node links to"