mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-06 01:00:16 +00:00
player light sensor is simplier,
wait until ready before doing _startIlluminated stuff
This commit is contained in:
parent
659ca91195
commit
187f45927d
@ -75,9 +75,8 @@ internal class LightSensorPatches : QSBPatch
|
||||
return true;
|
||||
}
|
||||
|
||||
var isPlayerLightSensor = LightSensorManager.IsPlayerLightSensor(__instance);
|
||||
var qsbPlayerLightSensor = isPlayerLightSensor ? __instance.GetComponent<QSBPlayerLightSensor>() : null;
|
||||
var qsbLightSensor = isPlayerLightSensor ? null : __instance.GetWorldObject<QSBLightSensor>();
|
||||
// player light sensors dont have a sector, so no need to worry about them
|
||||
var qsbLightSensor = __instance.GetWorldObject<QSBLightSensor>();
|
||||
|
||||
var containsAnyOccupants = __instance._sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe);
|
||||
if (containsAnyOccupants && !__instance.enabled)
|
||||
@ -95,22 +94,11 @@ internal class LightSensorPatches : QSBPatch
|
||||
__instance._lightDetector.GetShape().enabled = false;
|
||||
if (!__instance._preserveStateWhileDisabled)
|
||||
{
|
||||
if (isPlayerLightSensor)
|
||||
if (qsbLightSensor._locallyIlluminated)
|
||||
{
|
||||
if (qsbPlayerLightSensor._locallyIlluminated)
|
||||
{
|
||||
qsbPlayerLightSensor._locallyIlluminated = false;
|
||||
new PlayerSetIlluminatedMessage(qsbPlayerLightSensor.PlayerId, false).Send();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (qsbLightSensor._locallyIlluminated)
|
||||
{
|
||||
qsbLightSensor._locallyIlluminated = false;
|
||||
qsbLightSensor.OnDetectLocalDarkness?.Invoke();
|
||||
qsbLightSensor.SendMessage(new SetIlluminatedMessage(false));
|
||||
}
|
||||
qsbLightSensor._locallyIlluminated = false;
|
||||
qsbLightSensor.OnDetectLocalDarkness?.Invoke();
|
||||
qsbLightSensor.SendMessage(new SetIlluminatedMessage(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,16 +34,6 @@ public class QSBPlayerLightSensor : MonoBehaviour
|
||||
|
||||
RequestInitialStatesMessage.SendInitialState += SendInitialState;
|
||||
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
||||
|
||||
// normally done in Start, but world objects arent ready by that point
|
||||
if (_lightSensor._sector != null)
|
||||
{
|
||||
if (_lightSensor._startIlluminated)
|
||||
{
|
||||
_locallyIlluminated = true;
|
||||
new PlayerSetIlluminatedMessage(PlayerId, true).Send();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
|
@ -2,6 +2,7 @@
|
||||
using QSB.EchoesOfTheEye.LightSensorSync.Messages;
|
||||
using QSB.Messaging;
|
||||
using QSB.Player;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -37,15 +38,18 @@ internal class QSBLightSensor : WorldObject<SingleLightSensor>
|
||||
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
||||
|
||||
// normally done in Start, but world objects arent ready by that point
|
||||
if (AttachedObject._sector != null)
|
||||
Delay.RunWhen(() => QSBWorldSync.AllObjectsReady, () =>
|
||||
{
|
||||
if (AttachedObject._startIlluminated)
|
||||
if (AttachedObject._sector != null)
|
||||
{
|
||||
_locallyIlluminated = true;
|
||||
OnDetectLocalLight?.Invoke();
|
||||
this.SendMessage(new SetIlluminatedMessage(true));
|
||||
if (AttachedObject._startIlluminated)
|
||||
{
|
||||
_locallyIlluminated = true;
|
||||
OnDetectLocalLight?.Invoke();
|
||||
this.SendMessage(new SetIlluminatedMessage(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public override void OnRemoval() => QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave;
|
||||
|
Loading…
Reference in New Issue
Block a user