quantum-space-buddies/QSB/TimeSync/Events/ServerTimeEvent.cs

24 lines
807 B
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-08-09 18:33:36 +00:00
2020-11-03 17:56:48 +00:00
namespace QSB.TimeSync.Events
2020-08-09 18:33:36 +00:00
{
2020-12-02 21:23:01 +00:00
public class ServerTimeEvent : QSBEvent<ServerTimeMessage>
{
public override bool RequireWorldObjectsReady => false;
2020-12-02 21:23:01 +00:00
public override void SetupListener() => GlobalMessenger<float, int>.AddListener(EventNames.QSBServerTime, Handler);
public override void CloseListener() => GlobalMessenger<float, int>.RemoveListener(EventNames.QSBServerTime, Handler);
2020-08-15 19:32:58 +00:00
2020-12-02 21:23:01 +00:00
private void Handler(float time, int count) => SendEvent(CreateMessage(time, count));
2020-08-15 19:52:43 +00:00
2021-11-20 19:49:50 +00:00
private ServerTimeMessage CreateMessage(float time, int count) => new()
2020-12-02 21:23:01 +00:00
{
AboutId = LocalPlayerId,
ServerTime = time,
LoopCount = count
};
2020-08-10 16:17:54 +00:00
2020-12-14 21:20:53 +00:00
public override void OnReceiveRemote(bool server, ServerTimeMessage message) =>
WakeUpSync.LocalInstance.OnClientReceiveMessage(message);
}
2020-12-03 08:28:05 +00:00
}