mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-17 10:14:14 +00:00
30 lines
941 B
C#
30 lines
941 B
C#
using QSB.Events;
|
|
using QSB.GeyserSync.WorldObjects;
|
|
using QSB.WorldSync;
|
|
using QSB.WorldSync.Events;
|
|
|
|
namespace QSB.GeyserSync.Events
|
|
{
|
|
public class GeyserEvent : QSBEvent<BoolWorldObjectMessage>
|
|
{
|
|
public override bool RequireWorldObjectsReady => true;
|
|
|
|
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBGeyserState, Handler);
|
|
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBGeyserState, Handler);
|
|
|
|
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
|
|
|
|
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new()
|
|
{
|
|
AboutId = LocalPlayerId,
|
|
ObjectId = id,
|
|
State = state
|
|
};
|
|
|
|
public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message)
|
|
{
|
|
var geyser = QSBWorldSync.GetWorldFromId<QSBGeyser>(message.ObjectId);
|
|
geyser?.SetState(message.State);
|
|
}
|
|
}
|
|
} |