From d410a429fe2f98781686c768e6151691feb19dc2 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Sat, 22 Feb 2025 11:04:44 -0600 Subject: [PATCH 1/5] Update Eye sector occupancy on load --- NewHorizons/Handlers/EyeSceneHandler.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/NewHorizons/Handlers/EyeSceneHandler.cs b/NewHorizons/Handlers/EyeSceneHandler.cs index 233086e6..ee4f4cdd 100644 --- a/NewHorizons/Handlers/EyeSceneHandler.cs +++ b/NewHorizons/Handlers/EyeSceneHandler.cs @@ -185,6 +185,12 @@ namespace NewHorizons.Handlers starLightController.Awake(); SunLightEffectsController.AddStar(starController); SunLightEffectsController.AddStarLight(sunLight); + + // The player starts out already added to the eye sector, so we need to inform the sectored components that the sector isn't empty + Delay.FireOnNextUpdate(() => + { + eyeSector.OnSectorOccupantsUpdated.Invoke(); + }); } public static void SetUpEyeCampfireSequence() From 8edc801903bbc41e8afe88d78f7f6e1eec3fd303 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Sat, 22 Feb 2025 11:04:56 -0600 Subject: [PATCH 2/5] Fix error when single light sensor has no sector --- NewHorizons/Builder/Props/DetailBuilder.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Props/DetailBuilder.cs b/NewHorizons/Builder/Props/DetailBuilder.cs index 022acd74..825af0c1 100644 --- a/NewHorizons/Builder/Props/DetailBuilder.cs +++ b/NewHorizons/Builder/Props/DetailBuilder.cs @@ -356,7 +356,10 @@ namespace NewHorizons.Builder.Props singleLightSensor._sector.OnSectorOccupantsUpdated -= singleLightSensor.OnSectorOccupantsUpdated; } singleLightSensor._sector = sector; - singleLightSensor._sector.OnSectorOccupantsUpdated += singleLightSensor.OnSectorOccupantsUpdated; + if (singleLightSensor._sector != null) + { + singleLightSensor._sector.OnSectorOccupantsUpdated += singleLightSensor.OnSectorOccupantsUpdated; + } } } From 8c9d8ad02c084fe12de0d0e1e7ea99d00292d55b Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Wed, 26 Feb 2025 21:13:45 -0600 Subject: [PATCH 3/5] Revert previous eye sector fix attempt --- NewHorizons/Handlers/EyeSceneHandler.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/NewHorizons/Handlers/EyeSceneHandler.cs b/NewHorizons/Handlers/EyeSceneHandler.cs index ee4f4cdd..233086e6 100644 --- a/NewHorizons/Handlers/EyeSceneHandler.cs +++ b/NewHorizons/Handlers/EyeSceneHandler.cs @@ -185,12 +185,6 @@ namespace NewHorizons.Handlers starLightController.Awake(); SunLightEffectsController.AddStar(starController); SunLightEffectsController.AddStarLight(sunLight); - - // The player starts out already added to the eye sector, so we need to inform the sectored components that the sector isn't empty - Delay.FireOnNextUpdate(() => - { - eyeSector.OnSectorOccupantsUpdated.Invoke(); - }); } public static void SetUpEyeCampfireSequence() From b7c8bba33e1ccc57dffeed44e62e8ebe4a084d78 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Wed, 26 Feb 2025 21:14:22 -0600 Subject: [PATCH 4/5] Fix SectorCollisionGroups on immediately disabled details --- NewHorizons/Builder/General/GroupsBuilder.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NewHorizons/Builder/General/GroupsBuilder.cs b/NewHorizons/Builder/General/GroupsBuilder.cs index b2252f5e..2998c02f 100644 --- a/NewHorizons/Builder/General/GroupsBuilder.cs +++ b/NewHorizons/Builder/General/GroupsBuilder.cs @@ -25,5 +25,8 @@ public static class GroupsBuilder go.GetAddComponent()._sector = sector; go.GetAddComponent()._sector = sector; go.GetAddComponent()._sector = sector; + + // SectorCollisionGroup is unique among the sector groups because it only attaches its event listener on Start() instead of Awake(), so if the detail gets immediately deactivated then it never gets attached. To avoid this, we'll attach the event listener manually (even if it means getting attached twice). + sector.OnSectorOccupantsUpdated += go.GetComponent().OnSectorOccupantsUpdated; } } \ No newline at end of file From 155e7ace9ccce49dab1df370208ab17ce01934f8 Mon Sep 17 00:00:00 2001 From: Joshua Thome Date: Wed, 26 Feb 2025 21:14:35 -0600 Subject: [PATCH 5/5] Patch SingleLightSensors to handle immediately disabled details --- .../SingleLightSensorPatches.cs | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 NewHorizons/Patches/EchoesOfTheEyePatches/SingleLightSensorPatches.cs diff --git a/NewHorizons/Patches/EchoesOfTheEyePatches/SingleLightSensorPatches.cs b/NewHorizons/Patches/EchoesOfTheEyePatches/SingleLightSensorPatches.cs new file mode 100644 index 00000000..39665dfc --- /dev/null +++ b/NewHorizons/Patches/EchoesOfTheEyePatches/SingleLightSensorPatches.cs @@ -0,0 +1,24 @@ +using HarmonyLib; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NewHorizons.Patches.EchoesOfTheEyePatches +{ + [HarmonyPatch(typeof(SingleLightSensor))] + public static class SingleLightSensorPatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(SingleLightSensor.Start))] + public static void Start(SingleLightSensor __instance) + { + // SingleLightSensor assumes that the sector will be empty when it starts and disables itself, but this may not be true if it starts disabled and is activated later, or spawned via the API + if (__instance._sector && __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe)) + { + __instance.OnSectorOccupantsUpdated(); + } + } + } +}