mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-15 22:50:56 +00:00
messages
This commit is contained in:
parent
1b14fa0a3d
commit
32cba5ced2
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
@ -74,7 +74,7 @@ public partial class PlayerInfo
|
||||
}
|
||||
}
|
||||
|
||||
public QSBPlayerLightSensor PlayerLightSensor;
|
||||
public QSBPlayerLightSensor QSBPlayerLightSensor;
|
||||
|
||||
public Vector3 Velocity
|
||||
{
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user