2020-08-13 19:46:16 +00:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
2020-08-09 07:17:00 +00:00
|
|
|
|
|
2020-08-13 19:46:16 +00:00
|
|
|
|
namespace QSB.Tools
|
2020-08-07 23:08:44 +00:00
|
|
|
|
{
|
2020-08-10 16:17:54 +00:00
|
|
|
|
public class PlayerFlashlightEvent : QSBEvent<ToggleMessage>
|
2020-08-07 23:08:44 +00:00
|
|
|
|
{
|
2020-08-09 07:17:00 +00:00
|
|
|
|
public override MessageType Type => MessageType.FlashlightActiveChange;
|
2020-08-07 23:08:44 +00:00
|
|
|
|
|
2020-08-08 11:23:23 +00:00
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-15 19:52:43 +00:00
|
|
|
|
GlobalMessenger.AddListener(EventNames.TurnOnFlashlight, HandleTurnOn);
|
|
|
|
|
GlobalMessenger.AddListener(EventNames.TurnOffFlashlight, HandleTurnOff);
|
2020-08-08 11:23:23 +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.TurnOnFlashlight, HandleTurnOn);
|
|
|
|
|
GlobalMessenger.RemoveListener(EventNames.TurnOffFlashlight, HandleTurnOff);
|
2020-08-15 19:32:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-15 19:52:43 +00:00
|
|
|
|
private void HandleTurnOn() => SendEvent(CreateMessage(true));
|
|
|
|
|
private void HandleTurnOff() => SendEvent(CreateMessage(false));
|
2020-08-15 19:55:25 +00:00
|
|
|
|
|
2020-08-10 16:17:54 +00:00
|
|
|
|
private ToggleMessage CreateMessage(bool value) => new ToggleMessage
|
|
|
|
|
{
|
2020-08-17 15:51:56 +00:00
|
|
|
|
FromId = LocalPlayerId,
|
|
|
|
|
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-07 23:08:44 +00:00
|
|
|
|
{
|
2020-08-17 15:51:56 +00:00
|
|
|
|
var player = PlayerRegistry.GetPlayer(message.AboutId);
|
2020-08-16 20:39:21 +00:00
|
|
|
|
player?.UpdateState(State.Flashlight, message.ToggleValue);
|
|
|
|
|
if (!QSBSceneManager.IsInUniverse)
|
2020-08-10 18:25:10 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-16 20:39:21 +00:00
|
|
|
|
player?.FlashLight?.UpdateState(message.ToggleValue);
|
2020-08-07 23:08:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-09 07:37:32 +00:00
|
|
|
|
public override void OnReceiveLocal(ToggleMessage message)
|
2020-08-07 23:08:44 +00:00
|
|
|
|
{
|
2020-08-09 21:10:47 +00:00
|
|
|
|
PlayerRegistry.LocalPlayer.UpdateState(State.Flashlight, message.ToggleValue);
|
2020-08-07 23:08:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|