quantum-space-buddies/QSB/Animation/PlayerSuitEvent.cs

43 lines
1.3 KiB
C#
Raw Normal View History

2020-08-13 19:46:16 +00:00
using QSB.Events;
using QSB.Messaging;
2020-08-09 20:46:51 +00:00
2020-08-13 19:46:16 +00:00
namespace QSB.Animation
2020-08-09 20:46:51 +00:00
{
2020-08-10 16:17:54 +00:00
public class PlayerSuitEvent : QSBEvent<ToggleMessage>
2020-08-09 20:46:51 +00:00
{
public override MessageType Type => MessageType.SuitActiveChange;
public override void SetupListener()
{
2020-08-15 19:52:43 +00:00
GlobalMessenger.AddListener(EventNames.SuitUp, HandleSuitUp);
GlobalMessenger.AddListener(EventNames.RemoveSuit, HandleSuitDown);
2020-08-09 20:46:51 +00:00
}
2020-08-15 19:55:25 +00:00
2020-08-15 19:32:58 +00:00
public override void CloseListener()
{
2020-08-15 19:52:43 +00:00
GlobalMessenger.RemoveListener(EventNames.SuitUp, HandleSuitUp);
GlobalMessenger.RemoveListener(EventNames.RemoveSuit, HandleSuitDown);
2020-08-15 19:32:58 +00:00
}
2020-08-15 19:52:43 +00:00
private void HandleSuitUp() => SendEvent(CreateMessage(true));
private void HandleSuitDown() => SendEvent(CreateMessage(false));
2020-08-10 16:17:54 +00:00
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
{
2020-08-17 15:51:56 +00:00
AboutId = LocalPlayerId,
2020-08-10 16:17:54 +00:00
ToggleValue = value
};
2020-08-10 13:40:06 +00:00
public override void OnReceiveRemote(ToggleMessage message)
2020-08-09 20:46:51 +00:00
{
2020-08-17 15:51:56 +00:00
var player = PlayerRegistry.GetPlayer(message.AboutId);
player?.UpdateState(State.Suit, message.ToggleValue);
2020-08-09 20:46:51 +00:00
}
public override void OnReceiveLocal(ToggleMessage message)
{
PlayerRegistry.LocalPlayer.UpdateState(State.Suit, message.ToggleValue);
}
}
}