From f4b05940e32791c5dc5e9872168352e87000e6c1 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 31 Aug 2022 18:31:26 -0400 Subject: [PATCH 01/33] Fibonacci deadass thought his sequence counted rabbits --- NewHorizons/Builder/Props/ScatterBuilder.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index 26af9d33..2024d3ae 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -25,7 +25,7 @@ namespace NewHorizons.Builder.Props // Works up to planets with 575 radius before capping var numPoints = Math.Min((int)(area * 10), 41666666); - var points = RandomUtility.FibonacciSphere(numPoints); + //var points = RandomUtility.FibonacciSphere(numPoints); Texture2D heightMapTexture = null; if (heightMap != null) @@ -57,11 +57,7 @@ namespace NewHorizons.Builder.Props else prefab = SearchUtilities.Find(propInfo.path); for (int i = 0; i < propInfo.count; i++) { - // Failsafe - if (points.Count == 0) break; - - var randomInd = (int)Random.Range(0, points.Count - 1); - var point = points[randomInd]; + var point = Random.insideUnitSphere; var height = radius; if (heightMapTexture != null) @@ -105,9 +101,6 @@ namespace NewHorizons.Builder.Props // Rotate around normal prop.transform.localRotation *= Quaternion.AngleAxis(Random.Range(0, 360), Vector3.up); - - points.QuickRemoveAt(randomInd); - if (points.Count == 0) return; } } } From e73c48e5fc17aafcb0142d9bf8a636f0ef9a1b20 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 31 Aug 2022 19:00:27 -0400 Subject: [PATCH 02/33] Only run detail builder once --- NewHorizons/Builder/Props/ScatterBuilder.cs | 27 +++++++++------------ 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index 2024d3ae..e5d14c8a 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -19,14 +19,6 @@ namespace NewHorizons.Builder.Props { var heightMap = config.HeightMap; - var area = 4f * Mathf.PI * radius * radius; - - // To not use more than 0.5GB of RAM while doing this - // Works up to planets with 575 radius before capping - var numPoints = Math.Min((int)(area * 10), 41666666); - - //var points = RandomUtility.FibonacciSphere(numPoints); - Texture2D heightMapTexture = null; if (heightMap != null) { @@ -55,6 +47,14 @@ namespace NewHorizons.Builder.Props GameObject prefab; if (propInfo.assetBundle != null) prefab = AssetBundleUtilities.LoadPrefab(propInfo.assetBundle, propInfo.path, mod); else prefab = SearchUtilities.Find(propInfo.path); + + // Run all the make detail stuff on it early and just copy it over and over instead + var detailInfo = new PropModule.DetailInfo() + { + scale = propInfo.scale + }; + prefab = DetailBuilder.Make(go, sector, prefab, detailInfo); + for (int i = 0; i < propInfo.count; i++) { var point = Random.insideUnitSphere; @@ -88,13 +88,10 @@ namespace NewHorizons.Builder.Props point = Quaternion.Euler(90, 0, 0) * point; } - var detailInfo = new PropModule.DetailInfo() - { - position = point.normalized * height, - scale = propInfo.scale, - alignToNormal = true - }; - var prop = DetailBuilder.Make(go, sector, prefab, detailInfo); + var prop = prefab.InstantiateInactive(); + prop.transform.localPosition = go.transform.TransformPoint(point); + var up = go.transform.InverseTransformPoint(prop.transform.position).normalized; + prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up); if (propInfo.offset != null) prop.transform.localPosition += prop.transform.TransformVector(propInfo.offset); if (propInfo.rotation != null) prop.transform.rotation *= Quaternion.Euler(propInfo.rotation); From 3f6a0f04f55b25966060c4c96f9cbf597c5f16fd Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 31 Aug 2022 19:04:36 -0400 Subject: [PATCH 03/33] Set active dingus --- NewHorizons/Builder/Props/ScatterBuilder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index e5d14c8a..57efa403 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -98,6 +98,8 @@ namespace NewHorizons.Builder.Props // Rotate around normal prop.transform.localRotation *= Quaternion.AngleAxis(Random.Range(0, 360), Vector3.up); + + prop.SetActive(true); } } } From fb85ecdb35ba5b50093d2dbdd1df92e2021baa4e Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 31 Aug 2022 19:07:44 -0400 Subject: [PATCH 04/33] Set parent dingus --- NewHorizons/Builder/Props/ScatterBuilder.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index 57efa403..571d48db 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -89,6 +89,7 @@ namespace NewHorizons.Builder.Props } var prop = prefab.InstantiateInactive(); + prop.transform.SetParent(sector?.transform ?? go.transform); prop.transform.localPosition = go.transform.TransformPoint(point); var up = go.transform.InverseTransformPoint(prop.transform.position).normalized; prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up); From 93ef061b4b64c0ca201112822bf8c47a07e89524 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 31 Aug 2022 19:09:05 -0400 Subject: [PATCH 05/33] Destroy prefab --- NewHorizons/Builder/Props/ScatterBuilder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index 571d48db..49a4e1c9 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -102,6 +102,8 @@ namespace NewHorizons.Builder.Props prop.SetActive(true); } + + GameObject.Destroy(prefab); } } } From 422489f8de5fd82cfd6754856f4d96d2a9eed64a Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 31 Aug 2022 19:16:40 -0400 Subject: [PATCH 06/33] Forgot to multiply by height --- NewHorizons/Builder/Props/ScatterBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index 49a4e1c9..f1cb00d5 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -90,7 +90,7 @@ namespace NewHorizons.Builder.Props var prop = prefab.InstantiateInactive(); prop.transform.SetParent(sector?.transform ?? go.transform); - prop.transform.localPosition = go.transform.TransformPoint(point); + prop.transform.localPosition = go.transform.TransformPoint(point * height); var up = go.transform.InverseTransformPoint(prop.transform.position).normalized; prop.transform.rotation = Quaternion.FromToRotation(Vector3.up, up); From 9039c00908e1cecfff8b2db645b46d26a8b2f6ea Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 31 Aug 2022 22:57:50 -0400 Subject: [PATCH 07/33] Add preventOverlap option for better performance, fixed heights --- NewHorizons/Builder/Props/ScatterBuilder.cs | 30 ++++++++++++++++++++- NewHorizons/External/Modules/PropModule.cs | 5 ++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index f1cb00d5..bcbc4899 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -3,6 +3,8 @@ using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; using System; +using System.Collections.Generic; +using System.Linq; using UnityEngine; using Object = UnityEngine.Object; using Random = UnityEngine.Random; @@ -19,6 +21,21 @@ namespace NewHorizons.Builder.Props { var heightMap = config.HeightMap; + var makeFibonacciSphere = scatterInfo.Any(x => x.preventOverlap); + + List points = new(); + + if (makeFibonacciSphere) + { + var area = 4f * Mathf.PI * radius * radius; + + // To not use more than 0.5GB of RAM while doing this + // Works up to planets with 575 radius before capping + var numPoints = Math.Min((int)(area * 10), 41666666); + + points = RandomUtility.FibonacciSphere(numPoints); + } + Texture2D heightMapTexture = null; if (heightMap != null) { @@ -57,7 +74,18 @@ namespace NewHorizons.Builder.Props for (int i = 0; i < propInfo.count; i++) { - var point = Random.insideUnitSphere; + Vector3 point; + if (propInfo.preventOverlap) + { + if (points.Count == 0) break; + var randomInd = (int)Random.Range(0, points.Count - 1); + point = points[randomInd]; + points.QuickRemoveAt(randomInd); + } + else + { + point = Random.onUnitSphere; + } var height = radius; if (heightMapTexture != null) diff --git a/NewHorizons/External/Modules/PropModule.cs b/NewHorizons/External/Modules/PropModule.cs index 932b1bc0..1a7c6473 100644 --- a/NewHorizons/External/Modules/PropModule.cs +++ b/NewHorizons/External/Modules/PropModule.cs @@ -139,6 +139,11 @@ namespace NewHorizons.External.Modules /// The highest height that these objects will be placed at (only relevant if there's a heightmap) /// public float? maxHeight; + + /// + /// Should we try to prevent overlap between the scattered details? True by default. If it's affecting load times turn it off. + /// + [DefaultValue(true)] public bool preventOverlap = true; } [JsonObject] From 2967565653ba27a4637f2d4a81405047f72719f5 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 31 Aug 2022 22:59:31 -0400 Subject: [PATCH 08/33] Remove redundant cast --- NewHorizons/Builder/Props/ScatterBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index bcbc4899..b8aac0e0 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -78,7 +78,7 @@ namespace NewHorizons.Builder.Props if (propInfo.preventOverlap) { if (points.Count == 0) break; - var randomInd = (int)Random.Range(0, points.Count - 1); + var randomInd = Random.Range(0, points.Count - 1); point = points[randomInd]; points.QuickRemoveAt(randomInd); } From b987e7833b698f737a373e466f00c464fef74c72 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 1 Sep 2022 03:01:34 +0000 Subject: [PATCH 09/33] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 7ea40e04..328e550a 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1389,6 +1389,11 @@ ], "description": "The highest height that these objects will be placed at (only relevant if there's a heightmap)", "format": "float" + }, + "preventOverlap": { + "type": "boolean", + "description": "Should we try to prevent overlap between the scattered details? True by default. If it's affecting load times turn it off.", + "default": true } } }, From 3d1e450d6d68c6812b20f499e2570796f5af1a7b Mon Sep 17 00:00:00 2001 From: TerrificTrifid <99054745+TerrificTrifid@users.noreply.github.com> Date: Fri, 2 Sep 2022 19:15:49 -0500 Subject: [PATCH 10/33] Disable starlights when out of range --- NewHorizons/Builder/Body/StarBuilder.cs | 1 - .../StarEvolutionController.cs | 3 ++ NewHorizons/Components/StarLightController.cs | 33 +++++++++++++++++-- NewHorizons/Handlers/PlanetCreationHandler.cs | 4 +++ .../Handlers/PlanetDestructionHandler.cs | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 7e32c3d3..99a6ee9f 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -126,7 +126,6 @@ namespace NewHorizons.Builder.Body light.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); light.intensity *= starModule.solarLuminosity; light.range = starModule.lightRadius; - light.range *= Mathf.Sqrt(starModule.solarLuminosity); Color lightColour = light.color; if (starModule.lightTint != null) lightColour = starModule.lightTint.ToColor(); diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index ce904cca..164c2a20 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -287,6 +287,8 @@ namespace NewHorizons.Components.SizeControllers _stellarRemnant.SetActive(true); var remnantStarController = _stellarRemnant.GetComponentInChildren(); if (remnantStarController != null) StarLightController.AddStar(remnantStarController); + var remnantStarLight = _stellarRemnant.FindChild("SunLight"); + if (remnantStarLight != null) StarLightController.AddStarLight(remnantStarLight.GetComponent()); } if (Time.time > _supernovaStartTime + supernovaTime) @@ -300,6 +302,7 @@ namespace NewHorizons.Components.SizeControllers private void DisableStar(bool start = false) { if (controller != null) StarLightController.RemoveStar(controller); + StarLightController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); if (_stellarRemnant != null) { diff --git a/NewHorizons/Components/StarLightController.cs b/NewHorizons/Components/StarLightController.cs index 55a79074..a9e2b000 100644 --- a/NewHorizons/Components/StarLightController.cs +++ b/NewHorizons/Components/StarLightController.cs @@ -14,6 +14,7 @@ namespace NewHorizons.Components public static StarLightController Instance { get; private set; } private List _stars = new List(); + private List _lights = new List(); private StarController _activeStar; private SunLightController _sunLightController; @@ -53,6 +54,20 @@ namespace NewHorizons.Components } } + public static void AddStarLight(Light light) + { + if (light == null) return; + + Instance._lights.Add(light); + } + + public static void RemoveStarLight(Light light) + { + if (light == null) return; + + if (Instance._lights.Contains(light)) Instance._lights.Remove(light); + } + public void Update() { if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) @@ -78,13 +93,14 @@ namespace NewHorizons.Components material.SetFloat(SunIntensity, intensity); } + // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv + var origin = Vector3.zero; + foreach (var star in _stars) { if (star == null) continue; if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; - // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv - var origin = Vector3.zero; if (PlayerState.InMapView()) { origin = Locator.GetActiveCamera().transform.position; @@ -96,6 +112,19 @@ namespace NewHorizons.Components break; } } + + if (PlayerState.InMapView()) + { + foreach (var light in _lights) light.enabled = true; + return; + } + + foreach (var light in _lights) + { + // Minimum 50km range so it's not badly noticeable for dim stars + if ((light.transform.position - origin).sqrMagnitude <= Mathf.Max(light.range * light.range, 2500000000)) light.enabled = true; + else light.enabled = false; + } } private void ChangeActiveStar(StarController star) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 67700c36..84f97aea 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -59,6 +59,7 @@ namespace NewHorizons.Handlers starLightGO.AddComponent(); StarLightController.AddStar(starController); + StarLightController.AddStarLight(starController.Light); starLightGO.SetActive(true); @@ -500,6 +501,9 @@ namespace NewHorizons.Handlers if (starController != null) StarLightController.AddStar(starController); + var starLight = star.FindChild("SunLight"); + if (starLight != null) StarLightController.AddStarLight(starLight.GetComponent()); + // If it has an evolution controller that means it will die -> we make a remnant (unless its a remnant) if (starEvolutionController != null && !body.Config.isStellarRemnant) { diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 4d60a271..b92e7972 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -118,6 +118,7 @@ namespace NewHorizons.Handlers case AstroObject.Name.Sun: var starController = ao.gameObject.GetComponent(); StarLightController.RemoveStar(starController); + StarLightController.RemoveStarLight(ao.gameObject.FindChild("SunLight").GetComponent()); GameObject.Destroy(starController); var audio = ao.GetComponentInChildren(); From 7bcddf4261c9a1b0fcc6df6bd06367efb90f6741 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Sep 2022 21:58:31 -0400 Subject: [PATCH 11/33] Fix collision issue --- NewHorizons/Builder/Props/DetailBuilder.cs | 102 ++++++++++++++------ NewHorizons/Builder/Props/ScatterBuilder.cs | 6 +- 2 files changed, 77 insertions(+), 31 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index ae7a63f7..f49c8289 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -5,8 +5,10 @@ using NewHorizons.Utility; using OWML.Common; using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using UnityEngine; +using Component = UnityEngine.Component; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Props { @@ -71,6 +73,9 @@ namespace NewHorizons.Builder.Props var isTorch = prop.GetComponent() != null; + // Fix a bunch of stuff when done loading + var fixes = new List(); + foreach (var component in prop.GetComponentsInChildren(true)) { if (sector == null) @@ -80,6 +85,16 @@ namespace NewHorizons.Builder.Props else FixSectoredComponent(component, sector, isTorch); FixComponent(component, go, prefab.name); + + if (DetailFixer.fixes.Keys.Any(x => x.IsAssignableFrom(component.GetType()))) + { + fixes.Add(component); + } + } + + if (fixes.Count > 0) + { + prop.AddComponent().SetFixes(fixes); } prop.transform.position = detail.position == null ? go.transform.position : go.transform.TransformPoint(detail.position); @@ -277,44 +292,75 @@ namespace NewHorizons.Builder.Props torchItem.mindProjectorTrigger.enabled = true; torchItem.mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); } + } - // Fix a bunch of stuff when done loading - Delay.RunWhen(() => Main.IsSystemReady, () => + /// + /// Performs fixes that have to be done after the system loads + /// Has to be done this way to ensure that scatter works + /// + private class DetailFixer : MonoBehaviour + { + public static Dictionary> fixes = new() { - try + [typeof(AnglerfishAnimController)] = (x) => { - if (component == null) return; - if (component is Animator animator) animator.enabled = true; - else if (component is Collider collider) collider.enabled = true; - else if (component is Renderer renderer) renderer.enabled = true; - else if (component is Shape shape) shape.enabled = true; - else if (component is SectorCullGroup sectorCullGroup) + var angler = x as AnglerfishAnimController; + + Logger.LogVerbose("Enabling anglerfish animation"); + // Remove any reference to its angler + if (angler._anglerfishController) { - sectorCullGroup._inMapView = false; - sectorCullGroup._isFastForwarding = false; - sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); + angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; + angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; + angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; + angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; } - // If it's not a moving anglerfish make sure the anim controller is regular - else if (component is AnglerfishAnimController angler && angler.GetComponentInParent() == null) + angler.enabled = true; + angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); + }, + [typeof(SectorCullGroup)] = (x) => + { + var sectorCullGroup = x as SectorCullGroup; + sectorCullGroup._inMapView = false; + sectorCullGroup._isFastForwarding = false; + sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); + }, + [typeof(Shape)] = (x) => (x as Shape).enabled = true, + [typeof(Renderer)] = (x) => (x as Renderer).enabled = true, + [typeof(Collider)] = (x) => (x as Collider).enabled = true, + [typeof(Animator)] = (x) => (x as Animator).enabled = true + }; + + // Have to be public to be copied by Instantiate + public Component[] componentsToFix; + + public void SetFixes(List fixes) + { + // Components must be in a list for unity to properly deep copy + componentsToFix = fixes.ToArray(); + } + + public void Start() + { + for (int i = 0; i < componentsToFix.Length; i++) + { + var component = componentsToFix[i]; + + try { - Logger.LogVerbose("Enabling anglerfish animation"); - // Remove any reference to its angler - if (angler._anglerfishController) + if (component != null) { - angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; - angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; - angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; - angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; + var key = fixes.Keys.FirstOrDefault(x => x.IsAssignableFrom(component.GetType())); + var fix = fixes[key]; + fix(component); } - angler.enabled = true; - angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); + } + catch (Exception) + { + Logger.LogWarning($"Failed to fix component {component} on {gameObject.name}"); } } - catch (Exception e) - { - Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] for prop [{prefab}]:\n{e}"); - } - }); + } } } } \ No newline at end of file diff --git a/NewHorizons/Builder/Props/ScatterBuilder.cs b/NewHorizons/Builder/Props/ScatterBuilder.cs index b8aac0e0..2deea2c8 100644 --- a/NewHorizons/Builder/Props/ScatterBuilder.cs +++ b/NewHorizons/Builder/Props/ScatterBuilder.cs @@ -70,7 +70,7 @@ namespace NewHorizons.Builder.Props { scale = propInfo.scale }; - prefab = DetailBuilder.Make(go, sector, prefab, detailInfo); + var scatterPrefab = DetailBuilder.Make(go, sector, prefab, detailInfo); for (int i = 0; i < propInfo.count; i++) { @@ -116,7 +116,7 @@ namespace NewHorizons.Builder.Props point = Quaternion.Euler(90, 0, 0) * point; } - var prop = prefab.InstantiateInactive(); + var prop = scatterPrefab.InstantiateInactive(); prop.transform.SetParent(sector?.transform ?? go.transform); prop.transform.localPosition = go.transform.TransformPoint(point * height); var up = go.transform.InverseTransformPoint(prop.transform.position).normalized; @@ -131,7 +131,7 @@ namespace NewHorizons.Builder.Props prop.SetActive(true); } - GameObject.Destroy(prefab); + GameObject.Destroy(scatterPrefab); } } } From 2cabbc27b193e0fb0e13054bc146a415e6ea48a0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 14 Sep 2022 02:03:22 +0000 Subject: [PATCH 12/33] Updated Schemas --- NewHorizons/Schemas/body_schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Schemas/body_schema.json b/NewHorizons/Schemas/body_schema.json index 2d1984c0..a3d243d1 100644 --- a/NewHorizons/Schemas/body_schema.json +++ b/NewHorizons/Schemas/body_schema.json @@ -1399,7 +1399,7 @@ "type": "boolean", "description": "Should we try to prevent overlap between the scattered details? True by default. If it's affecting load times turn it off.", "default": true - }, + }, "keepLoaded": { "type": "boolean", "description": "Should this detail stay loaded even if you're outside the sector (good for very large props)" From d509e11379ad04c14417c059323764f079644ff5 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Sep 2022 23:03:59 -0400 Subject: [PATCH 13/33] Use CommonCameraUtility to fix projection pool remote cameras --- .../CommonCameraHandler.cs | 16 +++++++++++++ .../CommonCameraUtility/ICommonCameraAPI.cs | 13 ++++++++++ .../CameraPatches/NomaiRemoteCameraPatches.cs | 24 +++++++++++++++++++ NewHorizons/manifest.json | 2 +- 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs create mode 100644 NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs create mode 100644 NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs diff --git a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs new file mode 100644 index 00000000..2aab1526 --- /dev/null +++ b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs @@ -0,0 +1,16 @@ +using NewHorizons.OtherMods.MenuFramework; + +namespace NewHorizons.OtherMods.CommonCameraUtility +{ + public static class CommonCameraHandler + { + private static ICommonCameraAPI _cameraAPI; + + static CommonCameraHandler() + { + _cameraAPI = Main.Instance.ModHelper.Interaction.TryGetModApi("xen.CommonCameraUtility"); + } + + public static void RegisterCustomCamera(OWCamera camera) => _cameraAPI.RegisterCustomCamera(camera); + } +} diff --git a/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs new file mode 100644 index 00000000..bd49375b --- /dev/null +++ b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs @@ -0,0 +1,13 @@ +using UnityEngine; +using UnityEngine.Events; + +namespace NewHorizons.OtherMods.CommonCameraUtility +{ + public interface ICommonCameraAPI + { + void RegisterCustomCamera(OWCamera OWCamera); + (OWCamera, Camera) CreateCustomCamera(string name); + UnityEvent EquipTool(); + UnityEvent UnequipTool(); + } +} diff --git a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs new file mode 100644 index 00000000..29719c0e --- /dev/null +++ b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using NewHorizons.OtherMods.CommonCameraUtility; +using UnityEngine; + +namespace NewHorizons.Patches.CameraPatches +{ + [HarmonyPatch] + public static class NomaiRemoteCameraPatches + { + [HarmonyPostfix] + [HarmonyPatch(typeof(NomaiRemoteCamera), nameof(NomaiRemoteCamera.Awake))] + public static void NomaiRemoteCamera_Awake(NomaiRemoteCamera __instance) + { + // Ensures that if the player is visible from the remote camera they look normal + CommonCameraHandler.RegisterCustomCamera(__instance._camera); + + // These layers were left on because it doesnt come up in base game (Dreamworld is inactive, player is far away) + __instance._camera.mainCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("DreamSimulation")); + __instance._camera.mainCamera.cullingMask &= ~(1 < Date: Tue, 13 Sep 2022 23:04:11 -0400 Subject: [PATCH 14/33] Reorganize camera patches --- NewHorizons/Patches/{ => CameraPatches}/OWCameraPatch.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) rename NewHorizons/Patches/{ => CameraPatches}/OWCameraPatch.cs (93%) diff --git a/NewHorizons/Patches/OWCameraPatch.cs b/NewHorizons/Patches/CameraPatches/OWCameraPatch.cs similarity index 93% rename from NewHorizons/Patches/OWCameraPatch.cs rename to NewHorizons/Patches/CameraPatches/OWCameraPatch.cs index ccdafafc..db9251c1 100644 --- a/NewHorizons/Patches/OWCameraPatch.cs +++ b/NewHorizons/Patches/CameraPatches/OWCameraPatch.cs @@ -1,5 +1,6 @@ using HarmonyLib; -namespace NewHorizons.Patches + +namespace NewHorizons.Patches.CameraPatches { [HarmonyPatch] public static class OWCameraPatch From 0b2be0cfcce1a4c39e6c8339833d941f627d48c5 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Sep 2022 23:05:36 -0400 Subject: [PATCH 15/33] Revert "Reorganize camera patches" This reverts commit 461cdd6349b64932e8ffe2df87bc0bd7426bd5de. --- NewHorizons/Patches/{CameraPatches => }/OWCameraPatch.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename NewHorizons/Patches/{CameraPatches => }/OWCameraPatch.cs (93%) diff --git a/NewHorizons/Patches/CameraPatches/OWCameraPatch.cs b/NewHorizons/Patches/OWCameraPatch.cs similarity index 93% rename from NewHorizons/Patches/CameraPatches/OWCameraPatch.cs rename to NewHorizons/Patches/OWCameraPatch.cs index db9251c1..ccdafafc 100644 --- a/NewHorizons/Patches/CameraPatches/OWCameraPatch.cs +++ b/NewHorizons/Patches/OWCameraPatch.cs @@ -1,6 +1,5 @@ using HarmonyLib; - -namespace NewHorizons.Patches.CameraPatches +namespace NewHorizons.Patches { [HarmonyPatch] public static class OWCameraPatch From 829fedb6a3c02befe556271d9ada804fba15d9e5 Mon Sep 17 00:00:00 2001 From: Nick Date: Tue, 13 Sep 2022 23:05:41 -0400 Subject: [PATCH 16/33] Revert "Use CommonCameraUtility to fix projection pool remote cameras" This reverts commit d509e11379ad04c14417c059323764f079644ff5. --- .../CommonCameraHandler.cs | 16 ------------- .../CommonCameraUtility/ICommonCameraAPI.cs | 13 ---------- .../CameraPatches/NomaiRemoteCameraPatches.cs | 24 ------------------- NewHorizons/manifest.json | 2 +- 4 files changed, 1 insertion(+), 54 deletions(-) delete mode 100644 NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs delete mode 100644 NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs delete mode 100644 NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs diff --git a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs deleted file mode 100644 index 2aab1526..00000000 --- a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs +++ /dev/null @@ -1,16 +0,0 @@ -using NewHorizons.OtherMods.MenuFramework; - -namespace NewHorizons.OtherMods.CommonCameraUtility -{ - public static class CommonCameraHandler - { - private static ICommonCameraAPI _cameraAPI; - - static CommonCameraHandler() - { - _cameraAPI = Main.Instance.ModHelper.Interaction.TryGetModApi("xen.CommonCameraUtility"); - } - - public static void RegisterCustomCamera(OWCamera camera) => _cameraAPI.RegisterCustomCamera(camera); - } -} diff --git a/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs deleted file mode 100644 index bd49375b..00000000 --- a/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs +++ /dev/null @@ -1,13 +0,0 @@ -using UnityEngine; -using UnityEngine.Events; - -namespace NewHorizons.OtherMods.CommonCameraUtility -{ - public interface ICommonCameraAPI - { - void RegisterCustomCamera(OWCamera OWCamera); - (OWCamera, Camera) CreateCustomCamera(string name); - UnityEvent EquipTool(); - UnityEvent UnequipTool(); - } -} diff --git a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs deleted file mode 100644 index 29719c0e..00000000 --- a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs +++ /dev/null @@ -1,24 +0,0 @@ -using HarmonyLib; -using NewHorizons.OtherMods.CommonCameraUtility; -using UnityEngine; - -namespace NewHorizons.Patches.CameraPatches -{ - [HarmonyPatch] - public static class NomaiRemoteCameraPatches - { - [HarmonyPostfix] - [HarmonyPatch(typeof(NomaiRemoteCamera), nameof(NomaiRemoteCamera.Awake))] - public static void NomaiRemoteCamera_Awake(NomaiRemoteCamera __instance) - { - // Ensures that if the player is visible from the remote camera they look normal - CommonCameraHandler.RegisterCustomCamera(__instance._camera); - - // These layers were left on because it doesnt come up in base game (Dreamworld is inactive, player is far away) - __instance._camera.mainCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("DreamSimulation")); - __instance._camera.mainCamera.cullingMask &= ~(1 < Date: Tue, 13 Sep 2022 23:08:16 -0400 Subject: [PATCH 17/33] Revert revert revert revert --- .../CommonCameraHandler.cs | 16 +++++++++++++ .../CommonCameraUtility/ICommonCameraAPI.cs | 13 ++++++++++ .../CameraPatches/NomaiRemoteCameraPatches.cs | 24 +++++++++++++++++++ .../{ => CameraPatches}/OWCameraPatch.cs | 3 ++- NewHorizons/manifest.json | 2 +- 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs create mode 100644 NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs create mode 100644 NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs rename NewHorizons/Patches/{ => CameraPatches}/OWCameraPatch.cs (93%) diff --git a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs new file mode 100644 index 00000000..2aab1526 --- /dev/null +++ b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs @@ -0,0 +1,16 @@ +using NewHorizons.OtherMods.MenuFramework; + +namespace NewHorizons.OtherMods.CommonCameraUtility +{ + public static class CommonCameraHandler + { + private static ICommonCameraAPI _cameraAPI; + + static CommonCameraHandler() + { + _cameraAPI = Main.Instance.ModHelper.Interaction.TryGetModApi("xen.CommonCameraUtility"); + } + + public static void RegisterCustomCamera(OWCamera camera) => _cameraAPI.RegisterCustomCamera(camera); + } +} diff --git a/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs new file mode 100644 index 00000000..bd49375b --- /dev/null +++ b/NewHorizons/OtherMods/CommonCameraUtility/ICommonCameraAPI.cs @@ -0,0 +1,13 @@ +using UnityEngine; +using UnityEngine.Events; + +namespace NewHorizons.OtherMods.CommonCameraUtility +{ + public interface ICommonCameraAPI + { + void RegisterCustomCamera(OWCamera OWCamera); + (OWCamera, Camera) CreateCustomCamera(string name); + UnityEvent EquipTool(); + UnityEvent UnequipTool(); + } +} diff --git a/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs new file mode 100644 index 00000000..29719c0e --- /dev/null +++ b/NewHorizons/Patches/CameraPatches/NomaiRemoteCameraPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using NewHorizons.OtherMods.CommonCameraUtility; +using UnityEngine; + +namespace NewHorizons.Patches.CameraPatches +{ + [HarmonyPatch] + public static class NomaiRemoteCameraPatches + { + [HarmonyPostfix] + [HarmonyPatch(typeof(NomaiRemoteCamera), nameof(NomaiRemoteCamera.Awake))] + public static void NomaiRemoteCamera_Awake(NomaiRemoteCamera __instance) + { + // Ensures that if the player is visible from the remote camera they look normal + CommonCameraHandler.RegisterCustomCamera(__instance._camera); + + // These layers were left on because it doesnt come up in base game (Dreamworld is inactive, player is far away) + __instance._camera.mainCamera.cullingMask &= ~(1 << LayerMask.NameToLayer("DreamSimulation")); + __instance._camera.mainCamera.cullingMask &= ~(1 < Date: Tue, 13 Sep 2022 21:11:12 -0700 Subject: [PATCH 18/33] use da thing thankies rider --- NewHorizons/Builder/Props/DetailBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 74b19515..fb4ae2df 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -87,7 +87,7 @@ namespace NewHorizons.Builder.Props FixComponent(component, go, prefab.name); - if (DetailFixer.fixes.Keys.Any(x => x.IsAssignableFrom(component.GetType()))) + if (DetailFixer.fixes.Keys.Any(x => x.IsInstanceOfType(component))) { fixes.Add(component); } @@ -352,7 +352,7 @@ namespace NewHorizons.Builder.Props { if (component != null) { - var key = fixes.Keys.FirstOrDefault(x => x.IsAssignableFrom(component.GetType())); + var key = fixes.Keys.FirstOrDefault(x => x.IsInstanceOfType(component)); var fix = fixes[key]; fix(component); } From 5ff9f09684953187680a7e5ec71a2c85d3957c95 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 14 Sep 2022 16:34:10 -0700 Subject: [PATCH 19/33] revert da thingy --- NewHorizons/Builder/Props/DetailBuilder.cs | 104 ++++++--------------- 1 file changed, 28 insertions(+), 76 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index fb4ae2df..ae7a63f7 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Builder.General; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Handlers; @@ -6,10 +5,8 @@ using NewHorizons.Utility; using OWML.Common; using System; using System.Collections.Generic; -using System.ComponentModel; using System.Linq; using UnityEngine; -using Component = UnityEngine.Component; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.Builder.Props { @@ -74,9 +71,6 @@ namespace NewHorizons.Builder.Props var isTorch = prop.GetComponent() != null; - // Fix a bunch of stuff when done loading - var fixes = new List(); - foreach (var component in prop.GetComponentsInChildren(true)) { if (sector == null) @@ -86,16 +80,6 @@ namespace NewHorizons.Builder.Props else FixSectoredComponent(component, sector, isTorch); FixComponent(component, go, prefab.name); - - if (DetailFixer.fixes.Keys.Any(x => x.IsInstanceOfType(component))) - { - fixes.Add(component); - } - } - - if (fixes.Count > 0) - { - prop.AddComponent().SetFixes(fixes); } prop.transform.position = detail.position == null ? go.transform.position : go.transform.TransformPoint(detail.position); @@ -116,7 +100,6 @@ namespace NewHorizons.Builder.Props prop.transform.localScale = detail.scale != 0 ? Vector3.one * detail.scale : prefab.transform.localScale; - if (!detail.keepLoaded) GroupsBuilder.Make(prop, sector); prop.SetActive(true); if (prop == null) return null; @@ -294,75 +277,44 @@ namespace NewHorizons.Builder.Props torchItem.mindProjectorTrigger.enabled = true; torchItem.mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); } - } - /// - /// Performs fixes that have to be done after the system loads - /// Has to be done this way to ensure that scatter works - /// - private class DetailFixer : MonoBehaviour - { - public static Dictionary> fixes = new() + // Fix a bunch of stuff when done loading + Delay.RunWhen(() => Main.IsSystemReady, () => { - [typeof(AnglerfishAnimController)] = (x) => + try { - var angler = x as AnglerfishAnimController; - - Logger.LogVerbose("Enabling anglerfish animation"); - // Remove any reference to its angler - if (angler._anglerfishController) + if (component == null) return; + if (component is Animator animator) animator.enabled = true; + else if (component is Collider collider) collider.enabled = true; + else if (component is Renderer renderer) renderer.enabled = true; + else if (component is Shape shape) shape.enabled = true; + else if (component is SectorCullGroup sectorCullGroup) { - angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; - angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; - angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; - angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; + sectorCullGroup._inMapView = false; + sectorCullGroup._isFastForwarding = false; + sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); } - angler.enabled = true; - angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); - }, - [typeof(SectorCullGroup)] = (x) => - { - var sectorCullGroup = x as SectorCullGroup; - sectorCullGroup._inMapView = false; - sectorCullGroup._isFastForwarding = false; - sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); - }, - [typeof(Shape)] = (x) => (x as Shape).enabled = true, - [typeof(Renderer)] = (x) => (x as Renderer).enabled = true, - [typeof(Collider)] = (x) => (x as Collider).enabled = true, - [typeof(Animator)] = (x) => (x as Animator).enabled = true - }; - - // Have to be public to be copied by Instantiate - public Component[] componentsToFix; - - public void SetFixes(List fixes) - { - // Components must be in a list for unity to properly deep copy - componentsToFix = fixes.ToArray(); - } - - public void Start() - { - for (int i = 0; i < componentsToFix.Length; i++) - { - var component = componentsToFix[i]; - - try + // If it's not a moving anglerfish make sure the anim controller is regular + else if (component is AnglerfishAnimController angler && angler.GetComponentInParent() == null) { - if (component != null) + Logger.LogVerbose("Enabling anglerfish animation"); + // Remove any reference to its angler + if (angler._anglerfishController) { - var key = fixes.Keys.FirstOrDefault(x => x.IsInstanceOfType(component)); - var fix = fixes[key]; - fix(component); + angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; + angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; + angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; + angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; } - } - catch (Exception) - { - Logger.LogWarning($"Failed to fix component {component} on {gameObject.name}"); + angler.enabled = true; + angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); } } - } + catch (Exception e) + { + Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] for prop [{prefab}]:\n{e}"); + } + }); } } } \ No newline at end of file From 8ec41b58d592c2fe90dd4de34b1c44c5a1d9aa58 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 14 Sep 2022 16:59:48 -0700 Subject: [PATCH 20/33] remove the delay (things still work lol) --- NewHorizons/Builder/Props/DetailBuilder.cs | 62 ++++++++++------------ 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index ae7a63f7..209ca540 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -226,7 +226,7 @@ namespace NewHorizons.Builder.Props { // Fix other components // I forget why this is here - if (component is GhostIK || component is GhostEffects) + if (component is GhostIK or GhostEffects) { Component.DestroyImmediate(component); return; @@ -278,43 +278,35 @@ namespace NewHorizons.Builder.Props torchItem.mindSlideProjector._mindProjectorImageEffect = SearchUtilities.Find("Player_Body/PlayerCamera").GetComponent(); } - // Fix a bunch of stuff when done loading - Delay.RunWhen(() => Main.IsSystemReady, () => + if (component is Animator animator) animator.enabled = true; + if (component is Collider collider) collider.enabled = true; + if (component is Renderer renderer) renderer.enabled = true; + if (component is Shape shape) shape.enabled = true; + + // fixes sector cull group deactivating renderers on map view enter and fast foward + // TODO: does this actually worK? what? how? + if (component is SectorCullGroup sectorCullGroup) { - try + sectorCullGroup._inMapView = false; + sectorCullGroup._isFastForwarding = false; + sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); + } + + // If it's not a moving anglerfish make sure the anim controller is regular + if (component is AnglerfishAnimController angler2 && angler2.GetComponentInParent() == null) + { + Logger.LogVerbose("Enabling anglerfish animation"); + // Remove any reference to its angler + if (angler2._anglerfishController) { - if (component == null) return; - if (component is Animator animator) animator.enabled = true; - else if (component is Collider collider) collider.enabled = true; - else if (component is Renderer renderer) renderer.enabled = true; - else if (component is Shape shape) shape.enabled = true; - else if (component is SectorCullGroup sectorCullGroup) - { - sectorCullGroup._inMapView = false; - sectorCullGroup._isFastForwarding = false; - sectorCullGroup.SetVisible(sectorCullGroup.ShouldBeVisible(), true, false); - } - // If it's not a moving anglerfish make sure the anim controller is regular - else if (component is AnglerfishAnimController angler && angler.GetComponentInParent() == null) - { - Logger.LogVerbose("Enabling anglerfish animation"); - // Remove any reference to its angler - if (angler._anglerfishController) - { - angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; - angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; - angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; - angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; - } - angler.enabled = true; - angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); - } + angler2._anglerfishController.OnChangeAnglerState -= angler2.OnChangeAnglerState; + angler2._anglerfishController.OnAnglerTurn -= angler2.OnAnglerTurn; + angler2._anglerfishController.OnAnglerSuspended -= angler2.OnAnglerSuspended; + angler2._anglerfishController.OnAnglerUnsuspended -= angler2.OnAnglerUnsuspended; } - catch (Exception e) - { - Logger.LogWarning($"Exception when modifying component [{component.GetType().Name}] on [{planetGO.name}] for prop [{prefab}]:\n{e}"); - } - }); + angler2.enabled = true; + angler2.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); + } } } } \ No newline at end of file From 436cfa317520fce55e408472293bd982b83e3866 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 14 Sep 2022 17:04:53 -0700 Subject: [PATCH 21/33] remove unused parameter --- NewHorizons/Builder/Props/DetailBuilder.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 209ca540..0066a85d 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -79,7 +79,7 @@ namespace NewHorizons.Builder.Props } else FixSectoredComponent(component, sector, isTorch); - FixComponent(component, go, prefab.name); + FixComponent(component, go); } prop.transform.position = detail.position == null ? go.transform.position : go.transform.TransformPoint(detail.position); @@ -222,7 +222,7 @@ namespace NewHorizons.Builder.Props return false; } - private static void FixComponent(Component component, GameObject planetGO, string prefab) + private static void FixComponent(Component component, GameObject planetGO) { // Fix other components // I forget why this is here From cce97acddc326299881adfd4da8525e30125cbf1 Mon Sep 17 00:00:00 2001 From: JohnCorby Date: Wed, 14 Sep 2022 17:38:16 -0700 Subject: [PATCH 22/33] angler fixer yay --- NewHorizons/Builder/Props/DetailBuilder.cs | 36 ++++++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 0066a85d..016e5f61 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -284,7 +284,7 @@ namespace NewHorizons.Builder.Props if (component is Shape shape) shape.enabled = true; // fixes sector cull group deactivating renderers on map view enter and fast foward - // TODO: does this actually worK? what? how? + // TODO: does this actually work? what? how? if (component is SectorCullGroup sectorCullGroup) { sectorCullGroup._inMapView = false; @@ -293,19 +293,35 @@ namespace NewHorizons.Builder.Props } // If it's not a moving anglerfish make sure the anim controller is regular - if (component is AnglerfishAnimController angler2 && angler2.GetComponentInParent() == null) + if (component is AnglerfishAnimController && component.GetComponentInParent() == null) + component.gameObject.AddComponent(); + } + + /// + /// needs to happen later to remove the funny angler anim events yippee. + /// + /// cant do delay cuz it needs to work with scatter (which does copy detail thing). + /// + [RequireComponent(typeof(AnglerfishAnimController))] + private class AnglerAnimFixer : MonoBehaviour + { + private void Start() { - Logger.LogVerbose("Enabling anglerfish animation"); + var angler = GetComponent(); + + Logger.LogVerbose("Fixing anglerfish animation"); // Remove any reference to its angler - if (angler2._anglerfishController) + if (angler._anglerfishController) { - angler2._anglerfishController.OnChangeAnglerState -= angler2.OnChangeAnglerState; - angler2._anglerfishController.OnAnglerTurn -= angler2.OnAnglerTurn; - angler2._anglerfishController.OnAnglerSuspended -= angler2.OnAnglerSuspended; - angler2._anglerfishController.OnAnglerUnsuspended -= angler2.OnAnglerUnsuspended; + angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; + angler._anglerfishController.OnAnglerTurn -= angler.OnAnglerTurn; + angler._anglerfishController.OnAnglerSuspended -= angler.OnAnglerSuspended; + angler._anglerfishController.OnAnglerUnsuspended -= angler.OnAnglerUnsuspended; } - angler2.enabled = true; - angler2.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); + angler.enabled = true; + angler.OnChangeAnglerState(AnglerfishController.AnglerState.Lurking); + + Destroy(this); } } } From 2f49b61dd20ca840e7e8c09258ac85d8e9a7ffe6 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Sep 2022 20:48:55 -0400 Subject: [PATCH 23/33] Remove stupid usings wtf are these --- NewHorizons/OtherMods/MenuFramework/MenuHandler.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/NewHorizons/OtherMods/MenuFramework/MenuHandler.cs b/NewHorizons/OtherMods/MenuFramework/MenuHandler.cs index 45682279..bb88e7b4 100644 --- a/NewHorizons/OtherMods/MenuFramework/MenuHandler.cs +++ b/NewHorizons/OtherMods/MenuFramework/MenuHandler.cs @@ -4,9 +4,7 @@ using NewHorizons.Utility; using OWML.Common; using System.Collections.Generic; using System.Linq; -using System.Net.Mail; using UnityEngine; -using static UnityEngine.InputSystem.InputRemoting; using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.OtherMods.MenuFramework From d71b016c8a9d4726f2cf38b4d797b9bffb774252 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Sep 2022 20:51:07 -0400 Subject: [PATCH 24/33] Explained why the fixer is needed --- NewHorizons/Builder/Props/DetailBuilder.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 016e5f61..660956b6 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -298,9 +298,9 @@ namespace NewHorizons.Builder.Props } /// - /// needs to happen later to remove the funny angler anim events yippee. - /// - /// cant do delay cuz it needs to work with scatter (which does copy detail thing). + /// Has to happen after AnglerfishAnimController awake to remove the events it has set up. + /// Otherwise results in the anglerfish 1) having its animations controlled by an actual fish 2) randomly having different animations on solarsystem load + /// Can't do delay because it needs to work with scatter (copies a prefab made using MakeDetail). /// [RequireComponent(typeof(AnglerfishAnimController))] private class AnglerAnimFixer : MonoBehaviour @@ -310,7 +310,8 @@ namespace NewHorizons.Builder.Props var angler = GetComponent(); Logger.LogVerbose("Fixing anglerfish animation"); - // Remove any reference to its angler + + // Remove any event reference to its angler if (angler._anglerfishController) { angler._anglerfishController.OnChangeAnglerState -= angler.OnChangeAnglerState; From 27386e1730cb0bc20b4fd19142f01b8acbfa0143 Mon Sep 17 00:00:00 2001 From: Nick Date: Wed, 14 Sep 2022 21:08:28 -0400 Subject: [PATCH 25/33] Fix reload configs breaking NH translations --- NewHorizons/Main.cs | 13 ++++++++----- NewHorizons/Utility/DebugUtilities/DebugReload.cs | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index b86c8d65..678852bb 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -121,7 +121,7 @@ namespace NewHorizons _wasConfigured = true; } - public static void ResetConfigs(bool resetTranslation = true) + public void ResetConfigs(bool resetTranslation = true) { BodyDict.Clear(); SystemDict.Clear(); @@ -160,9 +160,13 @@ namespace NewHorizons } }; - if (!resetTranslation) return; - TranslationHandler.ClearTables(); - TextTranslation.Get().SetLanguage(TextTranslation.Get().GetLanguage()); + if (resetTranslation) + { + TranslationHandler.ClearTables(); + TextTranslation.Get().SetLanguage(TextTranslation.Get().GetLanguage()); + } + + LoadTranslations(Instance.ModHelper.Manifest.ModFolderPath + "Assets/", this); } public void Awake() @@ -212,7 +216,6 @@ namespace NewHorizons OnStarSystemLoaded.AddListener(RichPresenceHandler.OnStarSystemLoaded); OnChangeStarSystem.AddListener(RichPresenceHandler.OnChangeStarSystem); - LoadTranslations(ModHelper.Manifest.ModFolderPath + "Assets/", this); LoadAddonManifest("Assets/addon-manifest.json", this); } diff --git a/NewHorizons/Utility/DebugUtilities/DebugReload.cs b/NewHorizons/Utility/DebugUtilities/DebugReload.cs index b8a513c9..1bb6e639 100644 --- a/NewHorizons/Utility/DebugUtilities/DebugReload.cs +++ b/NewHorizons/Utility/DebugUtilities/DebugReload.cs @@ -31,7 +31,7 @@ namespace NewHorizons.Utility.DebugUtilities { Logger.Log("Begin reload of config files..."); - Main.ResetConfigs(); + Main.Instance.ResetConfigs(); try { From 235f62ffc7aa08bb78c79911a53af238e4c3dd42 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Wed, 14 Sep 2022 21:33:41 -0400 Subject: [PATCH 26/33] null check ig idk why a required mod wouldn't be downloaded --- .../CommonCameraUtility/CommonCameraHandler.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs index 2aab1526..e344a57f 100644 --- a/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs +++ b/NewHorizons/OtherMods/CommonCameraUtility/CommonCameraHandler.cs @@ -1,4 +1,5 @@ using NewHorizons.OtherMods.MenuFramework; +using Logger = NewHorizons.Utility.Logger; namespace NewHorizons.OtherMods.CommonCameraUtility { @@ -11,6 +12,16 @@ namespace NewHorizons.OtherMods.CommonCameraUtility _cameraAPI = Main.Instance.ModHelper.Interaction.TryGetModApi("xen.CommonCameraUtility"); } - public static void RegisterCustomCamera(OWCamera camera) => _cameraAPI.RegisterCustomCamera(camera); + public static void RegisterCustomCamera(OWCamera camera) + { + if (_cameraAPI != null) + { + _cameraAPI.RegisterCustomCamera(camera); + } + else + { + Logger.LogError("Tried to register custom camera but Common Camera Utility was missing."); + } + } } } From 13dfe1c535047e374ad5551032bddb5d702c3319 Mon Sep 17 00:00:00 2001 From: TerrificTrifid <99054745+TerrificTrifid@users.noreply.github.com> Date: Wed, 14 Sep 2022 23:10:05 -0500 Subject: [PATCH 27/33] Fix RemoveStarLight bugs --- .../Components/SizeControllers/StarEvolutionController.cs | 2 +- NewHorizons/Handlers/PlanetDestructionHandler.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 164c2a20..ced3222a 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -302,7 +302,7 @@ namespace NewHorizons.Components.SizeControllers private void DisableStar(bool start = false) { if (controller != null) StarLightController.RemoveStar(controller); - StarLightController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); + if (!isProxy) StarLightController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); if (_stellarRemnant != null) { diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index b92e7972..7f8fbf28 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -118,7 +118,7 @@ namespace NewHorizons.Handlers case AstroObject.Name.Sun: var starController = ao.gameObject.GetComponent(); StarLightController.RemoveStar(starController); - StarLightController.RemoveStarLight(ao.gameObject.FindChild("SunLight").GetComponent()); + StarLightController.RemoveStarLight(ao.gameObject.FindChild("Sector_SUN/Effects_SUN/SunLight").GetComponent()); GameObject.Destroy(starController); var audio = ao.GetComponentInChildren(); From 6dfe59e962602e7c096e190a70e4f7b0312822fc Mon Sep 17 00:00:00 2001 From: Will Corby Date: Wed, 14 Sep 2022 21:15:55 -0700 Subject: [PATCH 28/33] Revert "Disable starlights when out of range" --- NewHorizons/Builder/Body/StarBuilder.cs | 1 + .../StarEvolutionController.cs | 3 -- NewHorizons/Components/StarLightController.cs | 33 ++----------------- NewHorizons/Handlers/PlanetCreationHandler.cs | 4 --- .../Handlers/PlanetDestructionHandler.cs | 1 - 5 files changed, 3 insertions(+), 39 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 99a6ee9f..7e32c3d3 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -126,6 +126,7 @@ namespace NewHorizons.Builder.Body light.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); light.intensity *= starModule.solarLuminosity; light.range = starModule.lightRadius; + light.range *= Mathf.Sqrt(starModule.solarLuminosity); Color lightColour = light.color; if (starModule.lightTint != null) lightColour = starModule.lightTint.ToColor(); diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index ced3222a..ce904cca 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -287,8 +287,6 @@ namespace NewHorizons.Components.SizeControllers _stellarRemnant.SetActive(true); var remnantStarController = _stellarRemnant.GetComponentInChildren(); if (remnantStarController != null) StarLightController.AddStar(remnantStarController); - var remnantStarLight = _stellarRemnant.FindChild("SunLight"); - if (remnantStarLight != null) StarLightController.AddStarLight(remnantStarLight.GetComponent()); } if (Time.time > _supernovaStartTime + supernovaTime) @@ -302,7 +300,6 @@ namespace NewHorizons.Components.SizeControllers private void DisableStar(bool start = false) { if (controller != null) StarLightController.RemoveStar(controller); - if (!isProxy) StarLightController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); if (_stellarRemnant != null) { diff --git a/NewHorizons/Components/StarLightController.cs b/NewHorizons/Components/StarLightController.cs index a9e2b000..55a79074 100644 --- a/NewHorizons/Components/StarLightController.cs +++ b/NewHorizons/Components/StarLightController.cs @@ -14,7 +14,6 @@ namespace NewHorizons.Components public static StarLightController Instance { get; private set; } private List _stars = new List(); - private List _lights = new List(); private StarController _activeStar; private SunLightController _sunLightController; @@ -54,20 +53,6 @@ namespace NewHorizons.Components } } - public static void AddStarLight(Light light) - { - if (light == null) return; - - Instance._lights.Add(light); - } - - public static void RemoveStarLight(Light light) - { - if (light == null) return; - - if (Instance._lights.Contains(light)) Instance._lights.Remove(light); - } - public void Update() { if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) @@ -93,14 +78,13 @@ namespace NewHorizons.Components material.SetFloat(SunIntensity, intensity); } - // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv - var origin = Vector3.zero; - foreach (var star in _stars) { if (star == null) continue; if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; + // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv + var origin = Vector3.zero; if (PlayerState.InMapView()) { origin = Locator.GetActiveCamera().transform.position; @@ -112,19 +96,6 @@ namespace NewHorizons.Components break; } } - - if (PlayerState.InMapView()) - { - foreach (var light in _lights) light.enabled = true; - return; - } - - foreach (var light in _lights) - { - // Minimum 50km range so it's not badly noticeable for dim stars - if ((light.transform.position - origin).sqrMagnitude <= Mathf.Max(light.range * light.range, 2500000000)) light.enabled = true; - else light.enabled = false; - } } private void ChangeActiveStar(StarController star) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 3c7c2d1d..4e4bab9b 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -59,7 +59,6 @@ namespace NewHorizons.Handlers starLightGO.AddComponent(); StarLightController.AddStar(starController); - StarLightController.AddStarLight(starController.Light); starLightGO.SetActive(true); @@ -501,9 +500,6 @@ namespace NewHorizons.Handlers if (starController != null) StarLightController.AddStar(starController); - var starLight = star.FindChild("SunLight"); - if (starLight != null) StarLightController.AddStarLight(starLight.GetComponent()); - // If it has an evolution controller that means it will die -> we make a remnant (unless its a remnant) if (starEvolutionController != null && !body.Config.isStellarRemnant) { diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 7f8fbf28..4d60a271 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -118,7 +118,6 @@ namespace NewHorizons.Handlers case AstroObject.Name.Sun: var starController = ao.gameObject.GetComponent(); StarLightController.RemoveStar(starController); - StarLightController.RemoveStarLight(ao.gameObject.FindChild("Sector_SUN/Effects_SUN/SunLight").GetComponent()); GameObject.Destroy(starController); var audio = ao.GetComponentInChildren(); From 6d2dbf72d5c7e32ed7a2bee168bfa9db11485b94 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Sep 2022 00:25:07 -0400 Subject: [PATCH 29/33] Revert "Revert "Disable starlights when out of range" (#385)" This reverts commit a1b1bd9a4052a0ad212cf3570d79c6d37e197d08, reversing changes made to acb235d4788ed6d993a6b23f918e2ae94cce0493. --- NewHorizons/Builder/Body/StarBuilder.cs | 1 - .../StarEvolutionController.cs | 3 ++ NewHorizons/Components/StarLightController.cs | 33 +++++++++++++++++-- NewHorizons/Handlers/PlanetCreationHandler.cs | 4 +++ .../Handlers/PlanetDestructionHandler.cs | 1 + 5 files changed, 39 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 7e32c3d3..99a6ee9f 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -126,7 +126,6 @@ namespace NewHorizons.Builder.Body light.CopyPropertiesFrom(SearchUtilities.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent()); light.intensity *= starModule.solarLuminosity; light.range = starModule.lightRadius; - light.range *= Mathf.Sqrt(starModule.solarLuminosity); Color lightColour = light.color; if (starModule.lightTint != null) lightColour = starModule.lightTint.ToColor(); diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index ce904cca..ced3222a 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -287,6 +287,8 @@ namespace NewHorizons.Components.SizeControllers _stellarRemnant.SetActive(true); var remnantStarController = _stellarRemnant.GetComponentInChildren(); if (remnantStarController != null) StarLightController.AddStar(remnantStarController); + var remnantStarLight = _stellarRemnant.FindChild("SunLight"); + if (remnantStarLight != null) StarLightController.AddStarLight(remnantStarLight.GetComponent()); } if (Time.time > _supernovaStartTime + supernovaTime) @@ -300,6 +302,7 @@ namespace NewHorizons.Components.SizeControllers private void DisableStar(bool start = false) { if (controller != null) StarLightController.RemoveStar(controller); + if (!isProxy) StarLightController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); if (_stellarRemnant != null) { diff --git a/NewHorizons/Components/StarLightController.cs b/NewHorizons/Components/StarLightController.cs index 55a79074..a9e2b000 100644 --- a/NewHorizons/Components/StarLightController.cs +++ b/NewHorizons/Components/StarLightController.cs @@ -14,6 +14,7 @@ namespace NewHorizons.Components public static StarLightController Instance { get; private set; } private List _stars = new List(); + private List _lights = new List(); private StarController _activeStar; private SunLightController _sunLightController; @@ -53,6 +54,20 @@ namespace NewHorizons.Components } } + public static void AddStarLight(Light light) + { + if (light == null) return; + + Instance._lights.Add(light); + } + + public static void RemoveStarLight(Light light) + { + if (light == null) return; + + if (Instance._lights.Contains(light)) Instance._lights.Remove(light); + } + public void Update() { if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) @@ -78,13 +93,14 @@ namespace NewHorizons.Components material.SetFloat(SunIntensity, intensity); } + // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv + var origin = Vector3.zero; + foreach (var star in _stars) { if (star == null) continue; if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; - // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv - var origin = Vector3.zero; if (PlayerState.InMapView()) { origin = Locator.GetActiveCamera().transform.position; @@ -96,6 +112,19 @@ namespace NewHorizons.Components break; } } + + if (PlayerState.InMapView()) + { + foreach (var light in _lights) light.enabled = true; + return; + } + + foreach (var light in _lights) + { + // Minimum 50km range so it's not badly noticeable for dim stars + if ((light.transform.position - origin).sqrMagnitude <= Mathf.Max(light.range * light.range, 2500000000)) light.enabled = true; + else light.enabled = false; + } } private void ChangeActiveStar(StarController star) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 4e4bab9b..3c7c2d1d 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -59,6 +59,7 @@ namespace NewHorizons.Handlers starLightGO.AddComponent(); StarLightController.AddStar(starController); + StarLightController.AddStarLight(starController.Light); starLightGO.SetActive(true); @@ -500,6 +501,9 @@ namespace NewHorizons.Handlers if (starController != null) StarLightController.AddStar(starController); + var starLight = star.FindChild("SunLight"); + if (starLight != null) StarLightController.AddStarLight(starLight.GetComponent()); + // If it has an evolution controller that means it will die -> we make a remnant (unless its a remnant) if (starEvolutionController != null && !body.Config.isStellarRemnant) { diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 4d60a271..7f8fbf28 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -118,6 +118,7 @@ namespace NewHorizons.Handlers case AstroObject.Name.Sun: var starController = ao.gameObject.GetComponent(); StarLightController.RemoveStar(starController); + StarLightController.RemoveStarLight(ao.gameObject.FindChild("Sector_SUN/Effects_SUN/SunLight").GetComponent()); GameObject.Destroy(starController); var audio = ao.GetComponentInChildren(); From 5a5ea46b05755a6debc7a7386c5b6459a7d0b082 Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Sep 2022 00:41:05 -0400 Subject: [PATCH 30/33] Categorized some stuff in components and fixed Trifids star thing maybe --- NewHorizons/Builder/Body/RingBuilder.cs | 1 + .../Builder/Body/SingularityBuilder.cs | 2 +- NewHorizons/Builder/Body/StarBuilder.cs | 2 +- NewHorizons/Builder/Body/WaterBuilder.cs | 2 +- NewHorizons/Builder/Props/QuantumBuilder.cs | 2 +- NewHorizons/Builder/Props/RaftBuilder.cs | 2 +- NewHorizons/Builder/ShipLog/MapModeBuilder.cs | 3 +- .../Volumes/NotificationVolumeBuilder.cs | 3 +- .../Builder/Volumes/VolumesBuildManager.cs | 4 +- .../{ => Fixers}/MapSatelliteOrbitFix.cs | 2 +- .../NHMultiStateQuantumObject.cs | 168 +++++++++--------- .../Components/{ => Quantum}/QuantumPlanet.cs | 6 +- .../Components/RingOpacityController.cs | 1 + .../Components/{ => ShipLog}/ShipLogDetail.cs | 6 +- .../{ => ShipLog}/ShipLogStarChartMode.cs | 16 +- .../StarEvolutionController.cs | 9 +- .../Components/{ => Stars}/StarController.cs | 4 +- .../{ => Stars}/StarDestructionVolume.cs | 2 +- .../Components/{ => Stars}/StarFluidVolume.cs | 2 +- .../{ => Stars}/StarLightController.cs | 131 ++++++++------ .../{ => Stars}/StarSurfaceAudioController.cs | 4 +- .../{ => Stars}/StellarDeathController.cs | 4 +- .../Components/{ => Volumes}/BaseVolume.cs | 2 +- .../BlackHoleDestructionVolume.cs | 4 +- .../{ => Volumes}/ChangeStarSystemVolume.cs | 2 +- .../{ => Volumes}/InterferenceVolume.cs | 2 +- .../{ => Volumes}/MapRestrictionVolume.cs | 2 +- .../Components/{ => Volumes}/NHFluidVolume.cs | 4 +- .../{ => Volumes}/NHInnerFogWarpVolume.cs | 2 +- .../{ => Volumes}/NotificationVolume.cs | 4 +- .../{ => Volumes}/RingFluidVolume.cs | 4 +- NewHorizons/Handlers/InterferenceHandler.cs | 2 +- NewHorizons/Handlers/PlanetCreationHandler.cs | 13 +- .../Handlers/PlanetDestructionHandler.cs | 6 +- NewHorizons/Handlers/StarChartHandler.cs | 2 +- .../Handlers/VesselCoordinatePromptHandler.cs | 2 +- NewHorizons/Main.cs | 1 + .../OWRichPresence/RichPresenceHandler.cs | 2 +- .../Patches/DestructionVolumePatches.cs | 2 +- NewHorizons/Patches/RaftPatches.cs | 2 +- NewHorizons/Patches/ShipLogPatches.cs | 3 +- 41 files changed, 233 insertions(+), 204 deletions(-) rename NewHorizons/Components/{ => Fixers}/MapSatelliteOrbitFix.cs (94%) rename NewHorizons/Components/{ => Quantum}/NHMultiStateQuantumObject.cs (54%) rename NewHorizons/Components/{ => Quantum}/QuantumPlanet.cs (98%) rename NewHorizons/Components/{ => ShipLog}/ShipLogDetail.cs (92%) rename NewHorizons/Components/{ => ShipLog}/ShipLogStarChartMode.cs (95%) rename NewHorizons/Components/{ => Stars}/StarController.cs (94%) rename NewHorizons/Components/{ => Stars}/StarDestructionVolume.cs (98%) rename NewHorizons/Components/{ => Stars}/StarFluidVolume.cs (96%) rename NewHorizons/Components/{ => Stars}/StarLightController.cs (55%) rename NewHorizons/Components/{ => Stars}/StarSurfaceAudioController.cs (88%) rename NewHorizons/Components/{ => Stars}/StellarDeathController.cs (96%) rename NewHorizons/Components/{ => Volumes}/BaseVolume.cs (95%) rename NewHorizons/Components/{ => Volumes}/BlackHoleDestructionVolume.cs (84%) rename NewHorizons/Components/{ => Volumes}/ChangeStarSystemVolume.cs (94%) rename NewHorizons/Components/{ => Volumes}/InterferenceVolume.cs (97%) rename NewHorizons/Components/{ => Volumes}/MapRestrictionVolume.cs (94%) rename NewHorizons/Components/{ => Volumes}/NHFluidVolume.cs (86%) rename NewHorizons/Components/{ => Volumes}/NHInnerFogWarpVolume.cs (83%) rename NewHorizons/Components/{ => Volumes}/NotificationVolume.cs (97%) rename NewHorizons/Components/{ => Volumes}/RingFluidVolume.cs (95%) diff --git a/NewHorizons/Builder/Body/RingBuilder.cs b/NewHorizons/Builder/Body/RingBuilder.cs index a0918a56..40d5953f 100644 --- a/NewHorizons/Builder/Body/RingBuilder.cs +++ b/NewHorizons/Builder/Body/RingBuilder.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using NewHorizons.External.Modules; using UnityEngine; using Logger = NewHorizons.Utility.Logger; +using NewHorizons.Components.Volumes; namespace NewHorizons.Builder.Body { diff --git a/NewHorizons/Builder/Body/SingularityBuilder.cs b/NewHorizons/Builder/Body/SingularityBuilder.cs index 4b9d4cdf..c9cd4d4d 100644 --- a/NewHorizons/Builder/Body/SingularityBuilder.cs +++ b/NewHorizons/Builder/Body/SingularityBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Components; using NewHorizons.External.Configs; using NewHorizons.Utility; using System; @@ -10,6 +9,7 @@ using System.Linq; using NewHorizons.Components.SizeControllers; using System.Drawing; using Color = UnityEngine.Color; +using NewHorizons.Components.Volumes; namespace NewHorizons.Builder.Body { diff --git a/NewHorizons/Builder/Body/StarBuilder.cs b/NewHorizons/Builder/Body/StarBuilder.cs index 99a6ee9f..eb9cac25 100644 --- a/NewHorizons/Builder/Body/StarBuilder.cs +++ b/NewHorizons/Builder/Body/StarBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Components; using NewHorizons.Components.SizeControllers; using NewHorizons.Utility; using OWML.Utils; @@ -9,6 +8,7 @@ using OWML.ModHelper; using OWML.Common; using UnityEngine.InputSystem.XR; using System.Linq; +using NewHorizons.Components.Stars; namespace NewHorizons.Builder.Body { diff --git a/NewHorizons/Builder/Body/WaterBuilder.cs b/NewHorizons/Builder/Body/WaterBuilder.cs index 5cbc5d70..a05dd63e 100644 --- a/NewHorizons/Builder/Body/WaterBuilder.cs +++ b/NewHorizons/Builder/Body/WaterBuilder.cs @@ -1,9 +1,9 @@ -using NewHorizons.Components; using NewHorizons.Components.SizeControllers; using NewHorizons.Utility; using UnityEngine; using NewHorizons.External.Modules.VariableSize; using Tessellation; +using NewHorizons.Components.Volumes; namespace NewHorizons.Builder.Body { diff --git a/NewHorizons/Builder/Props/QuantumBuilder.cs b/NewHorizons/Builder/Props/QuantumBuilder.cs index 16484b8f..3dd81c3b 100644 --- a/NewHorizons/Builder/Props/QuantumBuilder.cs +++ b/NewHorizons/Builder/Props/QuantumBuilder.cs @@ -1,5 +1,5 @@ using HarmonyLib; -using NewHorizons.Components; +using NewHorizons.Components.Quantum; using NewHorizons.External.Configs; using NewHorizons.External.Modules; using NewHorizons.Utility; diff --git a/NewHorizons/Builder/Props/RaftBuilder.cs b/NewHorizons/Builder/Props/RaftBuilder.cs index 6ad6277f..2e8c6a15 100644 --- a/NewHorizons/Builder/Props/RaftBuilder.cs +++ b/NewHorizons/Builder/Props/RaftBuilder.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.Volumes; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; diff --git a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs index 12e55581..0eaf91aa 100644 --- a/NewHorizons/Builder/ShipLog/MapModeBuilder.cs +++ b/NewHorizons/Builder/ShipLog/MapModeBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -9,6 +8,8 @@ using NewHorizons.External.Modules.VariableSize; using UnityEngine; using UnityEngine.UI; using Logger = NewHorizons.Utility.Logger; +using NewHorizons.Components.ShipLog; + namespace NewHorizons.Builder.ShipLog { public static class MapModeBuilder diff --git a/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs b/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs index 13386e79..dab95143 100644 --- a/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs +++ b/NewHorizons/Builder/Volumes/NotificationVolumeBuilder.cs @@ -1,4 +1,3 @@ -using NewHorizons.Components; using NewHorizons.External.Modules; using NewHorizons.Utility; using OWML.Common; @@ -9,7 +8,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; using Logger = NewHorizons.Utility.Logger; -using NHNotificationVolume = NewHorizons.Components.NotificationVolume; +using NHNotificationVolume = NewHorizons.Components.Volumes.NotificationVolume; namespace NewHorizons.Builder.Volumes { diff --git a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs index 9e9a9c36..9b13db4f 100644 --- a/NewHorizons/Builder/Volumes/VolumesBuildManager.cs +++ b/NewHorizons/Builder/Volumes/VolumesBuildManager.cs @@ -1,7 +1,7 @@ using NewHorizons.Builder.Body; using NewHorizons.Builder.ShipLog; using NewHorizons.Builder.Volumes; -using NewHorizons.Components; +using NewHorizons.Components.Volumes; using NewHorizons.External.Configs; using OWML.Common; using System; @@ -61,7 +61,7 @@ namespace NewHorizons.Builder.Volumes { foreach (var interferenceVolume in config.Volumes.interferenceVolumes) { - VolumeBuilder.Make(go, sector, interferenceVolume); + VolumeBuilder.Make(go, sector, interferenceVolume); } } if (config.Volumes.reverbVolumes != null) diff --git a/NewHorizons/Components/MapSatelliteOrbitFix.cs b/NewHorizons/Components/Fixers/MapSatelliteOrbitFix.cs similarity index 94% rename from NewHorizons/Components/MapSatelliteOrbitFix.cs rename to NewHorizons/Components/Fixers/MapSatelliteOrbitFix.cs index 1e8e0778..4b1a9b30 100644 --- a/NewHorizons/Components/MapSatelliteOrbitFix.cs +++ b/NewHorizons/Components/Fixers/MapSatelliteOrbitFix.cs @@ -1,7 +1,7 @@ using NewHorizons.Builder.General; using NewHorizons.External.Configs; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Fixers { public class MapSatelliteOrbitFix : MonoBehaviour { diff --git a/NewHorizons/Components/NHMultiStateQuantumObject.cs b/NewHorizons/Components/Quantum/NHMultiStateQuantumObject.cs similarity index 54% rename from NewHorizons/Components/NHMultiStateQuantumObject.cs rename to NewHorizons/Components/Quantum/NHMultiStateQuantumObject.cs index 6c73cef5..4abd57b1 100644 --- a/NewHorizons/Components/NHMultiStateQuantumObject.cs +++ b/NewHorizons/Components/Quantum/NHMultiStateQuantumObject.cs @@ -7,60 +7,60 @@ using UnityEngine; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Components +namespace NewHorizons.Components.Quantum { public class NHMultiStateQuantumObject : MultiStateQuantumObject { - - public override bool ChangeQuantumState(bool skipInstantVisibilityCheck) - { - for (int i = 0; i < _prerequisiteObjects.Length; i++) - { - if (!_prerequisiteObjects[i].HasCollapsed()) - { - return false; - } - } - int stateIndex = _stateIndex; - if (_stateIndex == -1 && _initialState != -1) - { - _stateIndex = _initialState; - } - else if (_sequential) - { - _stateIndex = (_reverse ? (_stateIndex - 1) : (_stateIndex + 1)); - if (_loop) - { - if (_stateIndex < 0) - { - _stateIndex = _states.Length - 1; - } - else if (_stateIndex > _states.Length - 1) - { - _stateIndex = 0; - } - } - else - { - _stateIndex = Mathf.Clamp(_stateIndex, 0, _states.Length - 1); - } - } - else - { + + public override bool ChangeQuantumState(bool skipInstantVisibilityCheck) + { + for (int i = 0; i < _prerequisiteObjects.Length; i++) + { + if (!_prerequisiteObjects[i].HasCollapsed()) + { + return false; + } + } + int stateIndex = _stateIndex; + if (_stateIndex == -1 && _initialState != -1) + { + _stateIndex = _initialState; + } + else if (_sequential) + { + _stateIndex = _reverse ? _stateIndex - 1 : _stateIndex + 1; + if (_loop) + { + if (_stateIndex < 0) + { + _stateIndex = _states.Length - 1; + } + else if (_stateIndex > _states.Length - 1) + { + _stateIndex = 0; + } + } + else + { + _stateIndex = Mathf.Clamp(_stateIndex, 0, _states.Length - 1); + } + } + else + { // TODO: perform this roll for number of states, each time adding the selected state to the end of a list and removing it from the source list // this gets us a randomly ordered list that respects states' probability // then we can sequentially attempt collapsing to them, checking at each state whether the new state is invalid due to the player being able to see it, according to this: // // if (!((!IsPlayerEntangled()) ? (CheckIllumination() ? CheckVisibilityInstantly() : CheckPointInside(Locator.GetPlayerCamera().transform.position)) : CheckIllumination())) - // { - // return true; // this is a valid state - // } + // { + // return true; // this is a valid state + // } // List indices = new List(); for (var i = 0; i < _states.Length; i++) if (i != stateIndex) indices.Add(i); - + var previousIndex = stateIndex; do @@ -69,31 +69,31 @@ namespace NewHorizons.Components _stateIndex = RollState(stateIndex, indices); if (previousIndex >= 0 && previousIndex < _states.Length) _states[previousIndex].SetVisible(visible: false); _states[_stateIndex].SetVisible(visible: true); - + Logger.LogVerbose($"MultiStateQuantumObject - Trying to change state {_stateIndex}"); indices.Remove(_stateIndex); } while (!CurrentStateIsValid() && indices.Count > 0); - } + } var stateIndexIsValid = stateIndex >= 0 && stateIndex < _states.Length; - if (stateIndexIsValid) _states[stateIndex].SetVisible(visible: false); + if (stateIndexIsValid) _states[stateIndex].SetVisible(visible: false); - _states[_stateIndex].SetVisible(visible: true); + _states[_stateIndex].SetVisible(visible: true); if (!CurrentStateIsValid() && stateIndexIsValid) { - _states[_stateIndex].SetVisible(visible: false); - _states[stateIndex] .SetVisible(visible: true); - _stateIndex = stateIndex; + _states[_stateIndex].SetVisible(visible: false); + _states[stateIndex].SetVisible(visible: true); + _stateIndex = stateIndex; return false; } - if (_sequential && !_loop && _stateIndex == _states.Length - 1) - { - SetActivation(active: false); - } - return true; - } + if (_sequential && !_loop && _stateIndex == _states.Length - 1) + { + SetActivation(active: false); + } + return true; + } public bool CurrentStateIsValid() { @@ -102,20 +102,20 @@ namespace NewHorizons.Components var visibility = CheckVisibilityInstantly(); var playerInside = CheckPointInside(Locator.GetPlayerCamera().transform.position); - var isVisible = + var isVisible = isPlayerEntangled ? illumination - : ( - illumination + : + illumination ? visibility : playerInside - ); + ; return !isVisible; } public int RollState(int excludeIndex, List indices) - { + { var stateIndex = excludeIndex; // this function constructs a sort of segmented range: @@ -132,32 +132,32 @@ namespace NewHorizons.Components // // the second for looop uses num3 and num4 to figure out which segment num2 landed in - int num = 0; - foreach (int j in indices) - { - if (j != stateIndex) - { - _probabilities[j] = _states[j].GetProbability(); - num += _probabilities[j]; - } - } - int num2 = UnityEngine.Random.Range(0, num); - int num3 = 0; - int num4 = 0; - foreach (int k in indices) - { - if (k != stateIndex) - { - num3 = num4; - num4 += _probabilities[k]; - if (_probabilities[k] > 0 && num2 >= num3 && num2 < num4) - { - return k; - } - } - } + int num = 0; + foreach (int j in indices) + { + if (j != stateIndex) + { + _probabilities[j] = _states[j].GetProbability(); + num += _probabilities[j]; + } + } + int num2 = UnityEngine.Random.Range(0, num); + int num3 = 0; + int num4 = 0; + foreach (int k in indices) + { + if (k != stateIndex) + { + num3 = num4; + num4 += _probabilities[k]; + if (_probabilities[k] > 0 && num2 >= num3 && num2 < num4) + { + return k; + } + } + } - return indices[indices.Count-1]; + return indices[indices.Count - 1]; } } } diff --git a/NewHorizons/Components/QuantumPlanet.cs b/NewHorizons/Components/Quantum/QuantumPlanet.cs similarity index 98% rename from NewHorizons/Components/QuantumPlanet.cs rename to NewHorizons/Components/Quantum/QuantumPlanet.cs index 2b853b76..568a364b 100644 --- a/NewHorizons/Components/QuantumPlanet.cs +++ b/NewHorizons/Components/Quantum/QuantumPlanet.cs @@ -9,7 +9,7 @@ using System.Linq; using UnityEngine; using Logger = NewHorizons.Utility.Logger; using Random = UnityEngine.Random; -namespace NewHorizons.Components +namespace NewHorizons.Components.Quantum { public class QuantumPlanet : QuantumObject { @@ -162,9 +162,9 @@ namespace NewHorizons.Components private void OnPlayerBlink() { - if (base.IsVisible()) + if (IsVisible()) { - base.Collapse(true); + Collapse(true); } } diff --git a/NewHorizons/Components/RingOpacityController.cs b/NewHorizons/Components/RingOpacityController.cs index fde75452..df707a33 100644 --- a/NewHorizons/Components/RingOpacityController.cs +++ b/NewHorizons/Components/RingOpacityController.cs @@ -1,3 +1,4 @@ +using NewHorizons.Components.Volumes; using NewHorizons.External.Modules.VariableSize; using NewHorizons.Utility; using UnityEngine; diff --git a/NewHorizons/Components/ShipLogDetail.cs b/NewHorizons/Components/ShipLog/ShipLogDetail.cs similarity index 92% rename from NewHorizons/Components/ShipLogDetail.cs rename to NewHorizons/Components/ShipLog/ShipLogDetail.cs index a2ce809d..3852ff88 100644 --- a/NewHorizons/Components/ShipLogDetail.cs +++ b/NewHorizons/Components/ShipLog/ShipLogDetail.cs @@ -1,8 +1,8 @@ -using NewHorizons.External.Modules; +using NewHorizons.External.Modules; using UnityEngine; using UnityEngine.UI; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Components +namespace NewHorizons.Components.ShipLog { public class ShipLogDetail : MonoBehaviour { @@ -51,7 +51,7 @@ namespace NewHorizons.Components private void SetGreyScale(bool greyScale) { - _revealedImage.material = (greyScale ? _greyScaleMaterial : null); + _revealedImage.material = greyScale ? _greyScaleMaterial : null; } } } \ No newline at end of file diff --git a/NewHorizons/Components/ShipLogStarChartMode.cs b/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs similarity index 95% rename from NewHorizons/Components/ShipLogStarChartMode.cs rename to NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs index a5d9dad0..a7b972ed 100644 --- a/NewHorizons/Components/ShipLogStarChartMode.cs +++ b/NewHorizons/Components/ShipLog/ShipLogStarChartMode.cs @@ -6,7 +6,7 @@ using System.Linq; using UnityEngine; using UnityEngine.UI; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Components +namespace NewHorizons.Components.ShipLog { public class ShipLogStarChartMode : ShipLogMode { @@ -41,7 +41,7 @@ namespace NewHorizons.Components public override void Initialize(ScreenPromptList centerPromptList, ScreenPromptList upperRightPromptList, OWAudioSource oneShotSource) { - root = base.transform.Find("ScaleRoot/PanRoot"); + root = transform.Find("ScaleRoot/PanRoot"); _oneShotSource = oneShotSource; _centerPromptList = centerPromptList; @@ -101,11 +101,11 @@ namespace NewHorizons.Components if (_cardTemplate == null) { var panRoot = SearchUtilities.Find("Ship_Body/Module_Cabin/Systems_Cabin/ShipLogPivot/ShipLog/ShipLogPivot/ShipLogCanvas/DetectiveMode/ScaleRoot/PanRoot"); - _cardTemplate = GameObject.Instantiate(panRoot.GetComponentInChildren().gameObject); + _cardTemplate = Instantiate(panRoot.GetComponentInChildren().gameObject); _cardTemplate.SetActive(false); } - var newCard = GameObject.Instantiate(_cardTemplate, parent); + var newCard = Instantiate(_cardTemplate, parent); var textComponent = newCard.transform.Find("EntryCardRoot/NameBackground/Name").GetComponent(); var name = UniqueIDToName(uniqueID); @@ -164,7 +164,7 @@ namespace NewHorizons.Components public override void EnterMode(string entryID = "", List revealQueue = null) { - base.gameObject.SetActive(true); + gameObject.SetActive(true); Locator.GetPromptManager().AddScreenPrompt(_detectiveModePrompt, _upperRightPromptList, TextAnchor.MiddleRight, -1, true); Locator.GetPromptManager().AddScreenPrompt(_targetSystemPrompt, _centerPromptList, TextAnchor.MiddleCenter, -1, true); @@ -172,7 +172,7 @@ namespace NewHorizons.Components public override void ExitMode() { - base.gameObject.SetActive(false); + gameObject.SetActive(false); Locator.GetPromptManager().RemoveScreenPrompt(_detectiveModePrompt); Locator.GetPromptManager().RemoveScreenPrompt(_targetSystemPrompt); @@ -223,7 +223,7 @@ namespace NewHorizons.Components if (oldIndex != _cardIndex) { - _oneShotSource.PlayOneShot(global::AudioType.ShipLogMoveBetweenPlanets, 1f); + _oneShotSource.PlayOneShot(AudioType.ShipLogMoveBetweenPlanets, 1f); _startPanTime = Time.unscaledTime; _startPanPos = _panRootPos; _panDuration = 0.25f; @@ -297,7 +297,7 @@ namespace NewHorizons.Components { if (_warpNotificationData != null) NotificationManager.SharedInstance.UnpinNotification(_warpNotificationData); if (_target == null) return; - if (playSound) _oneShotSource.PlayOneShot(global::AudioType.ShipLogMarkLocation, 1f); + if (playSound) _oneShotSource.PlayOneShot(AudioType.ShipLogMarkLocation, 1f); _target.SetMarkedOnHUD(false); _target = null; } diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index ced3222a..4e27972b 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -1,5 +1,6 @@ using NewHorizons.Builder.Body; using NewHorizons.Components.Orbital; +using NewHorizons.Components.Stars; using NewHorizons.External.Modules.VariableSize; using NewHorizons.Handlers; using NewHorizons.Utility; @@ -286,9 +287,9 @@ namespace NewHorizons.Components.SizeControllers { _stellarRemnant.SetActive(true); var remnantStarController = _stellarRemnant.GetComponentInChildren(); - if (remnantStarController != null) StarLightController.AddStar(remnantStarController); + if (remnantStarController != null) SunLightEffectsController.AddStar(remnantStarController); var remnantStarLight = _stellarRemnant.FindChild("SunLight"); - if (remnantStarLight != null) StarLightController.AddStarLight(remnantStarLight.GetComponent()); + if (remnantStarLight != null) SunLightEffectsController.AddStarLight(remnantStarLight.GetComponent()); } if (Time.time > _supernovaStartTime + supernovaTime) @@ -301,8 +302,8 @@ namespace NewHorizons.Components.SizeControllers private void DisableStar(bool start = false) { - if (controller != null) StarLightController.RemoveStar(controller); - if (!isProxy) StarLightController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); + if (controller != null) SunLightEffectsController.RemoveStar(controller); + if (!isProxy) SunLightEffectsController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); if (_stellarRemnant != null) { diff --git a/NewHorizons/Components/StarController.cs b/NewHorizons/Components/Stars/StarController.cs similarity index 94% rename from NewHorizons/Components/StarController.cs rename to NewHorizons/Components/Stars/StarController.cs index 8f69f085..374d4437 100644 --- a/NewHorizons/Components/StarController.cs +++ b/NewHorizons/Components/Stars/StarController.cs @@ -1,5 +1,5 @@ -using UnityEngine; -namespace NewHorizons.Components +using UnityEngine; +namespace NewHorizons.Components.Stars { public class StarController : MonoBehaviour { diff --git a/NewHorizons/Components/StarDestructionVolume.cs b/NewHorizons/Components/Stars/StarDestructionVolume.cs similarity index 98% rename from NewHorizons/Components/StarDestructionVolume.cs rename to NewHorizons/Components/Stars/StarDestructionVolume.cs index e0068d24..5354821a 100644 --- a/NewHorizons/Components/StarDestructionVolume.cs +++ b/NewHorizons/Components/Stars/StarDestructionVolume.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { public class StarDestructionVolume : DestructionVolume { diff --git a/NewHorizons/Components/StarFluidVolume.cs b/NewHorizons/Components/Stars/StarFluidVolume.cs similarity index 96% rename from NewHorizons/Components/StarFluidVolume.cs rename to NewHorizons/Components/Stars/StarFluidVolume.cs index 150d39f4..bd91f025 100644 --- a/NewHorizons/Components/StarFluidVolume.cs +++ b/NewHorizons/Components/Stars/StarFluidVolume.cs @@ -1,6 +1,6 @@ using NewHorizons.Components.SizeControllers; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { public class StarFluidVolume : SimpleFluidVolume { diff --git a/NewHorizons/Components/StarLightController.cs b/NewHorizons/Components/Stars/StarLightController.cs similarity index 55% rename from NewHorizons/Components/StarLightController.cs rename to NewHorizons/Components/Stars/StarLightController.cs index a9e2b000..c3c7b944 100644 --- a/NewHorizons/Components/StarLightController.cs +++ b/NewHorizons/Components/Stars/StarLightController.cs @@ -2,29 +2,31 @@ using NewHorizons.Builder.Atmosphere; using System.Collections.Generic; using UnityEngine; using Logger = NewHorizons.Utility.Logger; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { [RequireComponent(typeof(SunLightController))] [RequireComponent(typeof(SunLightParamUpdater))] - public class StarLightController : MonoBehaviour + public class SunLightEffectsController : MonoBehaviour { private static readonly int SunIntensity = Shader.PropertyToID("_SunIntensity"); private static readonly float hearthSunDistanceSqr = 8593 * 8593; - public static StarLightController Instance { get; private set; } + public static SunLightEffectsController Instance { get; private set; } + + private readonly List _stars = new(); + private readonly List _lights = new(); - private List _stars = new List(); - private List _lights = new List(); private StarController _activeStar; - private SunLightController _sunLightController; private SunLightParamUpdater _sunLightParamUpdater; public void Awake() { Instance = this; + _sunLightController = GetComponent(); _sunLightController.enabled = true; + _sunLightParamUpdater = GetComponent(); _sunLightParamUpdater._sunLightController = _sunLightController; } @@ -70,60 +72,81 @@ namespace NewHorizons.Components public void Update() { - if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) - { - if (_stars.Contains(_activeStar)) _stars.Remove(_activeStar); - if (_stars.Count > 0) ChangeActiveStar(_stars[0]); - else gameObject.SetActive(false); - - foreach (var (_, material) in AtmosphereBuilder.Skys) - { - material.SetFloat(SunIntensity, 0); - } - - return; - } - - // Update atmo shaders - foreach (var (planet, material) in AtmosphereBuilder.Skys) - { - var sqrDist = (planet.transform.position - _activeStar.transform.position).sqrMagnitude; - var intensity = Mathf.Min(_activeStar.Intensity / (sqrDist / hearthSunDistanceSqr), 1f); - - material.SetFloat(SunIntensity, intensity); - } - // Player is always at 0,0,0 more or less so if they arent using the map camera then wtv var origin = Vector3.zero; - foreach (var star in _stars) - { - if (star == null) continue; - if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; - - if (PlayerState.InMapView()) - { - origin = Locator.GetActiveCamera().transform.position; - } - - if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStar.Intensity * (_activeStar.transform.position - origin).sqrMagnitude) - { - ChangeActiveStar(star); - break; - } - } - if (PlayerState.InMapView()) { - foreach (var light in _lights) light.enabled = true; - return; + origin = Locator.GetActiveCamera().transform.position; + + // Keep all star lights on in map + foreach (var light in _lights) + { + light.enabled = true; + } + } + else + { + // Outside map, only show lights within 50km range or light.range + // For some reason outside of the actual range of the lights they still show reflection effects on water and glass + foreach (var light in _lights) + { + // Minimum 50km range so it's not badly noticeable for dim stars + if ((light.transform.position - origin).sqrMagnitude <= Mathf.Max(light.range * light.range, 2500000000)) + { + light.enabled = true; + } + else + { + light.enabled = false; + } + } } - foreach (var light in _lights) + if (_stars.Count > 0) { - // Minimum 50km range so it's not badly noticeable for dim stars - if ((light.transform.position - origin).sqrMagnitude <= Mathf.Max(light.range * light.range, 2500000000)) light.enabled = true; - else light.enabled = false; + if (_activeStar == null || !_activeStar.gameObject.activeInHierarchy) + { + if (_stars.Contains(_activeStar)) + { + _stars.Remove(_activeStar); + } + + if (_stars.Count > 0) + { + ChangeActiveStar(_stars[0]); + } + else + { + foreach (var (_, material) in AtmosphereBuilder.Skys) + { + material.SetFloat(SunIntensity, 0); + } + } + } + else + { + // Update atmo shaders + foreach (var (planet, material) in AtmosphereBuilder.Skys) + { + var sqrDist = (planet.transform.position - _activeStar.transform.position).sqrMagnitude; + var intensity = Mathf.Min(_activeStar.Intensity / (sqrDist / hearthSunDistanceSqr), 1f); + + material.SetFloat(SunIntensity, intensity); + } + + foreach (var star in _stars) + { + if (star == null) continue; + if (!(star.gameObject.activeSelf && star.gameObject.activeInHierarchy)) continue; + + if (star.Intensity * (star.transform.position - origin).sqrMagnitude < _activeStar.Intensity * (_activeStar.transform.position - origin).sqrMagnitude) + { + ChangeActiveStar(star); + break; + } + } + } } } @@ -151,8 +174,8 @@ namespace NewHorizons.Components _sunLightParamUpdater._propID_OWSunColorIntensity = Shader.PropertyToID("_OWSunColorIntensity"); // For the param thing to work it wants this to be on the star idk - this.transform.parent = star.transform; - this.transform.localPosition = Vector3.zero; + transform.parent = star.transform; + transform.localPosition = Vector3.zero; } } } diff --git a/NewHorizons/Components/StarSurfaceAudioController.cs b/NewHorizons/Components/Stars/StarSurfaceAudioController.cs similarity index 88% rename from NewHorizons/Components/StarSurfaceAudioController.cs rename to NewHorizons/Components/Stars/StarSurfaceAudioController.cs index aab8d3ce..71bdf525 100644 --- a/NewHorizons/Components/StarSurfaceAudioController.cs +++ b/NewHorizons/Components/Stars/StarSurfaceAudioController.cs @@ -1,7 +1,7 @@ using UnityEngine; using NewHorizons.Components.SizeControllers; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { [RequireComponent(typeof(OWAudioSource))] public class StarSurfaceAudioController : SectoredMonoBehaviour @@ -34,7 +34,7 @@ namespace NewHorizons.Components public void Update() { _fade = Mathf.MoveTowards(_fade, 1, Time.deltaTime * 0.2f); - float value = Mathf.Max(0.0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, this.transform.position) - (_starEvolutionController != null ? _starEvolutionController.CurrentScale : _size)); + float value = Mathf.Max(0.0f, Vector3.Distance(Locator.GetPlayerCamera().transform.position, transform.position) - (_starEvolutionController != null ? _starEvolutionController.CurrentScale : _size)); float num = Mathf.InverseLerp(1600f, 100f, value); _audioSource.SetLocalVolume(num * num * _fade); } diff --git a/NewHorizons/Components/StellarDeathController.cs b/NewHorizons/Components/Stars/StellarDeathController.cs similarity index 96% rename from NewHorizons/Components/StellarDeathController.cs rename to NewHorizons/Components/Stars/StellarDeathController.cs index fe5dadb3..a07fddeb 100644 --- a/NewHorizons/Components/StellarDeathController.cs +++ b/NewHorizons/Components/Stars/StellarDeathController.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Stars { public class StellarDeathController : MonoBehaviour { @@ -71,7 +71,7 @@ namespace NewHorizons.Components surface.transform.localScale = Vector3.one * _currentSupernovaScale; _localSupernovaMat.color = Color.Lerp(Color.black, supernovaMaterial.color, supernovaAlpha.Evaluate(_time)); - float distanceToPlayer = PlayerState.InDreamWorld() ? 20000f : (Vector3.Distance(transform.position, Locator.GetPlayerCamera().transform.position) - GetSupernovaRadius()); + float distanceToPlayer = PlayerState.InDreamWorld() ? 20000f : Vector3.Distance(transform.position, Locator.GetPlayerCamera().transform.position) - GetSupernovaRadius(); if (_isProxy) return; diff --git a/NewHorizons/Components/BaseVolume.cs b/NewHorizons/Components/Volumes/BaseVolume.cs similarity index 95% rename from NewHorizons/Components/BaseVolume.cs rename to NewHorizons/Components/Volumes/BaseVolume.cs index 6ddccada..f313310c 100644 --- a/NewHorizons/Components/BaseVolume.cs +++ b/NewHorizons/Components/Volumes/BaseVolume.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { [RequireComponent(typeof(OWTriggerVolume))] public abstract class BaseVolume : MonoBehaviour diff --git a/NewHorizons/Components/BlackHoleDestructionVolume.cs b/NewHorizons/Components/Volumes/BlackHoleDestructionVolume.cs similarity index 84% rename from NewHorizons/Components/BlackHoleDestructionVolume.cs rename to NewHorizons/Components/Volumes/BlackHoleDestructionVolume.cs index 145a0c5c..e5489760 100644 --- a/NewHorizons/Components/BlackHoleDestructionVolume.cs +++ b/NewHorizons/Components/Volumes/BlackHoleDestructionVolume.cs @@ -1,6 +1,6 @@ using NewHorizons.OtherMods.AchievementsPlus.NH; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class BlackHoleDestructionVolume : DestructionVolume { @@ -15,7 +15,7 @@ namespace NewHorizons.Components SurveyorProbe requiredComponent = probeBody.GetRequiredComponent(); if (requiredComponent.IsLaunched()) { - UnityEngine.Object.Destroy(requiredComponent.gameObject); + Destroy(requiredComponent.gameObject); ProbeLostAchievement.Earn(); } } diff --git a/NewHorizons/Components/ChangeStarSystemVolume.cs b/NewHorizons/Components/Volumes/ChangeStarSystemVolume.cs similarity index 94% rename from NewHorizons/Components/ChangeStarSystemVolume.cs rename to NewHorizons/Components/Volumes/ChangeStarSystemVolume.cs index ea57c53f..bdf43aae 100644 --- a/NewHorizons/Components/ChangeStarSystemVolume.cs +++ b/NewHorizons/Components/Volumes/ChangeStarSystemVolume.cs @@ -1,4 +1,4 @@ -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class ChangeStarSystemVolume : BlackHoleDestructionVolume { diff --git a/NewHorizons/Components/InterferenceVolume.cs b/NewHorizons/Components/Volumes/InterferenceVolume.cs similarity index 97% rename from NewHorizons/Components/InterferenceVolume.cs rename to NewHorizons/Components/Volumes/InterferenceVolume.cs index 43cf34ac..acb3582f 100644 --- a/NewHorizons/Components/InterferenceVolume.cs +++ b/NewHorizons/Components/Volumes/InterferenceVolume.cs @@ -6,7 +6,7 @@ using System.Text; using System.Threading.Tasks; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class InterferenceVolume : BaseVolume { diff --git a/NewHorizons/Components/MapRestrictionVolume.cs b/NewHorizons/Components/Volumes/MapRestrictionVolume.cs similarity index 94% rename from NewHorizons/Components/MapRestrictionVolume.cs rename to NewHorizons/Components/Volumes/MapRestrictionVolume.cs index 04442840..ee31a2a2 100644 --- a/NewHorizons/Components/MapRestrictionVolume.cs +++ b/NewHorizons/Components/Volumes/MapRestrictionVolume.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class MapRestrictionVolume : BaseVolume { diff --git a/NewHorizons/Components/NHFluidVolume.cs b/NewHorizons/Components/Volumes/NHFluidVolume.cs similarity index 86% rename from NewHorizons/Components/NHFluidVolume.cs rename to NewHorizons/Components/Volumes/NHFluidVolume.cs index 3b19f04d..3b5a4a00 100644 --- a/NewHorizons/Components/NHFluidVolume.cs +++ b/NewHorizons/Components/Volumes/NHFluidVolume.cs @@ -1,5 +1,5 @@ -using UnityEngine; -namespace NewHorizons.Components +using UnityEngine; +namespace NewHorizons.Components.Volumes { public class NHFluidVolume : RadialFluidVolume { diff --git a/NewHorizons/Components/NHInnerFogWarpVolume.cs b/NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs similarity index 83% rename from NewHorizons/Components/NHInnerFogWarpVolume.cs rename to NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs index 61c5e3ea..70d74979 100644 --- a/NewHorizons/Components/NHInnerFogWarpVolume.cs +++ b/NewHorizons/Components/Volumes/NHInnerFogWarpVolume.cs @@ -1,4 +1,4 @@ -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class NHInnerFogWarpVolume : InnerFogWarpVolume { diff --git a/NewHorizons/Components/NotificationVolume.cs b/NewHorizons/Components/Volumes/NotificationVolume.cs similarity index 97% rename from NewHorizons/Components/NotificationVolume.cs rename to NewHorizons/Components/Volumes/NotificationVolume.cs index 6fe7b746..70543449 100644 --- a/NewHorizons/Components/NotificationVolume.cs +++ b/NewHorizons/Components/Volumes/NotificationVolume.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class NotificationVolume : BaseVolume { @@ -16,7 +16,7 @@ namespace NewHorizons.Components public void SetPinned(bool pin) => _pin = pin; - public void SetTarget(External.Modules.VolumesModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse(target.ToString(), NotificationTarget.All)); + public void SetTarget(External.Modules.VolumesModule.NotificationVolumeInfo.NotificationTarget target) => SetTarget(EnumUtils.Parse(target.ToString(), NotificationTarget.All)); public void SetTarget(NotificationTarget target) => _target = target; diff --git a/NewHorizons/Components/RingFluidVolume.cs b/NewHorizons/Components/Volumes/RingFluidVolume.cs similarity index 95% rename from NewHorizons/Components/RingFluidVolume.cs rename to NewHorizons/Components/Volumes/RingFluidVolume.cs index 83b377a7..66982bdc 100644 --- a/NewHorizons/Components/RingFluidVolume.cs +++ b/NewHorizons/Components/Volumes/RingFluidVolume.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace NewHorizons.Components +namespace NewHorizons.Components.Volumes { public class RingFluidVolume : SimpleFluidVolume { @@ -14,7 +14,7 @@ namespace NewHorizons.Components ForceDetector forceDetector = hitObj.GetComponent(); if (forceDetector != null && forceDetector._activeVolumes != null && forceDetector._activeVolumes.Count > 0 && forceDetector._activeVolumes.Where(activeVolume => activeVolume is ForceVolume).Select(activeVolume => activeVolume as ForceVolume).Any(activeVolume => activeVolume.GetAffectsAlignment(forceDetector._attachedBody))) return; - + fluidDetector.AddVolume(this); } diff --git a/NewHorizons/Handlers/InterferenceHandler.cs b/NewHorizons/Handlers/InterferenceHandler.cs index 97ff0046..73912289 100644 --- a/NewHorizons/Handlers/InterferenceHandler.cs +++ b/NewHorizons/Handlers/InterferenceHandler.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace NewHorizons.Handlers { - using InterferenceVolume = NewHorizons.Components.InterferenceVolume; + using InterferenceVolume = Components.Volumes.InterferenceVolume; public static class InterferenceHandler { diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 3c7c2d1d..ffc14739 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -4,8 +4,9 @@ using NewHorizons.Builder.General; using NewHorizons.Builder.Orbital; using NewHorizons.Builder.Props; using NewHorizons.Builder.Volumes; -using NewHorizons.Components; using NewHorizons.Components.Orbital; +using NewHorizons.Components.Quantum; +using NewHorizons.Components.Stars; using NewHorizons.OtherMods.OWRichPresence; using NewHorizons.Utility; using System; @@ -57,9 +58,9 @@ namespace NewHorizons.Handlers GameObject.Destroy(starLightGO.GetComponent()); starLightGO.name = "StarLightController"; - starLightGO.AddComponent(); - StarLightController.AddStar(starController); - StarLightController.AddStarLight(starController.Light); + starLightGO.AddComponent(); + SunLightEffectsController.AddStar(starController); + SunLightEffectsController.AddStarLight(starController.Light); starLightGO.SetActive(true); @@ -499,10 +500,10 @@ namespace NewHorizons.Handlers { var (star, starController, starEvolutionController) = StarBuilder.Make(go, sector, body.Config.Star, body.Mod, body.Config.isStellarRemnant); - if (starController != null) StarLightController.AddStar(starController); + if (starController != null) SunLightEffectsController.AddStar(starController); var starLight = star.FindChild("SunLight"); - if (starLight != null) StarLightController.AddStarLight(starLight.GetComponent()); + if (starLight != null) SunLightEffectsController.AddStarLight(starLight.GetComponent()); // If it has an evolution controller that means it will die -> we make a remnant (unless its a remnant) if (starEvolutionController != null && !body.Config.isStellarRemnant) diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 7f8fbf28..b25e6d00 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.Stars; using NewHorizons.Utility; using OWML.Utils; using System; @@ -117,8 +117,8 @@ namespace NewHorizons.Handlers break; case AstroObject.Name.Sun: var starController = ao.gameObject.GetComponent(); - StarLightController.RemoveStar(starController); - StarLightController.RemoveStarLight(ao.gameObject.FindChild("Sector_SUN/Effects_SUN/SunLight").GetComponent()); + SunLightEffectsController.RemoveStar(starController); + SunLightEffectsController.RemoveStarLight(ao.gameObject.FindChild("Sector_SUN/Effects_SUN/SunLight").GetComponent()); GameObject.Destroy(starController); var audio = ao.GetComponentInChildren(); diff --git a/NewHorizons/Handlers/StarChartHandler.cs b/NewHorizons/Handlers/StarChartHandler.cs index 69e542c7..4ddec030 100644 --- a/NewHorizons/Handlers/StarChartHandler.cs +++ b/NewHorizons/Handlers/StarChartHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.ShipLog; using NewHorizons.Utility; using System.Collections.Generic; using UnityEngine; diff --git a/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs b/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs index f3578bda..f1e547c2 100644 --- a/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs +++ b/NewHorizons/Handlers/VesselCoordinatePromptHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.ShipLog; using NewHorizons.Utility; using System; using System.Collections.Generic; diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 678852bb..20e4a877 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -3,6 +3,7 @@ using NewHorizons.Builder.Atmosphere; using NewHorizons.Builder.Body; using NewHorizons.Builder.Props; using NewHorizons.Components; +using NewHorizons.Components.Fixers; using NewHorizons.Components.SizeControllers; using NewHorizons.External; using NewHorizons.External.Configs; diff --git a/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs b/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs index 7b94ca6c..727bc082 100644 --- a/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs +++ b/NewHorizons/OtherMods/OWRichPresence/RichPresenceHandler.cs @@ -1,4 +1,4 @@ -using NewHorizons.Components; +using NewHorizons.Components.ShipLog; using NewHorizons.Handlers; using NewHorizons.Utility; using System; diff --git a/NewHorizons/Patches/DestructionVolumePatches.cs b/NewHorizons/Patches/DestructionVolumePatches.cs index 23221daa..e29e3d02 100644 --- a/NewHorizons/Patches/DestructionVolumePatches.cs +++ b/NewHorizons/Patches/DestructionVolumePatches.cs @@ -1,5 +1,5 @@ using HarmonyLib; -using NewHorizons.Components; +using NewHorizons.Components.Quantum; using System; using System.Collections.Generic; using System.Linq; diff --git a/NewHorizons/Patches/RaftPatches.cs b/NewHorizons/Patches/RaftPatches.cs index b6f214ac..fea55497 100644 --- a/NewHorizons/Patches/RaftPatches.cs +++ b/NewHorizons/Patches/RaftPatches.cs @@ -1,5 +1,5 @@ using HarmonyLib; -using NewHorizons.Components; +using NewHorizons.Components.Volumes; using UnityEngine; namespace NewHorizons.Patches { diff --git a/NewHorizons/Patches/ShipLogPatches.cs b/NewHorizons/Patches/ShipLogPatches.cs index 96a89c01..52ce5a74 100644 --- a/NewHorizons/Patches/ShipLogPatches.cs +++ b/NewHorizons/Patches/ShipLogPatches.cs @@ -1,7 +1,6 @@ using HarmonyLib; using NewHorizons.OtherMods.AchievementsPlus; using NewHorizons.Builder.ShipLog; -using NewHorizons.Components; using NewHorizons.Handlers; using NewHorizons.Utility; using System; @@ -10,6 +9,8 @@ using System.Linq; using UnityEngine; using Logger = NewHorizons.Utility.Logger; using Object = UnityEngine.Object; +using NewHorizons.Components.ShipLog; + namespace NewHorizons.Patches { [HarmonyPatch] From b1eac0748ef7ab05cd024e62c1a620b7efa6d17d Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Sep 2022 00:57:10 -0400 Subject: [PATCH 31/33] Renamed it and fixed it for the sun --- .../StarEvolutionController.cs | 2 +- ...roller.cs => SunLightEffectsController.cs} | 22 ++++++++++++++----- .../Handlers/PlanetDestructionHandler.cs | 2 +- NewHorizons/Main.cs | 1 + 4 files changed, 19 insertions(+), 8 deletions(-) rename NewHorizons/Components/Stars/{StarLightController.cs => SunLightEffectsController.cs} (91%) diff --git a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs index 4e27972b..5e8a1b2e 100644 --- a/NewHorizons/Components/SizeControllers/StarEvolutionController.cs +++ b/NewHorizons/Components/SizeControllers/StarEvolutionController.cs @@ -303,7 +303,7 @@ namespace NewHorizons.Components.SizeControllers private void DisableStar(bool start = false) { if (controller != null) SunLightEffectsController.RemoveStar(controller); - if (!isProxy) SunLightEffectsController.RemoveStarLight(gameObject.FindChild("SunLight").GetAddComponent()); + if (!isProxy) SunLightEffectsController.RemoveStarLight(gameObject.FindChild("SunLight").GetComponent()); if (_stellarRemnant != null) { diff --git a/NewHorizons/Components/Stars/StarLightController.cs b/NewHorizons/Components/Stars/SunLightEffectsController.cs similarity index 91% rename from NewHorizons/Components/Stars/StarLightController.cs rename to NewHorizons/Components/Stars/SunLightEffectsController.cs index c3c7b944..c5260e54 100644 --- a/NewHorizons/Components/Stars/StarLightController.cs +++ b/NewHorizons/Components/Stars/SunLightEffectsController.cs @@ -1,4 +1,5 @@ using NewHorizons.Builder.Atmosphere; +using NewHorizons.Utility; using System.Collections.Generic; using UnityEngine; using Logger = NewHorizons.Utility.Logger; @@ -31,6 +32,13 @@ namespace NewHorizons.Components.Stars _sunLightParamUpdater._sunLightController = _sunLightController; } + public void Start() + { + // Using GameObject.Find here so that if its null we just dont find it + var sunlight = GameObject.Find("Sun_Body/Sector_SUN/Effects_SUN/SunLight").GetComponent(); + if (sunlight != null) AddStarLight(sunlight); + } + public static void AddStar(StarController star) { if (star == null) return; @@ -58,16 +66,18 @@ namespace NewHorizons.Components.Stars public static void AddStarLight(Light light) { - if (light == null) return; - - Instance._lights.Add(light); + if (light != null) + { + Instance._lights.SafeAdd(light); + } } public static void RemoveStarLight(Light light) { - if (light == null) return; - - if (Instance._lights.Contains(light)) Instance._lights.Remove(light); + if (light != null && Instance._lights.Contains(light)) + { + Instance._lights.Remove(light); + } } public void Update() diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index b25e6d00..a170ff62 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -118,7 +118,7 @@ namespace NewHorizons.Handlers case AstroObject.Name.Sun: var starController = ao.gameObject.GetComponent(); SunLightEffectsController.RemoveStar(starController); - SunLightEffectsController.RemoveStarLight(ao.gameObject.FindChild("Sector_SUN/Effects_SUN/SunLight").GetComponent()); + SunLightEffectsController.RemoveStarLight(ao.transform.Find("Sector_SUN/Effects_SUN/SunLight").GetComponent()); GameObject.Destroy(starController); var audio = ao.GetComponentInChildren(); diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 20e4a877..ef13942d 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -354,6 +354,7 @@ namespace NewHorizons var map = GameObject.FindObjectOfType(); if (map != null) map._maxPanDistance = FurthestOrbit * 1.5f; + // Fix the map satellite SearchUtilities.Find("HearthianMapSatellite_Body", false).AddComponent(); From e5bc06dacee3a2b992a6908eedb8777eb872260e Mon Sep 17 00:00:00 2001 From: Nick Date: Thu, 15 Sep 2022 13:28:08 -0400 Subject: [PATCH 32/33] Update GameLibs version --- NewHorizons/NewHorizons.csproj | 2 +- SchemaExporter/SchemaExporter.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/NewHorizons/NewHorizons.csproj b/NewHorizons/NewHorizons.csproj index bb43cdbf..a4e7f6e4 100644 --- a/NewHorizons/NewHorizons.csproj +++ b/NewHorizons/NewHorizons.csproj @@ -17,7 +17,7 @@ - + diff --git a/SchemaExporter/SchemaExporter.csproj b/SchemaExporter/SchemaExporter.csproj index 2c55f3ad..40ec8c5e 100644 --- a/SchemaExporter/SchemaExporter.csproj +++ b/SchemaExporter/SchemaExporter.csproj @@ -20,7 +20,7 @@ - + From edf505628046245b16ddf370028216879631b750 Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Thu, 15 Sep 2022 18:19:58 -0400 Subject: [PATCH 33/33] Update to match vanilla --- NewHorizons/Components/Stars/StellarDeathController.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Components/Stars/StellarDeathController.cs b/NewHorizons/Components/Stars/StellarDeathController.cs index a07fddeb..400297b3 100644 --- a/NewHorizons/Components/Stars/StellarDeathController.cs +++ b/NewHorizons/Components/Stars/StellarDeathController.cs @@ -22,6 +22,7 @@ namespace NewHorizons.Components.Stars private float _currentSupernovaScale; private Material _localSupernovaMat; private bool _isProxy; + private bool _renderingEnabled = true; private ParticleSystemRenderer[] _cachedParticleRenderers; public void Awake() @@ -34,8 +35,12 @@ namespace NewHorizons.Components.Stars public void Activate() { enabled = true; - shockwave.enabled = true; - foreach (var particle in explosionParticles) particle.Play(); + shockwave.enabled = _renderingEnabled; + for (int i = 0; i < explosionParticles.Length; i++) + { + explosionParticles[i].Play(); + _cachedParticleRenderers[i].enabled = _renderingEnabled; + } _time = 0.0f; _currentSupernovaScale = supernovaScale.Evaluate(0.0f); _localSupernovaMat = new Material(supernovaMaterial); @@ -97,6 +102,7 @@ namespace NewHorizons.Components.Stars public void SetRenderingEnabled(bool renderingEnabled) { + _renderingEnabled = renderingEnabled; if (!enabled) return; shockwave.enabled = renderingEnabled; SetParticlesVisibility(renderingEnabled);