quantum-space-buddies/QSB/OrbSync/Events/OrbDragEvent.cs

47 lines
1.4 KiB
C#
Raw Normal View History

2021-12-15 04:24:02 +00:00
using QSB.AuthoritySync;
2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-11-03 22:18:22 +00:00
using QSB.WorldSync.Events;
2021-12-15 04:24:02 +00:00
using QSB.OrbSync.WorldObjects;
using QSB.WorldSync;
2020-11-03 17:56:48 +00:00
namespace QSB.OrbSync.Events
{
2021-12-15 09:20:51 +00:00
public class OrbDragEvent : QSBEvent<BoolWorldObjectMessage>
2020-12-02 21:29:53 +00:00
{
public override bool RequireWorldObjectsReady => true;
2021-12-15 09:20:51 +00:00
public override void SetupListener() => GlobalMessenger<QSBOrb, bool>.AddListener(EventNames.QSBOrbDrag, Handler);
public override void CloseListener() => GlobalMessenger<QSBOrb, bool>.RemoveListener(EventNames.QSBOrbDrag, Handler);
2021-12-15 04:24:02 +00:00
private void Handler(QSBOrb qsbOrb, bool isDragging) => SendEvent(CreateMessage(qsbOrb, isDragging));
2021-12-15 04:24:02 +00:00
private BoolWorldObjectMessage CreateMessage(QSBOrb qsbOrb, bool isDragging) => new()
2020-12-02 21:29:53 +00:00
{
2021-12-15 04:24:02 +00:00
ObjectId = qsbOrb.ObjectId,
2021-12-14 05:18:16 +00:00
State = isDragging
2020-12-02 21:29:53 +00:00
};
2021-12-15 07:57:21 +00:00
public override void OnReceiveLocal(bool isHost, BoolWorldObjectMessage message)
2020-12-19 13:31:05 +00:00
{
2021-12-15 04:24:02 +00:00
var qsbOrb = QSBWorldSync.GetWorldFromId<QSBOrb>(message.ObjectId);
2020-12-14 20:41:56 +00:00
2021-12-18 06:21:58 +00:00
if (isHost && message.State)
2021-03-23 13:18:29 +00:00
{
2021-12-18 05:14:30 +00:00
qsbOrb.TransformSync.NetIdentity.UpdateAuthQueue(message.FromId, AuthQueueAction.Force);
2021-03-23 13:18:29 +00:00
}
2021-12-15 07:57:21 +00:00
}
public override void OnReceiveRemote(bool isHost, BoolWorldObjectMessage message)
{
var qsbOrb = QSBWorldSync.GetWorldFromId<QSBOrb>(message.ObjectId);
2021-12-18 06:21:58 +00:00
if (isHost && message.State)
2020-12-14 21:20:53 +00:00
{
2021-12-18 05:14:30 +00:00
qsbOrb.TransformSync.NetIdentity.UpdateAuthQueue(message.FromId, AuthQueueAction.Force);
2020-12-14 21:20:53 +00:00
}
2021-12-15 07:57:21 +00:00
qsbOrb.SetDragging(message.State);
2020-12-14 21:20:53 +00:00
}
}
2021-12-02 05:34:02 +00:00
}