quantum-space-buddies/QSB/DeathSync/Events/StartLoopEvent.cs

42 lines
1.3 KiB
C#
Raw Normal View History

2021-08-08 19:01:21 +00:00
using QSB.ClientServerStateSync;
using QSB.Events;
using QSB.Messaging;
using QSB.Utility;
namespace QSB.DeathSync.Events
{
2021-08-09 10:49:58 +00:00
internal class StartLoopEvent : QSBEvent<PlayerMessage>
2021-08-08 19:01:21 +00:00
{
public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBStartLoop, Handler);
public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBStartLoop, Handler);
private void Handler() => SendEvent(CreateMessage());
2021-11-20 19:49:50 +00:00
private PlayerMessage CreateMessage() => new()
2021-08-08 19:01:21 +00:00
{
AboutId = LocalPlayerId
};
public override void OnReceiveLocal(bool server, PlayerMessage message)
=> OnReceiveRemote(server, message);
public override void OnReceiveRemote(bool server, PlayerMessage message)
{
DebugLog.DebugWrite($" ~~~ LOOP START ~~~");
2021-11-12 21:05:58 +00:00
if (QSBSceneManager.CurrentScene == OWScene.SolarSystem)
{
QSBEventManager.FireEvent(EventNames.QSBClientState, ClientState.AliveInSolarSystem);
}
else if (QSBSceneManager.CurrentScene == OWScene.EyeOfTheUniverse)
{
QSBEventManager.FireEvent(EventNames.QSBClientState, ClientState.AliveInEye);
}
else
{
DebugLog.ToConsole($"Error - Got StartLoop event when not in universe!", OWML.Common.MessageType.Error);
QSBEventManager.FireEvent(EventNames.QSBClientState, ClientState.NotLoaded);
}
2021-08-08 19:01:21 +00:00
}
}
}