2021-12-31 10:38:37 +00:00
|
|
|
|
using QSB.Messaging;
|
2021-12-23 20:33:30 +00:00
|
|
|
|
using QSB.Player;
|
2021-12-23 20:38:14 +00:00
|
|
|
|
using QSB.Player.TransformSync;
|
2021-12-23 20:33:30 +00:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
namespace QSB.EyeOfTheUniverse.EyeStateSync.Messages;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// todo SendInitialState
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal class EyeStateMessage : QSBMessage<EyeState>
|
2021-12-23 20:33:30 +00:00
|
|
|
|
{
|
2022-02-25 06:04:54 +00:00
|
|
|
|
static EyeStateMessage() => GlobalMessenger<EyeState>.AddListener(OWEvents.EyeStateChanged, Handler);
|
2021-12-23 20:38:14 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
private static void Handler(EyeState state)
|
|
|
|
|
{
|
|
|
|
|
if (PlayerTransformSync.LocalInstance)
|
2021-12-23 20:38:14 +00:00
|
|
|
|
{
|
2022-02-25 06:04:54 +00:00
|
|
|
|
new EyeStateMessage(state).Send();
|
2021-12-23 20:38:14 +00:00
|
|
|
|
}
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|
2021-12-23 20:33:30 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
private EyeStateMessage(EyeState state) => Value = state;
|
2021-12-23 20:33:30 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
2021-12-23 20:33:30 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
public override void OnReceiveLocal() => QSBPlayerManager.LocalPlayer.EyeState = Value;
|
2021-12-23 20:33:30 +00:00
|
|
|
|
|
2022-02-25 06:04:54 +00:00
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
|
|
|
player.EyeState = Value;
|
2021-12-23 20:33:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|