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 59b2d3b4..2c3b0764 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.RunWhen( () => Locator._centerOfTheUniverse != null, () => Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent() diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 6b1055df..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,16 +146,25 @@ 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); + + var fogLight = nodeWarp.GetComponent(); + fogLight._linkedSector = destinationAO._rootSector; return true; } @@ -168,12 +191,59 @@ 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(); // this node comes with Feldspar's signal, we don't want that though 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 + // + brambleNode.transform.localScale = Vector3.one * config.scale; + warpController._warpRadius *= config.scale; + warpController._exitRadius *= config.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 @@ -217,6 +287,7 @@ namespace NewHorizons.Builder.Props } // Done! + brambleNode.SetActive(true); return brambleNode; } @@ -228,6 +299,9 @@ namespace NewHorizons.Builder.Props fogRenderer._fogColor = fogTint.Value; fogRenderer._useFarFogColor = false; + + var fogBackdrop = brambleNode.FindChild("Terrain_DB_BrambleSphere_Inner_v2")?.FindChild("fogbackdrop_v2"); + if (fogBackdrop != null) fogBackdrop.GetComponent().sharedMaterial.color = (Color)fogTint; } if (lightTint != null) 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; } 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 /// 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) 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"