2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-12-14 16:28:03 +00:00
|
|
|
|
using QSB.Messaging;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-08-09 09:17:00 +02:00
|
|
|
|
|
2020-11-03 17:56:48 +00:00
|
|
|
|
namespace QSB.Tools.Events
|
2020-08-08 00:08:44 +01:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class PlayerFlashlightEvent : QSBEvent<ToggleMessage>
|
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.FlashlightActiveChange;
|
2020-08-08 00:08:44 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger.AddListener(EventNames.TurnOnFlashlight, HandleTurnOn);
|
|
|
|
|
GlobalMessenger.AddListener(EventNames.TurnOffFlashlight, HandleTurnOff);
|
|
|
|
|
}
|
2020-08-15 21:55:25 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.TurnOnFlashlight, HandleTurnOn);
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.TurnOffFlashlight, HandleTurnOff);
|
|
|
|
|
}
|
2020-08-15 20:32:58 +01:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void HandleTurnOn() => SendEvent(CreateMessage(true));
|
|
|
|
|
private void HandleTurnOff() => SendEvent(CreateMessage(false));
|
2020-08-15 21:55:25 +02:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
ToggleValue = value
|
|
|
|
|
};
|
2020-08-10 18:17:54 +02:00
|
|
|
|
|
2020-12-11 22:42:21 +00:00
|
|
|
|
public override void OnReceiveRemote(bool server, ToggleMessage message)
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
var player = QSBPlayerManager.GetPlayer(message.AboutId);
|
2021-04-18 18:42:22 +01:00
|
|
|
|
player.PlayerStates.FlashlightActive = message.ToggleValue;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
player.FlashLight?.UpdateState(message.ToggleValue);
|
|
|
|
|
}
|
2020-08-08 00:08:44 +01:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
public override void OnReceiveLocal(bool server, ToggleMessage message) =>
|
2021-04-18 18:42:22 +01:00
|
|
|
|
QSBPlayerManager.LocalPlayer.PlayerStates.FlashlightActive = message.ToggleValue;
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|