diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 1e6a917c..2ff9a98b 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; using System.Linq; using UnityEngine; +using NewHorizons.Streaming; using Newtonsoft.Json; namespace NewHorizons.Handlers @@ -745,6 +746,35 @@ namespace NewHorizons.Handlers var aoName = ao.GetAstroObjectName(); var aoType = ao.GetAstroObjectType(); + // When updating orbits of the twins be sure the FocalBody is gone + // Don't do it if it's already an NHAstroObject since that means this was already done + if (ao is not NHAstroObject && (aoName == AstroObject.Name.TowerTwin || aoName == AstroObject.Name.CaveTwin)) + { + var hourglassTwinsFocal = SearchUtilities.Find("FocalBody"); + + // Have to copy the HGT sector bc it has some ruleset stuff on it we want + var clonedSectorHGT = hourglassTwinsFocal.FindChild("Sector_HGT").Instantiate().Rename("Sector_HGT"); + clonedSectorHGT.transform.parent = go.transform; + clonedSectorHGT.transform.localPosition = Vector3.zero; + clonedSectorHGT.transform.localRotation = Quaternion.identity; + + // Don't need this part + GameObject.Destroy(clonedSectorHGT.GetComponentInChildren().gameObject); + + // Take the hourglass twins shader effect controller off the focal body so it can stay active + var shaderController = hourglassTwinsFocal.GetComponentInChildren(); + if (shaderController != null) shaderController.transform.parent = null; + + hourglassTwinsFocal.SetActive(false); + + // Remove the drift tracker since its unneeded now + Component.Destroy(go.GetComponent()); + + // Fix sectors + VanillaStreamingFix.UnparentSectorStreaming(ao.GetRootSector(), ao.gameObject, AstroObject.Name.HourglassTwins, Sector.Name.HourglassTwins); + ao.GetRootSector().SetParentSector(null); + } + var owrb = go.GetComponent(); var im = go.GetComponent(); diff --git a/NewHorizons/Handlers/StreamingHandler.cs b/NewHorizons/Handlers/StreamingHandler.cs index aeeb7794..c037594d 100644 --- a/NewHorizons/Handlers/StreamingHandler.cs +++ b/NewHorizons/Handlers/StreamingHandler.cs @@ -1,3 +1,4 @@ +using NewHorizons.Utility; using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -143,7 +144,7 @@ namespace NewHorizons.Handlers { if (name is AstroObject.Name.CaveTwin or AstroObject.Name.TowerTwin) { - return GameObject.Find("FocalBody/StreamingGroup_HGT").GetComponent(); + return SearchUtilities.Find("FocalBody/StreamingGroup_HGT").GetComponent(); } else { diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index fbfe94fb..f9600c0a 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -15,6 +15,7 @@ using NewHorizons.OtherMods.AchievementsPlus; using NewHorizons.OtherMods.MenuFramework; using NewHorizons.OtherMods.OWRichPresence; using NewHorizons.OtherMods.VoiceActing; +using NewHorizons.Streaming; using NewHorizons.Utility; using NewHorizons.Utility.DebugTools; using NewHorizons.Utility.DebugTools.Menu; @@ -478,46 +479,9 @@ namespace NewHorizons // Sector changes (so that projection pools actually turn off proxies and cull groups on these moons) - //Fix attlerock vanilla sector components (they were set to timber hearth's sector) - var thm = SearchUtilities.Find("Moon_Body/Sector_THM").GetComponent(); - foreach (var component in thm.GetComponentsInChildren(true)) - { - if (component is ISectorGroup sectorGroup) - { - sectorGroup.SetSector(thm); - } - - if (component is SectoredMonoBehaviour behaviour) - { - behaviour.SetSector(thm); - } - } - var thm_ss_obj = new GameObject("Sector_Streaming"); - thm_ss_obj.transform.SetParent(thm.transform, false); - var thm_ss = thm_ss_obj.AddComponent(); - thm_ss._streamingGroup = SearchUtilities.Find("TimberHearth_Body/StreamingGroup_TH").GetComponent(); - thm_ss.SetSector(thm); - - - //Fix hollow's lantern vanilla sector components (they were set to brittle hollow's sector) - var vm = SearchUtilities.Find("VolcanicMoon_Body/Sector_VM").GetComponent(); - foreach (var component in vm.GetComponentsInChildren(true)) - { - if (component is ISectorGroup sectorGroup) - { - sectorGroup.SetSector(vm); - } - - if (component is SectoredMonoBehaviour behaviour) - { - behaviour.SetSector(vm); - } - } - var vm_ss_obj = new GameObject("Sector_Streaming"); - vm_ss_obj.transform.SetParent(vm.transform, false); - var vm_ss = vm_ss_obj.AddComponent(); - vm_ss._streamingGroup = SearchUtilities.Find("BrittleHollow_Body/StreamingGroup_BH").GetComponent(); - vm_ss.SetSector(vm); + // Fix moon vanilla sector components (they were set to their primaries' sectors) + VanillaStreamingFix.UnparentSectorStreaming(SearchUtilities.Find("Moon_Body/Sector_THM").GetComponent(), AstroObject.Name.TimberHearth); + VanillaStreamingFix.UnparentSectorStreaming(SearchUtilities.Find("VolcanicMoon_Body/Sector_VM").GetComponent(), AstroObject.Name.BrittleHollow); //Fix brittle hollow north pole projection platform var northPoleSurface = SearchUtilities.Find("BrittleHollow_Body/Sector_BH/Sector_NorthHemisphere/Sector_NorthPole/Sector_NorthPoleSurface").GetComponent(); diff --git a/NewHorizons/Streaming/VanillaStreamingFix.cs b/NewHorizons/Streaming/VanillaStreamingFix.cs new file mode 100644 index 00000000..2b5b0c36 --- /dev/null +++ b/NewHorizons/Streaming/VanillaStreamingFix.cs @@ -0,0 +1,39 @@ +using NewHorizons.Handlers; +using UnityEngine; + +namespace NewHorizons.Streaming; + +internal static class VanillaStreamingFix +{ + internal static void UnparentSectorStreaming(Sector rootSector, AstroObject.Name streamingGroupName) + => UnparentSectorStreaming(rootSector, rootSector.gameObject, streamingGroupName, Sector.Name.Unnamed); + + internal static void UnparentSectorStreaming(Sector rootSector, GameObject startingObject, AstroObject.Name streamingGroupName, Sector.Name originalParentSectorName) + { + // Set originalParentSectorName to unnamed to alter all sectors + foreach (var component in startingObject.GetComponentsInChildren(true)) + { + if (component is ISectorGroup sectorGroup) + { + if (sectorGroup.GetSector()?.GetName() == originalParentSectorName || originalParentSectorName == Sector.Name.Unnamed) + { + sectorGroup.SetSector(rootSector); + } + } + + if (component is SectoredMonoBehaviour behaviour) + { + if (behaviour.GetSector()?.GetName() == originalParentSectorName || originalParentSectorName == Sector.Name.Unnamed) + { + behaviour.SetSector(rootSector); + } + } + } + var sectorStreamingObj = new GameObject("Sector_Streaming"); + sectorStreamingObj.transform.SetParent(startingObject.transform, false); + + var sectorStreaming = sectorStreamingObj.AddComponent(); + sectorStreaming._streamingGroup = StreamingHandler.GetStreamingGroup(streamingGroupName); + sectorStreaming.SetSector(rootSector); + } +}