quantum-space-buddies/QSB/SatelliteSync/Events/SatelliteProjectorEvent.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2021-11-03 09:18:52 +00:00
using QSB.Events;
using QSB.Messaging;
namespace QSB.SatelliteSync.Events
{
2021-11-09 19:39:56 +00:00
internal class SatelliteProjectorEvent : QSBEvent<BoolMessage>
2021-11-03 09:18:52 +00:00
{
public override bool RequireWorldObjectsReady() => true;
2021-11-03 09:18:52 +00:00
public override void SetupListener()
{
GlobalMessenger.AddListener(EventNames.QSBEnterSatelliteCamera, () => Handler(true));
GlobalMessenger.AddListener(EventNames.QSBExitSatelliteCamera, () => Handler(false));
}
public override void CloseListener()
{
GlobalMessenger.RemoveListener(EventNames.QSBEnterSatelliteCamera, () => Handler(true));
GlobalMessenger.RemoveListener(EventNames.QSBExitSatelliteCamera, () => Handler(false));
}
private void Handler(bool usingProjector) => SendEvent(CreateMessage(usingProjector));
2021-11-20 19:49:50 +00:00
private BoolMessage CreateMessage(bool usingProjector) => new()
2021-11-03 09:18:52 +00:00
{
AboutId = LocalPlayerId,
Value = usingProjector
};
public override void OnReceiveRemote(bool isHost, BoolMessage message)
{
if (message.Value)
{
SatelliteProjectorManager.Instance.RemoteEnter();
}
else
{
SatelliteProjectorManager.Instance.RemoteExit();
}
}
}
}