mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-09 03:40:46 +00:00
34 lines
954 B
C#
34 lines
954 B
C#
using QSB.Messaging;
|
|
|
|
namespace QSB.Events
|
|
{
|
|
public class PlayerReadyEvent : QSBEvent<ToggleMessage>
|
|
{
|
|
public override EventType Type => EventType.PlayerReady;
|
|
|
|
public override void SetupListener()
|
|
{
|
|
GlobalMessenger<bool>.AddListener(EventNames.QSBPlayerReady, Handler);
|
|
}
|
|
|
|
public override void CloseListener()
|
|
{
|
|
GlobalMessenger<bool>.RemoveListener(EventNames.QSBPlayerReady, Handler);
|
|
}
|
|
|
|
private void Handler(bool ready) => SendEvent(CreateMessage(ready));
|
|
|
|
private ToggleMessage CreateMessage(bool ready) => new ToggleMessage
|
|
{
|
|
AboutId = LocalPlayerId,
|
|
ToggleValue = ready
|
|
};
|
|
|
|
public override void OnServerReceive(ToggleMessage message)
|
|
{
|
|
PlayerRegistry.GetPlayer(message.AboutId).IsReady = message.ToggleValue;
|
|
PlayerState.LocalInstance.Send();
|
|
}
|
|
}
|
|
}
|