mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-10 15:53:19 +00:00
d7c0c06698
* refactoring
60 lines
2.1 KiB
C#
60 lines
2.1 KiB
C#
using OWML.ModHelper.Events;
|
|
using QSB.Messaging;
|
|
using UnityEngine;
|
|
|
|
namespace QSB
|
|
{
|
|
public class WakeUpSync : MonoBehaviour
|
|
{
|
|
public static bool IsServer;
|
|
private MessageHandler<WakeUpMessage> _wakeUpHandler;
|
|
|
|
private void Start()
|
|
{
|
|
DebugLog.Screen("Start WakeUpSync");
|
|
GlobalMessenger.AddListener("WakeUp", OnWakeUp);
|
|
_wakeUpHandler = new MessageHandler<WakeUpMessage>();
|
|
_wakeUpHandler.OnClientReceiveMessage += OnClientReceiveMessage;
|
|
}
|
|
|
|
private void OnWakeUp()
|
|
{
|
|
DebugLog.Screen("Sending wakeup to all my friends");
|
|
if (IsServer)
|
|
{
|
|
_wakeUpHandler.SendToAll(new WakeUpMessage());
|
|
}
|
|
}
|
|
|
|
private void OnClientReceiveMessage(WakeUpMessage message)
|
|
{
|
|
if (IsServer)
|
|
{
|
|
return;
|
|
}
|
|
|
|
// I copied all of this from my AutoResume mod, since that already wakes up the player instantly.
|
|
// There must be a simpler way to do this though, I just couldn't find it.
|
|
|
|
// Skip wake up animation.
|
|
var cameraEffectController = FindObjectOfType<PlayerCameraEffectController>();
|
|
cameraEffectController.OpenEyes(0, true);
|
|
cameraEffectController.SetValue("_wakeLength", 0f);
|
|
cameraEffectController.SetValue("_waitForWakeInput", false);
|
|
|
|
// Skip wake up prompt.
|
|
LateInitializerManager.pauseOnInitialization = false;
|
|
Locator.GetPauseCommandListener().RemovePauseCommandLock();
|
|
Locator.GetPromptManager().RemoveScreenPrompt(cameraEffectController.GetValue<ScreenPrompt>("_wakePrompt"));
|
|
OWTime.Unpause(OWTime.PauseType.Sleeping);
|
|
cameraEffectController.Invoke("WakeUp");
|
|
|
|
// Enable all inputs immediately.
|
|
OWInput.ChangeInputMode(InputMode.Character);
|
|
typeof(OWInput).SetValue("_inputFadeFraction", 0f);
|
|
GlobalMessenger.FireEvent("TakeFirstFlashbackSnapshot");
|
|
}
|
|
|
|
}
|
|
}
|