quantum-space-buddies/QSB/TornadoSync/Events/TornadoFormStateEvent.cs

33 lines
994 B
C#
Raw Normal View History

2021-12-05 11:41:07 +00:00
using QSB.Events;
using QSB.TornadoSync.WorldObjects;
using QSB.WorldSync;
using QSB.WorldSync.Events;
namespace QSB.TornadoSync.Events
{
2021-12-06 04:09:54 +00:00
public class TornadoFormStateEvent : QSBEvent<BoolWorldObjectMessage>
2021-12-05 11:41:07 +00:00
{
public override bool RequireWorldObjectsReady => true;
public override void SetupListener()
2021-12-06 04:09:54 +00:00
=> GlobalMessenger<QSBTornado>.AddListener(EventNames.QSBTornadoFormState, Handler);
2021-12-05 11:41:07 +00:00
public override void CloseListener()
2021-12-06 04:09:54 +00:00
=> GlobalMessenger<QSBTornado>.RemoveListener(EventNames.QSBTornadoFormState, Handler);
2021-12-05 11:41:07 +00:00
2021-12-06 04:09:54 +00:00
private void Handler(QSBTornado qsbTornado) => SendEvent(CreateMessage(qsbTornado));
2021-12-05 11:41:07 +00:00
2021-12-06 04:09:54 +00:00
private BoolWorldObjectMessage CreateMessage(QSBTornado qsbTornado) => new()
2021-12-05 11:41:07 +00:00
{
ObjectId = qsbTornado.ObjectId,
2021-12-06 04:09:54 +00:00
State = qsbTornado.FormState
2021-12-05 11:41:07 +00:00
};
public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message)
{
var qsbTornado = QSBWorldSync.GetWorldFromId<QSBTornado>(message.ObjectId);
2021-12-06 04:09:54 +00:00
qsbTornado.FormState = message.State;
2021-12-05 11:41:07 +00:00
}
}
}