52 lines
1.1 KiB
C#
Raw Normal View History

2022-01-28 20:49:07 -08:00
using Cysharp.Threading.Tasks;
using QSB.GeyserSync.Messages;
2021-12-24 21:23:40 -08:00
using QSB.Messaging;
2020-08-13 19:25:12 +02:00
using QSB.WorldSync;
2022-01-28 20:49:07 -08:00
using System.Threading;
2020-08-13 19:25:12 +02:00
namespace QSB.GeyserSync.WorldObjects
2020-08-13 19:25:12 +02:00
{
public class QSBGeyser : WorldObject<GeyserController>
2020-12-02 21:29:53 +00:00
{
public override async UniTask Init(CancellationToken ct)
2020-12-02 21:29:53 +00:00
{
if (QSBCore.IsHost)
{
AttachedObject.OnGeyserActivateEvent += OnActivate;
AttachedObject.OnGeyserDeactivateEvent += OnDeactivate;
}
2020-12-02 21:29:53 +00:00
}
2020-08-13 19:25:12 +02:00
public override void OnRemoval()
2022-01-25 20:20:16 -08:00
{
if (QSBCore.IsHost)
{
AttachedObject.OnGeyserActivateEvent -= OnActivate;
AttachedObject.OnGeyserDeactivateEvent -= OnDeactivate;
}
2022-01-25 20:20:16 -08:00
}
2022-01-21 21:54:46 -08:00
public override void SendInitialState(uint to) =>
this.SendMessage(new GeyserMessage(AttachedObject._isActive));
2020-08-13 19:25:12 +02:00
private void OnActivate() => this.SendMessage(new GeyserMessage(true));
private void OnDeactivate() => this.SendMessage(new GeyserMessage(false));
2022-01-25 20:20:16 -08:00
public void SetState(bool state)
2020-12-02 21:29:53 +00:00
{
if (AttachedObject._isActive == state)
{
return;
}
2021-06-18 22:38:32 +01:00
if (state)
{
AttachedObject.ActivateGeyser();
}
else
{
AttachedObject.DeactivateGeyser();
}
2020-12-02 21:29:53 +00:00
}
}
}