mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-16 16:15:24 +00:00
51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using QSB.GeyserSync.Messages;
|
|
using QSB.Messaging;
|
|
using QSB.WorldSync;
|
|
using System.Threading;
|
|
|
|
namespace QSB.GeyserSync.WorldObjects;
|
|
|
|
public class QSBGeyser : WorldObject<GeyserController>
|
|
{
|
|
public override async UniTask Init(CancellationToken ct)
|
|
{
|
|
if (QSBCore.IsHost)
|
|
{
|
|
AttachedObject.OnGeyserActivateEvent += OnActivate;
|
|
AttachedObject.OnGeyserDeactivateEvent += OnDeactivate;
|
|
}
|
|
}
|
|
|
|
public override void OnRemoval()
|
|
{
|
|
if (QSBCore.IsHost)
|
|
{
|
|
AttachedObject.OnGeyserActivateEvent -= OnActivate;
|
|
AttachedObject.OnGeyserDeactivateEvent -= OnDeactivate;
|
|
}
|
|
}
|
|
|
|
public override void SendInitialState(uint to) =>
|
|
this.SendMessage(new GeyserMessage(AttachedObject._isActive) { To = to });
|
|
|
|
private void OnActivate() => this.SendMessage(new GeyserMessage(true));
|
|
private void OnDeactivate() => this.SendMessage(new GeyserMessage(false));
|
|
|
|
public void SetState(bool state)
|
|
{
|
|
if (AttachedObject._isActive == state)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (state)
|
|
{
|
|
AttachedObject.ActivateGeyser();
|
|
}
|
|
else
|
|
{
|
|
AttachedObject.DeactivateGeyser();
|
|
}
|
|
}
|
|
} |