mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2024-12-29 12:21:25 +00:00
light sensors: set enabled message, too lazy to do auth stuff
This commit is contained in:
parent
8dbd884403
commit
82666dff2d
@ -0,0 +1,10 @@
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
||||
|
||||
internal class SetEnabledMessage : QSBWorldObjectMessage<QSBLightSensor, bool>
|
||||
{
|
||||
public SetEnabledMessage(bool data) : base(data) { }
|
||||
public override void OnReceiveRemote() => WorldObject.SetEnabled(Data);
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
using HarmonyLib;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
using QSB.Tools.FlashlightTool;
|
||||
using QSB.Tools.ProbeTool;
|
||||
@ -13,6 +15,45 @@ internal class LightSensorPatches : QSBPatch
|
||||
{
|
||||
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(SingleLightSensor.OnSectorOccupantsUpdated))]
|
||||
private static bool OnSectorOccupantsUpdated(SingleLightSensor __instance)
|
||||
{
|
||||
if (!QSBWorldSync.AllObjectsReady)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var flag = __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe);
|
||||
if (flag && !__instance.enabled)
|
||||
{
|
||||
__instance.enabled = true;
|
||||
__instance.GetWorldObject<QSBLightSensor>().SendMessage(new SetEnabledMessage(true));
|
||||
__instance._lightDetector.GetShape().enabled = true;
|
||||
if (__instance._preserveStateWhileDisabled)
|
||||
{
|
||||
__instance._fixedUpdateFrameDelayCount = 10;
|
||||
}
|
||||
}
|
||||
else if (!flag && __instance.enabled)
|
||||
{
|
||||
__instance.enabled = false;
|
||||
__instance.GetWorldObject<QSBLightSensor>().SendMessage(new SetEnabledMessage(false));
|
||||
__instance._lightDetector.GetShape().enabled = false;
|
||||
if (!__instance._preserveStateWhileDisabled)
|
||||
{
|
||||
if (__instance._illuminated)
|
||||
{
|
||||
__instance.OnDetectDarkness.Invoke();
|
||||
}
|
||||
|
||||
__instance._illuminated = false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(SingleLightSensor.UpdateIllumination))]
|
||||
private static bool UpdateIllumination(SingleLightSensor __instance)
|
||||
|
@ -1,4 +1,6 @@
|
||||
using QSB.WorldSync;
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
||||
using QSB.Messaging;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
|
||||
namespace QSB.EchoesOfTheEye.LightSensorSync.WorldObjects;
|
||||
@ -10,5 +12,33 @@ internal class QSBLightSensor : WorldObject<SingleLightSensor>
|
||||
public Action OnDetectLocalLight;
|
||||
public Action OnDetectLocalDarkness;
|
||||
|
||||
public override void SendInitialState(uint to) { }
|
||||
public override void SendInitialState(uint to) =>
|
||||
this.SendMessage(new SetEnabledMessage(AttachedObject.enabled));
|
||||
|
||||
public void SetEnabled(bool enabled)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user