mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-27 03:35:20 +00:00
0fef22cbf1
This reverts commit caf952a3
51 lines
1.3 KiB
C#
51 lines
1.3 KiB
C#
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
|
using QSB.Messaging;
|
|
using QSB.WorldSync;
|
|
using System;
|
|
|
|
namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
|
|
|
internal class QSBLightSensor : WorldObject<SingleLightSensor>
|
|
{
|
|
public bool IlluminatedByLocal;
|
|
|
|
public Action OnDetectLocalLight;
|
|
public Action OnDetectLocalDarkness;
|
|
|
|
public override void SendInitialState(uint to) =>
|
|
this.SendMessage(new SetEnabledMessage(AttachedObject.enabled) { To = to });
|
|
|
|
public void SetEnabled(bool enabled)
|
|
{
|
|
if (AttachedObject._sector && AttachedObject._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe))
|
|
{
|
|
// local player is in sector, do not disable lights
|
|
return;
|
|
}
|
|
|
|
if (enabled && !AttachedObject.enabled)
|
|
{
|
|
AttachedObject.enabled = true;
|
|
AttachedObject._lightDetector.GetShape().enabled = true;
|
|
if (AttachedObject._preserveStateWhileDisabled)
|
|
{
|
|
AttachedObject._fixedUpdateFrameDelayCount = 10;
|
|
}
|
|
}
|
|
else if (!enabled && AttachedObject.enabled)
|
|
{
|
|
AttachedObject.enabled = false;
|
|
AttachedObject._lightDetector.GetShape().enabled = false;
|
|
if (!AttachedObject._preserveStateWhileDisabled)
|
|
{
|
|
if (AttachedObject._illuminated)
|
|
{
|
|
AttachedObject.OnDetectDarkness.Invoke();
|
|
}
|
|
|
|
AttachedObject._illuminated = false;
|
|
}
|
|
}
|
|
}
|
|
}
|