quantum-space-buddies/QSB/OrbSync/OrbStatusEvent.cs
2020-08-29 22:49:29 +01:00

38 lines
1.1 KiB
C#

using OWML.ModHelper.Events;
using QSB.Events;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.OrbSync
{
public class OrbStatusEvent : QSBEvent<BoolWorldObjectMessage>
{
public override EventType Type => EventType.OrbStatus;
public override void SetupListener()
{
GlobalMessenger<int, bool>.AddListener(EventNames.QSBOrbStatus, Handler);
}
public override void CloseListener()
{
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBOrbStatus, Handler);
}
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
{
AboutId = LocalPlayerId,
ObjectId = id,
State = state
};
public override void OnReceiveRemote(BoolWorldObjectMessage message)
{
var orb = WorldRegistry.OldOrbList[message.ObjectId];
orb.SetValue("_isBeingDragged", true);
}
}
}