2020-09-04 20:54:34 +01:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
using QSB.WorldSync;
|
|
|
|
|
|
|
|
|
|
namespace QSB.OrbSync
|
|
|
|
|
{
|
|
|
|
|
public class OrbSlotEvent : QSBEvent<BoolWorldObjectMessage>
|
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.OrbSlot;
|
|
|
|
|
|
2020-09-05 15:46:20 +01:00
|
|
|
|
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBOrbSlot, Handler);
|
2020-09-04 20:54:34 +01:00
|
|
|
|
|
2020-09-05 15:46:20 +01:00
|
|
|
|
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBOrbSlot, Handler);
|
2020-09-04 20:54:34 +01:00
|
|
|
|
|
|
|
|
|
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 orbSlot = WorldRegistry.GetObject<QSBOrbSlot>(message.ObjectId);
|
|
|
|
|
orbSlot?.SetState(message.State);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|