2021-12-31 02:38:37 -08:00
|
|
|
|
using QSB.Messaging;
|
2021-12-23 12:33:30 -08:00
|
|
|
|
using QSB.Player;
|
2021-12-23 12:38:14 -08:00
|
|
|
|
using QSB.Player.TransformSync;
|
2021-12-23 12:33:30 -08:00
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
namespace QSB.EyeOfTheUniverse.EyeStateSync.Messages;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// todo SendInitialState
|
|
|
|
|
/// </summary>
|
2023-07-28 19:30:57 +01:00
|
|
|
|
public class EyeStateMessage : QSBMessage<EyeState>
|
2021-12-23 12:33:30 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
static EyeStateMessage() => GlobalMessenger<EyeState>.AddListener(OWEvents.EyeStateChanged, Handler);
|
2022-02-27 04:40:44 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
private static void Handler(EyeState state)
|
|
|
|
|
{
|
|
|
|
|
if (PlayerTransformSync.LocalInstance)
|
2021-12-23 12:38:14 -08:00
|
|
|
|
{
|
2022-03-02 19:46:33 -08:00
|
|
|
|
new EyeStateMessage(state).Send();
|
2021-12-23 12:38:14 -08:00
|
|
|
|
}
|
2022-03-02 19:46:33 -08:00
|
|
|
|
}
|
2021-12-23 12:33:30 -08:00
|
|
|
|
|
2022-03-10 17:57:50 -08:00
|
|
|
|
private EyeStateMessage(EyeState state) : base(state) { }
|
2021-12-23 12:33:30 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override bool ShouldReceive => QSBWorldSync.AllObjectsReady;
|
2021-12-23 12:33:30 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void OnReceiveLocal() => QSBPlayerManager.LocalPlayer.EyeState = Data;
|
2021-12-23 12:33:30 -08:00
|
|
|
|
|
2022-03-02 19:46:33 -08:00
|
|
|
|
public override void OnReceiveRemote()
|
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(From);
|
|
|
|
|
player.EyeState = Data;
|
2021-12-23 12:33:30 -08:00
|
|
|
|
}
|
|
|
|
|
}
|