From bcdfbedb5372dacb21c61b9e6661948e8efd07c3 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sun, 18 Dec 2022 03:22:56 -0500 Subject: [PATCH 01/16] Delete packages.config --- NewHorizons/packages.config | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 NewHorizons/packages.config diff --git a/NewHorizons/packages.config b/NewHorizons/packages.config deleted file mode 100644 index 29df5b05..00000000 --- a/NewHorizons/packages.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From fa8b1249e83536812a2d08c72b1113ee4a70b3fc Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 24 Dec 2022 13:19:01 -0500 Subject: [PATCH 02/16] Add renames --- NewHorizons/External/Modules/PropModule.cs | 30 +++++++++++++++++++ .../Modules/VariableSize/SingularityModule.cs | 5 ++++ 2 files changed, 35 insertions(+) diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 4e0a3a1e..51610074 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -243,6 +243,11 @@ namespace NewHorizons.External.Modules /// Acceleration of the raft. Default acceleration is 5. /// [DefaultValue(5f)] public float acceleration = 5f; + + /// + /// An optional rename of this object + /// + public string rename; } [JsonObject] @@ -287,6 +292,11 @@ namespace NewHorizons.External.Modules /// Loudness of the geyser /// [DefaultValue(0.7f)] public float volume = 0.7f; + + /// + /// An optional rename of this object + /// + public string rename; } [JsonObject] @@ -354,6 +364,11 @@ namespace NewHorizons.External.Modules /// Fluid type for sounds/effects when colliding with this tornado. /// [DefaultValue("cloud")] public FluidType fluidType = FluidType.Cloud; + + /// + /// An optional rename of this object + /// + public string rename; } [JsonObject] @@ -402,6 +417,11 @@ namespace NewHorizons.External.Modules /// The colour of the meteor's stone. /// public MColor stoneTint; + + /// + /// An optional rename of this object + /// + public string rename; } [JsonObject] @@ -489,6 +509,11 @@ namespace NewHorizons.External.Modules /// The position of this entry location /// public MVector3 position; + + /// + /// An optional rename of this object + /// + public string rename; } [JsonObject] @@ -680,6 +705,11 @@ namespace NewHorizons.External.Modules /// Whether the positional and rotational coordinates are relative to parent instead of the root planet object. /// public bool isRelativeToParent; + + /// + /// An optional rename of this object + /// + public string rename; } [JsonObject] diff --git a/NewHorizons/External/Modules/VariableSize/SingularityModule.cs b/NewHorizons/External/Modules/VariableSize/SingularityModule.cs index 448c3cdb..bbdcf27f 100644 --- a/NewHorizons/External/Modules/VariableSize/SingularityModule.cs +++ b/NewHorizons/External/Modules/VariableSize/SingularityModule.cs @@ -75,5 +75,10 @@ namespace NewHorizons.External.Modules.VariableSize /// Optional override for the render queue. If the singularity is rendering oddly, increasing this to 3000 can help /// [Range(2501f, 3500f)] public int renderQueueOverride = 2985; + + /// + /// An optional rename of this object + /// + public string rename; } } \ No newline at end of file From f08e7b264dd8c8fcdf2aa55c944542da89d52044 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 24 Dec 2022 13:22:26 -0500 Subject: [PATCH 03/16] Narp --- NewHorizons/Patches/AchievementPatches.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Patches/AchievementPatches.cs b/NewHorizons/Patches/AchievementPatches.cs index a034be9b..1c75e7d8 100644 --- a/NewHorizons/Patches/AchievementPatches.cs +++ b/NewHorizons/Patches/AchievementPatches.cs @@ -14,10 +14,9 @@ namespace NewHorizons.Patches [HarmonyPatch(typeof(ProbeDestructionDetector), nameof(ProbeDestructionDetector.FixedUpdate))] public static bool ProbeDestructionDetector_FixedUpdate(ProbeDestructionDetector __instance) { - if (!AchievementHandler.Enabled) return true; - if (__instance._activeVolumes.Count > 0 && __instance._safetyVolumes.Count == 0) { + // Mobius does SetConditionState even when you are in solar system because probe never get destroyed anywhere else but the Eye. if (LoadManager.GetCurrentScene() == OWScene.EyeOfTheUniverse) { DialogueConditionManager.SharedInstance.SetConditionState("PROBE_ENTERED_EYE", conditionState: true); @@ -26,7 +25,8 @@ namespace NewHorizons.Patches else Debug.Log("PROBE DESTROYED"); - ProbeLostAchievement.Earn(); + if (AchievementHandler.Enabled) ProbeLostAchievement.Earn(); + Object.Destroy(__instance._probe.gameObject); } __instance.enabled = false; From 56d52bd5cd0267aea5c121c73bf5d3b14ebf9c17 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 24 Dec 2022 13:19:12 -0500 Subject: [PATCH 04/16] Add parentPath and isRelativeToParent --- NewHorizons/External/Modules/PropModule.cs | 45 +++++++++++++++++++ .../Modules/VariableSize/SingularityModule.cs | 10 +++++ 2 files changed, 55 insertions(+) diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 51610074..a6058299 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -244,6 +244,16 @@ namespace NewHorizons.External.Modules /// [DefaultValue(5f)] public float acceleration = 5f; + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + + /// + /// Whether the positional and rotational coordinates are relative to parent instead of the root planet object. + /// + public bool isRelativeToParent; + /// /// An optional rename of this object /// @@ -293,6 +303,11 @@ namespace NewHorizons.External.Modules /// [DefaultValue(0.7f)] public float volume = 0.7f; + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + /// /// An optional rename of this object /// @@ -365,6 +380,16 @@ namespace NewHorizons.External.Modules /// [DefaultValue("cloud")] public FluidType fluidType = FluidType.Cloud; + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + + /// + /// Whether the positional and rotational coordinates are relative to parent instead of the root planet object. + /// + public bool isRelativeToParent; + /// /// An optional rename of this object /// @@ -418,6 +443,16 @@ namespace NewHorizons.External.Modules /// public MColor stoneTint; + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + + /// + /// Whether the positional and rotational coordinates are relative to parent instead of the root planet object. + /// + public bool isRelativeToParent; + /// /// An optional rename of this object /// @@ -510,6 +545,16 @@ namespace NewHorizons.External.Modules /// public MVector3 position; + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + + /// + /// Whether the positional and rotational coordinates are relative to parent instead of the root planet object. + /// + public bool isRelativeToParent; + /// /// An optional rename of this object /// diff --git a/NewHorizons/External/Modules/VariableSize/SingularityModule.cs b/NewHorizons/External/Modules/VariableSize/SingularityModule.cs index bbdcf27f..e0c1041d 100644 --- a/NewHorizons/External/Modules/VariableSize/SingularityModule.cs +++ b/NewHorizons/External/Modules/VariableSize/SingularityModule.cs @@ -76,6 +76,16 @@ namespace NewHorizons.External.Modules.VariableSize /// [Range(2501f, 3500f)] public int renderQueueOverride = 2985; + /// + /// The relative path from the planet to the parent of this object. Optional (will default to the root sector). + /// + public string parentPath; + + /// + /// Whether the positional and rotational coordinates are relative to parent instead of the root planet object. + /// + public bool isRelativeToParent; + /// /// An optional rename of this object /// From 25e9eaf16f751f9c7b3c1a969a8a8a38d43cf05e Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 24 Dec 2022 13:43:44 -0500 Subject: [PATCH 05/16] Don't use sector if null cause it can be null on some bodies --- NewHorizons/Builder/Atmosphere/AirBuilder.cs | 2 +- NewHorizons/Builder/Props/BrambleNodeBuilder.cs | 2 +- NewHorizons/Builder/Props/QuantumBuilder.cs | 6 +++--- NewHorizons/Builder/Props/TornadoBuilder.cs | 16 ++++++++-------- NewHorizons/Builder/Props/VolcanoBuilder.cs | 2 +- .../Components/NHTornadoWanderController.cs | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/NewHorizons/Builder/Atmosphere/AirBuilder.cs b/NewHorizons/Builder/Atmosphere/AirBuilder.cs index 209a2b26..e4518e4c 100644 --- a/NewHorizons/Builder/Atmosphere/AirBuilder.cs +++ b/NewHorizons/Builder/Atmosphere/AirBuilder.cs @@ -9,7 +9,7 @@ namespace NewHorizons.Builder.Atmosphere var airGO = new GameObject("Air"); airGO.SetActive(false); airGO.layer = 17; - airGO.transform.parent = sector?.transform ? sector.transform : planetGO.transform; + airGO.transform.parent = sector?.transform ?? planetGO.transform; var sc = airGO.AddComponent(); sc.isTrigger = true; diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 48bfc824..6acfd8c1 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -192,7 +192,7 @@ namespace NewHorizons.Builder.Props var outerFogWarpVolume = GetOuterFogWarpVolumeFromAstroObject(go); var fogLight = brambleNode.GetComponent(); - brambleNode.transform.parent = sector.transform; + brambleNode.transform.parent = sector?.transform ?? go.transform; brambleNode.transform.position = go.transform.TransformPoint(config.position ?? Vector3.zero); brambleNode.transform.rotation = go.transform.TransformRotation(Quaternion.Euler(config.rotation ?? Vector3.zero)); brambleNode.name = config.name ?? "Bramble Node to " + config.linksTo; diff --git a/NewHorizons/Builder/Props/QuantumBuilder.cs b/NewHorizons/Builder/Props/QuantumBuilder.cs index 3dd81c3b..8a5a383b 100644 --- a/NewHorizons/Builder/Props/QuantumBuilder.cs +++ b/NewHorizons/Builder/Props/QuantumBuilder.cs @@ -41,7 +41,7 @@ namespace NewHorizons.Builder.Props public static void MakeSocketGroup(GameObject go, Sector sector, PlanetConfig config, IModBehaviour mod, PropModule.QuantumGroupInfo quantumGroup, GameObject[] propsInGroup) { var groupRoot = new GameObject("Quantum Sockets - " + quantumGroup.id); - groupRoot.transform.parent = sector.transform; + groupRoot.transform.parent = sector?.transform ?? go.transform; groupRoot.transform.localPosition = Vector3.zero; groupRoot.transform.localEulerAngles = Vector3.zero; @@ -79,7 +79,7 @@ namespace NewHorizons.Builder.Props public static void MakeStateGroup(GameObject go, Sector sector, PlanetConfig config, IModBehaviour mod, PropModule.QuantumGroupInfo quantumGroup, GameObject[] propsInGroup) { var groupRoot = new GameObject("Quantum States - " + quantumGroup.id); - groupRoot.transform.parent = sector.transform; + groupRoot.transform.parent = sector?.transform ?? go.transform; groupRoot.transform.localPosition = Vector3.zero; var states = new List(); @@ -128,7 +128,7 @@ namespace NewHorizons.Builder.Props //var averagePosition = propsInGroup.Aggregate(Vector3.zero, (avg, prop) => avg + prop.transform.position) / propsInGroup.Count(); GameObject shuffleParent = new GameObject("Quantum Shuffle - " + quantumGroup.id); shuffleParent.SetActive(false); - shuffleParent.transform.parent = sector.transform; + shuffleParent.transform.parent = sector?.transform ?? go.transform; shuffleParent.transform.localPosition = Vector3.zero; propsInGroup.ToList().ForEach(p => p.transform.parent = shuffleParent.transform); diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index d7fef963..9ec65b5b 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -100,9 +100,9 @@ namespace NewHorizons.Builder.Props { var tornadoGO = downwards ? _downPrefab.InstantiateInactive() : _upPrefab.InstantiateInactive(); tornadoGO.name = downwards ? "Tornado_Down" : "Tornado_Up"; - tornadoGO.transform.parent = sector.transform; + tornadoGO.transform.parent = sector?.transform ?? planetGO.transform; tornadoGO.transform.position = planetGO.transform.TransformPoint(position); - tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized)); + tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, planetGO.transform.TransformDirection(position.normalized)); // Add the sound thing before changing the scale var soundGO = _soundPrefab.InstantiateInactive(); @@ -168,7 +168,7 @@ namespace NewHorizons.Builder.Props if (info.wanderRate != 0) { - ApplyWanderer(tornadoGO, sector, info); + ApplyWanderer(tornadoGO, planetGO, info); } soundGO.SetActive(true); @@ -179,9 +179,9 @@ namespace NewHorizons.Builder.Props { var hurricaneGO = _hurricanePrefab.InstantiateInactive(); hurricaneGO.name = "Hurricane"; - hurricaneGO.transform.parent = sector.transform; + hurricaneGO.transform.parent = sector?.transform ?? planetGO.transform; hurricaneGO.transform.position = planetGO.transform.TransformPoint(position); - hurricaneGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(position.normalized)); + hurricaneGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, planetGO.transform.TransformDirection(position.normalized)); var fluidVolume = hurricaneGO.GetComponentInChildren(); fluidVolume._fluidType = info.fluidType.ConvertToOW(FluidVolume.Type.CLOUD); @@ -227,7 +227,7 @@ namespace NewHorizons.Builder.Props if (info.wanderRate != 0) { - ApplyWanderer(hurricaneGO, sector, info); + ApplyWanderer(hurricaneGO, planetGO, info); } hurricaneGO.SetActive(true); @@ -263,13 +263,13 @@ namespace NewHorizons.Builder.Props } } - private static void ApplyWanderer(GameObject go, Sector sector, PropModule.TornadoInfo info) + private static void ApplyWanderer(GameObject go, GameObject planetGO, PropModule.TornadoInfo info) { var wanderer = go.AddComponent(); wanderer.wanderRate = info.wanderRate; wanderer.wanderDegreesX = info.wanderDegreesX; wanderer.wanderDegreesZ = info.wanderDegreesZ; - wanderer.sector = sector; + wanderer.planetGO = planetGO; } } } diff --git a/NewHorizons/Builder/Props/VolcanoBuilder.cs b/NewHorizons/Builder/Props/VolcanoBuilder.cs index df8e549b..dd449e1f 100644 --- a/NewHorizons/Builder/Props/VolcanoBuilder.cs +++ b/NewHorizons/Builder/Props/VolcanoBuilder.cs @@ -44,7 +44,7 @@ namespace NewHorizons.Builder.Props InitPrefab(); var launcherGO = _meteorLauncherPrefab.InstantiateInactive(); - launcherGO.transform.parent = sector.transform; + launcherGO.transform.parent = sector?.transform ?? planetGO.transform; launcherGO.transform.position = planetGO.transform.TransformPoint(info.position == null ? Vector3.zero : (Vector3)info.position); launcherGO.transform.rotation = Quaternion.FromToRotation(launcherGO.transform.TransformDirection(Vector3.up), ((Vector3)info.position).normalized).normalized; launcherGO.name = "MeteorLauncher"; diff --git a/NewHorizons/Components/NHTornadoWanderController.cs b/NewHorizons/Components/NHTornadoWanderController.cs index ea65be11..6d8dcd0e 100644 --- a/NewHorizons/Components/NHTornadoWanderController.cs +++ b/NewHorizons/Components/NHTornadoWanderController.cs @@ -7,7 +7,7 @@ namespace NewHorizons.Components public float wanderRate; public float wanderDegreesX; public float wanderDegreesZ; - public Sector sector; + public GameObject planetGO; private float noiseOffset; private float startDegreesX; @@ -47,7 +47,7 @@ namespace NewHorizons.Components var newPos = new Vector3(newX, newY, newZ); transform.localPosition = newPos; - transform.rotation = Quaternion.FromToRotation(Vector3.up, sector.transform.TransformDirection(newPos.normalized)); + transform.rotation = Quaternion.FromToRotation(Vector3.up, planetGO.transform.TransformDirection(newPos.normalized)); } } } From 97a2ccd25864999164bcbb5a523da9201c64dc08 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Sat, 24 Dec 2022 14:08:07 -0500 Subject: [PATCH 06/16] Actually add the renaming and parenting stuff --- .../Builder/Body/SingularityBuilder.cs | 34 +++++++++++++++---- NewHorizons/Builder/Props/GeyserBuilder.cs | 17 +++++++++- .../Builder/Props/ProjectionBuilder.cs | 9 ++--- NewHorizons/Builder/Props/RaftBuilder.cs | 30 ++++++++++++++-- NewHorizons/Builder/Props/RemoteBuilder.cs | 9 +---- NewHorizons/Builder/Props/TornadoBuilder.cs | 2 +- NewHorizons/Builder/Props/VolcanoBuilder.cs | 26 ++++++++++++-- .../Builder/ShipLog/EntryLocationBuilder.cs | 25 ++++++++++++-- 8 files changed, 124 insertions(+), 28 deletions(-) diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index 0c4d12f1..432c57f0 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -88,9 +88,8 @@ namespace NewHorizons.Builder.Body Vector3 localPosition = singularity?.position == null ? Vector3.zero : singularity.position; Vector3 localRotation = singularity?.rotation == null ? Vector3.zero : singularity.rotation; - GameObject newSingularity = null; - newSingularity = MakeSingularity(go, sector, localPosition, localRotation, polarity, horizonRadius, distortRadius, - hasHazardVolume, singularity.targetStarSystem, singularity.curve, singularity.hasWarpEffects, singularity.renderQueueOverride); + GameObject newSingularity = MakeSingularity(go, sector, localPosition, localRotation, polarity, horizonRadius, distortRadius, + hasHazardVolume, singularity.targetStarSystem, singularity.curve, singularity.hasWarpEffects, singularity.renderQueueOverride, singularity.rename, singularity.parentPath, singularity.isRelativeToParent); var uniqueID = string.IsNullOrEmpty(singularity.uniqueID) ? config.name : singularity.uniqueID; _singularitiesByID.Add(uniqueID, newSingularity); @@ -134,15 +133,32 @@ namespace NewHorizons.Builder.Body } public static GameObject MakeSingularity(GameObject planetGO, Sector sector, Vector3 position, Vector3 rotation, bool polarity, float horizon, float distort, - bool hasDestructionVolume, string targetStarSystem = null, TimeValuePair[] curve = null, bool warpEffects = true, int renderQueue = 2985) + bool hasDestructionVolume, string targetStarSystem = null, TimeValuePair[] curve = null, bool warpEffects = true, int renderQueue = 2985, string rename = null, string parentPath = null, bool isRelativeToParent = false) { InitPrefabs(); // polarity true = black, false = white - var singularity = new GameObject(polarity ? "BlackHole" : "WhiteHole"); + var singularity = new GameObject(!string.IsNullOrEmpty(rename) ? rename : (polarity ? "BlackHole" : "WhiteHole")); singularity.transform.parent = sector?.transform ?? planetGO.transform; - singularity.transform.position = planetGO.transform.TransformPoint(position); + + if (!string.IsNullOrEmpty(parentPath)) + { + var newParent = planetGO.transform.Find(parentPath); + if (newParent != null) + { + singularity.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{parentPath}"); + } + } + + if (isRelativeToParent) + singularity.transform.localPosition = position; + else + singularity.transform.position = planetGO.transform.TransformPoint(position); var singularityRenderer = MakeSingularityGraphics(singularity, polarity, horizon, distort, renderQueue); @@ -257,7 +273,11 @@ namespace NewHorizons.Builder.Body whiteHoleFluidVolume.enabled = true; } - singularity.transform.rotation = planetGO.transform.TransformRotation(Quaternion.Euler(rotation)); + var rot = Quaternion.Euler(rotation); + if (isRelativeToParent) + singularity.transform.localRotation = rot; + else + singularity.transform.rotation = planetGO.transform.TransformRotation(rot); singularity.SetActive(true); return singularity; diff --git a/NewHorizons/Builder/Props/GeyserBuilder.cs b/NewHorizons/Builder/Props/GeyserBuilder.cs index 2ef988d8..dd6a12ce 100644 --- a/NewHorizons/Builder/Props/GeyserBuilder.cs +++ b/NewHorizons/Builder/Props/GeyserBuilder.cs @@ -1,6 +1,8 @@ using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + namespace NewHorizons.Builder.Props { public static class GeyserBuilder @@ -17,8 +19,21 @@ namespace NewHorizons.Builder.Props InitPrefab(); var geyserGO = _geyserPrefab.InstantiateInactive(); + geyserGO.name = !string.IsNullOrEmpty(info.rename) ? info.rename : "Geyser"; geyserGO.transform.parent = sector?.transform ?? planetGO.transform; - geyserGO.name = "Geyser"; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + geyserGO.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } var pos = (Vector3)info.position; diff --git a/NewHorizons/Builder/Props/ProjectionBuilder.cs b/NewHorizons/Builder/Props/ProjectionBuilder.cs index 09e086c4..2c912aff 100644 --- a/NewHorizons/Builder/Props/ProjectionBuilder.cs +++ b/NewHorizons/Builder/Props/ProjectionBuilder.cs @@ -94,7 +94,7 @@ namespace NewHorizons.Builder.Props if (_slideReelPrefab == null) return null; var slideReelObj = _slideReelPrefab.InstantiateInactive(); - slideReelObj.name = $"Prefab_IP_Reel_{mod.ModHelper.Manifest.Name}"; + slideReelObj.name = !string.IsNullOrEmpty(info.rename) ? info.rename : $"Prefab_IP_Reel_{mod.ModHelper.Manifest.Name}"; var slideReel = slideReelObj.GetComponent(); slideReel.SetSector(sector); @@ -196,7 +196,7 @@ namespace NewHorizons.Builder.Props if (_autoPrefab == null) return null; var projectorObj = _autoPrefab.InstantiateInactive(); - projectorObj.name = $"Prefab_IP_AutoProjector_{mod.ModHelper.Manifest.Name}"; + projectorObj.name = !string.IsNullOrEmpty(info.rename) ? info.rename : $"Prefab_IP_AutoProjector_{mod.ModHelper.Manifest.Name}"; var autoProjector = projectorObj.GetComponent(); autoProjector._sector = sector; @@ -276,7 +276,7 @@ namespace NewHorizons.Builder.Props return null; } - g.name = "VisionStaffDetector"; + g.name = !string.IsNullOrEmpty(info.rename) ? info.rename : "VisionStaffDetector"; // The number of slides is unlimited, 15 is only for texturing the actual slide reel item. This is not a slide reel item var slides = info.slides; @@ -312,7 +312,8 @@ namespace NewHorizons.Builder.Props position = info.position, rotation = info.rotation, parentPath = info.parentPath, - isRelativeToParent = info.isRelativeToParent + isRelativeToParent = info.isRelativeToParent, + rename = info.rename }; var standingTorch = DetailBuilder.Make(planetGO, sector, _standingVisionTorchPrefab, detailInfo); diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index ae27cea2..77295611 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -53,10 +53,34 @@ namespace NewHorizons.Builder.Props if (_prefab == null || sector == null) return null; GameObject raftObject = _prefab.InstantiateInactive(); - raftObject.name = "Raft_Body"; + raftObject.name = !string.IsNullOrEmpty(info.rename) ? info.rename : "Raft_Body"; raftObject.transform.parent = sector?.transform ?? planetGO.transform; - raftObject.transform.position = planetGO.transform.TransformPoint(info?.position ?? Vector3.zero); - raftObject.transform.rotation = planetGO.transform.TransformRotation(Quaternion.identity); + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + raftObject.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + + var pos = (Vector3)(info.position ?? Vector3.zero); + var rot = Quaternion.identity; + if (info.isRelativeToParent) + { + raftObject.transform.localPosition = pos; + raftObject.transform.localRotation = rot; + } + else + { + raftObject.transform.position = planetGO.transform.TransformPoint(pos); + raftObject.transform.rotation = planetGO.transform.TransformRotation(rot); + } StreamingHandler.SetUpStreaming(raftObject, sector); diff --git a/NewHorizons/Builder/Props/RemoteBuilder.cs b/NewHorizons/Builder/Props/RemoteBuilder.cs index 83c66158..bfe446d4 100644 --- a/NewHorizons/Builder/Props/RemoteBuilder.cs +++ b/NewHorizons/Builder/Props/RemoteBuilder.cs @@ -252,14 +252,7 @@ namespace NewHorizons.Builder.Props { var shareStone = _shareStonePrefab.InstantiateInactive(); - if (!string.IsNullOrEmpty(info.rename)) - { - shareStone.name = info.rename; - } - else - { - shareStone.name = "ShareStone_" + id.ToString(); - } + shareStone.name = !string.IsNullOrEmpty(info.rename) ? info.rename : ("ShareStone_" + id.ToString()); shareStone.transform.parent = sector?.transform ?? go.transform; diff --git a/NewHorizons/Builder/Props/TornadoBuilder.cs b/NewHorizons/Builder/Props/TornadoBuilder.cs index 9ec65b5b..2b63bd52 100644 --- a/NewHorizons/Builder/Props/TornadoBuilder.cs +++ b/NewHorizons/Builder/Props/TornadoBuilder.cs @@ -99,7 +99,7 @@ namespace NewHorizons.Builder.Props private static void MakeTornado(GameObject planetGO, Sector sector, PropModule.TornadoInfo info, Vector3 position, bool downwards) { var tornadoGO = downwards ? _downPrefab.InstantiateInactive() : _upPrefab.InstantiateInactive(); - tornadoGO.name = downwards ? "Tornado_Down" : "Tornado_Up"; + tornadoGO.name = !string.IsNullOrEmpty(info.rename) ? info.rename : (downwards ? "Tornado_Down" : "Tornado_Up"); tornadoGO.transform.parent = sector?.transform ?? planetGO.transform; tornadoGO.transform.position = planetGO.transform.TransformPoint(position); tornadoGO.transform.rotation = Quaternion.FromToRotation(Vector3.up, planetGO.transform.TransformDirection(position.normalized)); diff --git a/NewHorizons/Builder/Props/VolcanoBuilder.cs b/NewHorizons/Builder/Props/VolcanoBuilder.cs index dd449e1f..478213cf 100644 --- a/NewHorizons/Builder/Props/VolcanoBuilder.cs +++ b/NewHorizons/Builder/Props/VolcanoBuilder.cs @@ -1,6 +1,8 @@ using NewHorizons.External.Modules; using NewHorizons.Utility; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + namespace NewHorizons.Builder.Props { public static class VolcanoBuilder @@ -44,10 +46,30 @@ namespace NewHorizons.Builder.Props InitPrefab(); var launcherGO = _meteorLauncherPrefab.InstantiateInactive(); + launcherGO.name = !string.IsNullOrEmpty(info.rename) ? info.rename : "MeteorLauncher"; launcherGO.transform.parent = sector?.transform ?? planetGO.transform; launcherGO.transform.position = planetGO.transform.TransformPoint(info.position == null ? Vector3.zero : (Vector3)info.position); - launcherGO.transform.rotation = Quaternion.FromToRotation(launcherGO.transform.TransformDirection(Vector3.up), ((Vector3)info.position).normalized).normalized; - launcherGO.name = "MeteorLauncher"; + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = planetGO.transform.Find(info.parentPath); + if (newParent != null) + { + launcherGO.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {planetGO.name}/{info.parentPath}"); + } + } + + var pos = (Vector3)(info.position ?? Vector3.zero); + if (info.isRelativeToParent) + launcherGO.transform.localPosition = pos; + else + launcherGO.transform.position = planetGO.transform.TransformPoint(pos); + + launcherGO.transform.rotation = Quaternion.FromToRotation(launcherGO.transform.TransformDirection(Vector3.up), pos.normalized).normalized; var meteorLauncher = launcherGO.GetComponent(); meteorLauncher._audioSector = sector; diff --git a/NewHorizons/Builder/ShipLog/EntryLocationBuilder.cs b/NewHorizons/Builder/ShipLog/EntryLocationBuilder.cs index b35ec450..4218e400 100644 --- a/NewHorizons/Builder/ShipLog/EntryLocationBuilder.cs +++ b/NewHorizons/Builder/ShipLog/EntryLocationBuilder.cs @@ -2,6 +2,8 @@ using NewHorizons.External.Modules; using OWML.Common; using System.Collections.Generic; using UnityEngine; +using Logger = NewHorizons.Utility.Logger; + namespace NewHorizons.Builder.ShipLog { public static class EntryLocationBuilder @@ -9,10 +11,29 @@ namespace NewHorizons.Builder.ShipLog private static readonly List _locationsToInitialize = new List(); public static void Make(GameObject go, Sector sector, PropModule.EntryLocationInfo info, IModBehaviour mod) { - GameObject entryLocationGameObject = new GameObject("Entry Location (" + info.id + ")"); + GameObject entryLocationGameObject = new GameObject(!string.IsNullOrEmpty(info.rename) ? info.rename : ("Entry Location (" + info.id + ")")); entryLocationGameObject.SetActive(false); entryLocationGameObject.transform.parent = sector?.transform ?? go.transform; - entryLocationGameObject.transform.position = go.transform.TransformPoint(info.position ?? Vector3.zero); + + if (!string.IsNullOrEmpty(info.parentPath)) + { + var newParent = go.transform.Find(info.parentPath); + if (newParent != null) + { + entryLocationGameObject.transform.parent = newParent; + } + else + { + Logger.LogWarning($"Cannot find parent object at path: {go.name}/{info.parentPath}"); + } + } + + var pos = (Vector3)(info.position ?? Vector3.zero); + if (info.isRelativeToParent) + entryLocationGameObject.transform.localPosition = pos; + else + entryLocationGameObject.transform.position = go.transform.TransformPoint(pos); + ShipLogEntryLocation newLocation = entryLocationGameObject.AddComponent(); newLocation._entryID = info.id; newLocation._outerFogWarpVolume = go.GetComponentInChildren(); From 8ada7c7b77468eda20cd601357da40c8df6ce437 Mon Sep 17 00:00:00 2001 From: Ben C Date: Sat, 24 Dec 2022 19:11:25 +0000 Subject: [PATCH 07/16] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 72 ++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 03fedb7f..8da78e60 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1162,6 +1162,18 @@ "position": { "description": "The position of this entry location", "$ref": "#/definitions/MVector3" + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "isRelativeToParent": { + "type": "boolean", + "description": "Whether the positional and rotational coordinates are relative to parent instead of the root planet object." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" } } }, @@ -1218,6 +1230,14 @@ "description": "Loudness of the geyser", "format": "float", "default": 0.7 + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" } } }, @@ -1390,6 +1410,18 @@ "description": "Acceleration of the raft. Default acceleration is 5.", "format": "float", "default": 5.0 + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "isRelativeToParent": { + "type": "boolean", + "description": "Whether the positional and rotational coordinates are relative to parent instead of the root planet object." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" } } }, @@ -1505,6 +1537,10 @@ "isRelativeToParent": { "type": "boolean", "description": "Whether the positional and rotational coordinates are relative to parent instead of the root planet object." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" } } }, @@ -1707,6 +1743,18 @@ "description": "Fluid type for sounds/effects when colliding with this tornado.", "default": "cloud", "$ref": "#/definitions/FluidType" + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "isRelativeToParent": { + "type": "boolean", + "description": "Whether the positional and rotational coordinates are relative to parent instead of the root planet object." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" } } }, @@ -1768,6 +1816,18 @@ "stoneTint": { "description": "The colour of the meteor's stone.", "$ref": "#/definitions/MColor" + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "isRelativeToParent": { + "type": "boolean", + "description": "Whether the positional and rotational coordinates are relative to parent instead of the root planet object." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" } } }, @@ -1828,6 +1888,18 @@ "format": "int32", "maximum": 3500.0, "minimum": 2501.0 + }, + "parentPath": { + "type": "string", + "description": "The relative path from the planet to the parent of this object. Optional (will default to the root sector)." + }, + "isRelativeToParent": { + "type": "boolean", + "description": "Whether the positional and rotational coordinates are relative to parent instead of the root planet object." + }, + "rename": { + "type": "string", + "description": "An optional rename of this object" } } }, From 4488390bd93550e9f91c2570a0f3a487f0dfd3da Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 11:55:04 -0800 Subject: [PATCH 08/16] do streaming unloading --- NewHorizons/Handlers/StreamingHandler.cs | 3 --- 1 file changed, 3 deletions(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index 116c3ae6..9aed55ef 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -106,15 +106,12 @@ namespace NewHorizons.Handlers foreach (var assetBundle in assetBundles) StreamingManager.LoadStreamingAssets(assetBundle); }; - /* sector.OnOccupantExitSector += _ => { - // UnloadStreamingAssets is patched to check IsBundleInUse first before unloading if (!sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) foreach (var assetBundle in assetBundles) StreamingManager.UnloadStreamingAssets(assetBundle); }; - */ } } From f8de674a6d7c30769c10fafcdb09705f0e0b7bb2 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 12:06:49 -0800 Subject: [PATCH 09/16] filter out goofy error --- ...reamingManagerPatches.cs => StreamingPatches.cs} | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) rename NewHorizons/Patches/{StreamingManagerPatches.cs => StreamingPatches.cs} (53%) diff --git a/NewHorizons/Patches/StreamingManagerPatches.cs b/NewHorizons/Patches/StreamingPatches.cs similarity index 53% rename from NewHorizons/Patches/StreamingManagerPatches.cs rename to NewHorizons/Patches/StreamingPatches.cs index 5f422072..e877a789 100644 --- a/NewHorizons/Patches/StreamingManagerPatches.cs +++ b/NewHorizons/Patches/StreamingPatches.cs @@ -1,10 +1,11 @@ using HarmonyLib; using NewHorizons.Handlers; +using OWML.Logging; namespace NewHorizons.Patches { [HarmonyPatch] - public static class StreamingManagerPatches + public static class StreamingPatches { [HarmonyPrefix] [HarmonyPatch(typeof(StreamingManager), nameof(StreamingManager.UnloadStreamingAssets))] @@ -12,6 +13,14 @@ namespace NewHorizons.Patches { // Only let it unload stuff that isn't being used return !StreamingHandler.IsBundleInUse(assetBundleName); - } + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(UnityLogger), "OnLogMessageReceived")] + public static bool UnityLogger_OnLogMessageReceived(string message) + { + // Filter out goofy error that doesn't actually break anything + return !message.Contains(" is out of bounds (size=0)"); + } } } From c3b343b4bf7c77cc4d1c3f51716f3db00b9e2260 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 12:11:56 -0800 Subject: [PATCH 10/16] be more specific --- NewHorizons/Patches/StreamingPatches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Patches/StreamingPatches.cs b/NewHorizons/Patches/StreamingPatches.cs index e877a789..b188106c 100644 --- a/NewHorizons/Patches/StreamingPatches.cs +++ b/NewHorizons/Patches/StreamingPatches.cs @@ -20,7 +20,7 @@ namespace NewHorizons.Patches public static bool UnityLogger_OnLogMessageReceived(string message) { // Filter out goofy error that doesn't actually break anything - return !message.Contains(" is out of bounds (size=0)"); + return !message.EndsWith(" is out of bounds (size=0)"); } } } From ca07710866e8a5cfb8ec67b95b4ea497860a8879 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 12:14:21 -0800 Subject: [PATCH 11/16] MORE specific --- NewHorizons/Patches/StreamingPatches.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Patches/StreamingPatches.cs b/NewHorizons/Patches/StreamingPatches.cs index b188106c..85acd0ab 100644 --- a/NewHorizons/Patches/StreamingPatches.cs +++ b/NewHorizons/Patches/StreamingPatches.cs @@ -20,7 +20,7 @@ namespace NewHorizons.Patches public static bool UnityLogger_OnLogMessageReceived(string message) { // Filter out goofy error that doesn't actually break anything - return !message.EndsWith(" is out of bounds (size=0)"); + return !message.EndsWith(") is out of bounds (size=0)"); } } } From ce4072fed09089023021b2bad0e3e8064c72b8fc Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 12:16:56 -0800 Subject: [PATCH 12/16] check null here --- NewHorizons/Builder/Props/NomaiTextBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/NomaiTextBuilder.cs b/NewHorizons/Builder/Props/NomaiTextBuilder.cs index 54aaa96a..25cc09bc 100644 --- a/NewHorizons/Builder/Props/NomaiTextBuilder.cs +++ b/NewHorizons/Builder/Props/NomaiTextBuilder.cs @@ -614,7 +614,7 @@ namespace NewHorizons.Builder.Props nomaiWallText.SetTextAsset(text); // #433 fuzzy stranger text - if (info.arcInfo.Any(x => x.type == PropModule.NomaiTextArcInfo.NomaiTextArcType.Stranger)) + if (info.arcInfo != null && info.arcInfo.Any(x => x.type == PropModule.NomaiTextArcInfo.NomaiTextArcType.Stranger)) { StreamingHandler.SetUpStreaming(AstroObject.Name.RingWorld, sector); } From 177eea9e3604e800c3d36ac7aac1b1c24f284013 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 12:28:29 -0800 Subject: [PATCH 13/16] do proper null checking on sectors --- NewHorizons/Handlers/StreamingHandler.cs | 32 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index 9aed55ef..7cb6abf5 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -24,16 +24,23 @@ namespace NewHorizons.Handlers { var group = GetStreamingGroup(name); - sector.OnOccupantEnterSector += _ => + if (sector) { - if (sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) - group.RequestGeneralAssets(); - }; - sector.OnOccupantExitSector += _ => + sector.OnOccupantEnterSector += _ => + { + if (sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) + group.RequestGeneralAssets(); + }; + sector.OnOccupantExitSector += _ => + { + if (!sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) + group.ReleaseGeneralAssets(); + }; + } + else { - if (!sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) - group.ReleaseGeneralAssets(); - }; + group.RequestGeneralAssets(); + } } /// @@ -87,8 +94,6 @@ namespace NewHorizons.Handlers foreach (var assetBundle in assetBundles) { - StreamingManager.LoadStreamingAssets(assetBundle); - // Track the sector even if its null. null means stay loaded forever if (!_sectorCache.TryGetValue(assetBundle, out var sectors)) { @@ -113,6 +118,11 @@ namespace NewHorizons.Handlers StreamingManager.UnloadStreamingAssets(assetBundle); }; } + else + { + foreach (var assetBundle in assetBundles) + StreamingManager.LoadStreamingAssets(assetBundle); + } } public static bool IsBundleInUse(string assetBundle) @@ -133,7 +143,7 @@ namespace NewHorizons.Handlers } else { - return Locator.GetAstroObject(name)?.GetComponentInChildren(); + return Locator.GetAstroObject(name).GetComponentInChildren(); } } } From 3c44c030054baf1ba95a88ddc0bc42d6459da932 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 13:40:18 -0800 Subject: [PATCH 14/16] do streaming on bramble node --- NewHorizons/Builder/Props/BrambleNodeBuilder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 6acfd8c1..601f4a7f 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -199,6 +199,8 @@ namespace NewHorizons.Builder.Props // This node comes with Feldspar's signal, we don't want that though GameObject.Destroy(brambleNode.FindChild("Signal_Harmonica")); + + StreamingHandler.SetUpStreaming(brambleNode, sector); // Fix some components fogLight._parentBody = go.GetComponent(); From 1f69ad640e8c7a483a4cc1cda6b08af52e7e08c7 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 13:42:44 -0800 Subject: [PATCH 15/16] put it lower --- NewHorizons/Builder/Props/BrambleNodeBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs index 601f4a7f..168febcb 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -200,8 +200,6 @@ namespace NewHorizons.Builder.Props // This node comes with Feldspar's signal, we don't want that though GameObject.Destroy(brambleNode.FindChild("Signal_Harmonica")); - StreamingHandler.SetUpStreaming(brambleNode, sector); - // Fix some components fogLight._parentBody = go.GetComponent(); fogLight._sector = sector; @@ -387,6 +385,8 @@ namespace NewHorizons.Builder.Props } } + StreamingHandler.SetUpStreaming(brambleNode, sector); + // Done! brambleNode.SetActive(true); return brambleNode; From ea550edfea19101060d30e75560f1932443f5211 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 28 Dec 2022 13:46:01 -0800 Subject: [PATCH 16/16] bruh --- 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 168febcb..f3980776 100644 --- a/NewHorizons/Builder/Props/BrambleNodeBuilder.cs +++ b/NewHorizons/Builder/Props/BrambleNodeBuilder.cs @@ -199,7 +199,7 @@ namespace NewHorizons.Builder.Props // This node comes with Feldspar's signal, we don't want that though GameObject.Destroy(brambleNode.FindChild("Signal_Harmonica")); - + // Fix some components fogLight._parentBody = go.GetComponent(); fogLight._sector = sector;