This commit is contained in:
JohnCorby 2022-05-28 13:57:32 -07:00
parent 1b14fa0a3d
commit 32cba5ced2
6 changed files with 76 additions and 3 deletions

View File

@ -0,0 +1,28 @@
using QSB.Messaging;
using QSB.Player;
using System.Linq;
namespace QSB.EchoesOfTheEye.LightSensorSync.Messages;
/// <summary>
/// always sent by host
/// </summary>
internal class PlayerIlluminatedByMessage : QSBMessage<(uint playerId, uint[] illuminatedBy)>
{
public PlayerIlluminatedByMessage(uint playerId, uint[] illuminatedBy) : base((playerId, illuminatedBy)) { }
public override void OnReceiveRemote()
{
var qsbPlayerLightSensor = QSBPlayerManager.GetPlayer(Data.playerId).QSBPlayerLightSensor;
foreach (var added in Data.illuminatedBy.Except(qsbPlayerLightSensor._illuminatedBy))
{
qsbPlayerLightSensor.SetIlluminated(added, true);
}
foreach (var removed in qsbPlayerLightSensor._illuminatedBy.Except(Data.illuminatedBy))
{
qsbPlayerLightSensor.SetIlluminated(removed, false);
}
}
}

View File

@ -0,0 +1,32 @@
using QSB.EchoesOfTheEye.DreamLantern.WorldObjects;
using QSB.Messaging;
using QSB.Player;
using QSB.WorldSync;
using System.Collections.Generic;
using System.Linq;
namespace QSB.EchoesOfTheEye.LightSensorSync.Messages;
internal class PlayerIlluminatingLanternsMessage : QSBMessage<(uint playerId, int[] lanterns)>
{
public PlayerIlluminatingLanternsMessage(uint playerId, IEnumerable<DreamLanternController> lanterns) :
base((
playerId,
lanterns.Select(x => x.GetWorldObject<QSBDreamLantern>().ObjectId).ToArray()
)) { }
public override void OnReceiveRemote()
{
var lightSensor = (SingleLightSensor)QSBPlayerManager.GetPlayer(Data.playerId).LightSensor;
if (lightSensor.enabled)
{
// sensor is enabled, so this will already be synced
return;
}
lightSensor._illuminatingDreamLanternList.Clear();
lightSensor._illuminatingDreamLanternList.AddRange(
Data.lanterns.Select(x => x.GetWorldObject<QSBDreamLantern>().AttachedObject));
}
}

View File

@ -0,0 +1,13 @@
using QSB.Messaging;
using QSB.Player;
namespace QSB.EchoesOfTheEye.LightSensorSync.Messages;
internal class PlayerSetIlluminatedMessage : QSBMessage<(uint playerId, bool illuminated)>
{
public PlayerSetIlluminatedMessage(uint playerId, bool illuminated) : base((playerId, illuminated)) { }
public override void OnReceiveLocal() => OnReceiveRemote();
public override void OnReceiveRemote() =>
QSBPlayerManager.GetPlayer(Data.playerId).QSBPlayerLightSensor.SetIlluminated(From, Data.illuminated);
}

View File

@ -74,7 +74,7 @@ public partial class PlayerInfo
}
}
public QSBPlayerLightSensor PlayerLightSensor;
public QSBPlayerLightSensor QSBPlayerLightSensor;
public Vector3 Velocity
{

View File

@ -38,7 +38,7 @@ public static class LocalPlayerCreation
player.CameraBody = cameraBody.gameObject;
visibleCameraRoot = cameraBody;
player.PlayerLightSensor = player.LightSensor.gameObject.GetAddComponent<QSBPlayerLightSensor>();
player.QSBPlayerLightSensor = player.LightSensor.gameObject.GetAddComponent<QSBPlayerLightSensor>();
PlayerToolsManager.InitLocal();

View File

@ -77,7 +77,7 @@ public static class RemotePlayerCreation
player.CameraBody = REMOTE_PlayerCamera;
visibleCameraRoot = REMOTE_PlayerCamera.transform;
player.PlayerLightSensor = player.LightSensor.gameObject.GetAddComponent<QSBPlayerLightSensor>();
player.QSBPlayerLightSensor = player.LightSensor.gameObject.GetAddComponent<QSBPlayerLightSensor>();
PlayerToolsManager.InitRemote(player);