quantum-space-buddies/QSB/GeyserSync/WorldObjects/QSBGeyser.cs

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();
}
}
}