quantum-space-buddies/QSB/OrbSync/OrbSlotEvent.cs

38 lines
1.0 KiB
C#
Raw Normal View History

2020-08-26 19:50:30 +00:00
using QSB.Events;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.OrbSync
{
2020-08-26 20:12:57 +00:00
public class OrbSlotEvent : QSBEvent<BoolWorldObjectMessage>
2020-08-26 19:50:30 +00:00
{
public override EventType Type => EventType.OrbSlot;
public override void SetupListener()
{
GlobalMessenger<int, bool>.AddListener(EventNames.QSBOrbSlot, Handler);
}
public override void CloseListener()
{
GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBOrbSlot, Handler);
}
private void Handler(int id, bool state) => SendEvent(CreateMessage(id, state));
2020-08-26 20:12:57 +00:00
private BoolWorldObjectMessage CreateMessage(int id, bool state) => new BoolWorldObjectMessage
2020-08-26 19:50:30 +00:00
{
AboutId = LocalPlayerId,
ObjectId = id,
State = state
};
2020-08-26 20:12:57 +00:00
public override void OnReceiveRemote(BoolWorldObjectMessage message)
2020-08-26 19:50:30 +00:00
{
2020-08-26 19:50:30 +00:00
var orbSlot = WorldRegistry.GetObject<QSBOrbSlot>(message.ObjectId);
orbSlot?.SetState(message.State);
}
}
}