34 lines
933 B
C#
Raw Normal View History

2020-08-13 14:32:58 +01:00
using QSB.Events;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.GeyserSync
{
public class GeyserEvent : QSBEvent<GeyserMessage>
{
public override MessageType Type => MessageType.Geyser;
public override void SetupListener()
{
2020-08-13 20:43:47 +02:00
GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, (id, state) => SendEvent(CreateMessage(id, state)));
2020-08-13 14:32:58 +01:00
}
2020-08-13 20:43:47 +02:00
private GeyserMessage CreateMessage(int id, bool state) => new GeyserMessage
2020-08-13 14:32:58 +01:00
{
SenderId = PlayerRegistry.LocalPlayer.NetId,
2020-08-13 20:47:23 +02:00
ObjectId = id,
2020-08-13 14:32:58 +01:00
State = state
};
public override void OnReceiveRemote(GeyserMessage message)
{
2020-08-13 17:44:27 +01:00
if (!IsInUniverse)
2020-08-13 14:32:58 +01:00
{
return;
}
2020-08-13 20:47:23 +02:00
var geyser = WorldRegistry.GetObject<QSBGeyser>(message.ObjectId);
2020-08-13 19:25:12 +02:00
geyser.SetState(message.State);
2020-08-13 14:32:58 +01:00
}
}
}