Fixes for Immediately Disabled Details (#1058)

## Bug fixes

- Fixed details not having collision if they were immediately
deactivated after being created (for instance, via
`activationCondition`)
- Fixed light sensors disabling themselves on activation if their detail
was immediately deactivated after being created
This commit is contained in:
Joshua Thome 2025-02-26 22:11:19 -06:00 committed by GitHub
commit d215fc4cef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 1 deletions

View File

@ -25,5 +25,8 @@ public static class GroupsBuilder
go.GetAddComponent<SectorCullGroup>()._sector = sector;
go.GetAddComponent<SectorCollisionGroup>()._sector = sector;
go.GetAddComponent<SectorLightsCullGroup>()._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<SectorCollisionGroup>().OnSectorOccupantsUpdated;
}
}

View File

@ -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;
}
}
}

View File

@ -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();
}
}
}
}