2022-03-04 11:46:10 +00:00
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
|
using QSB.EchoesOfTheEye.SlideProjectors.Messages;
|
2022-03-03 04:47:32 +00:00
|
|
|
|
using QSB.Messaging;
|
2022-03-04 11:46:10 +00:00
|
|
|
|
using QSB.Player;
|
2022-01-21 21:54:58 +00:00
|
|
|
|
using QSB.WorldSync;
|
2022-03-04 11:46:10 +00:00
|
|
|
|
using System.Threading;
|
2022-01-21 21:54:58 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.EchoesOfTheEye.SlideProjectors.WorldObjects;
|
|
|
|
|
|
|
|
|
|
public class QSBSlideProjector : WorldObject<SlideProjector>
|
2022-01-21 21:54:58 +00:00
|
|
|
|
{
|
2022-03-03 04:47:32 +00:00
|
|
|
|
private uint _user;
|
2022-01-21 21:54:58 +00:00
|
|
|
|
|
2022-03-04 11:46:10 +00:00
|
|
|
|
public override async UniTask Init(CancellationToken ct) =>
|
|
|
|
|
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
|
|
|
|
|
|
|
|
|
|
public override void OnRemoval() =>
|
|
|
|
|
QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave;
|
|
|
|
|
|
2022-10-07 03:57:14 +00:00
|
|
|
|
private void OnPlayerLeave(PlayerInfo player)
|
2022-08-20 19:09:50 +00:00
|
|
|
|
{
|
|
|
|
|
if (!QSBCore.IsHost)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-10-07 03:57:14 +00:00
|
|
|
|
if (_user == player.PlayerId)
|
|
|
|
|
{
|
|
|
|
|
this.SendMessage(new UseSlideProjectorMessage(false));
|
|
|
|
|
}
|
2022-08-20 19:09:50 +00:00
|
|
|
|
}
|
2022-03-04 11:46:10 +00:00
|
|
|
|
|
2022-03-03 04:47:32 +00:00
|
|
|
|
public override void SendInitialState(uint to) =>
|
2022-03-04 10:57:31 +00:00
|
|
|
|
this.SendMessage(new UseSlideProjectorMessage(_user) { To = to });
|
2022-01-30 09:43:20 +00:00
|
|
|
|
|
2022-03-03 04:47:32 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// called both locally and remotely
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void SetUser(uint user)
|
2022-03-03 03:46:33 +00:00
|
|
|
|
{
|
2022-03-03 04:47:32 +00:00
|
|
|
|
AttachedObject._interactReceiver.SetInteractionEnabled(user == 0 || user == _user);
|
|
|
|
|
_user = user;
|
2022-08-20 19:46:59 +00:00
|
|
|
|
|
|
|
|
|
if (user != 0)
|
|
|
|
|
{
|
|
|
|
|
if (AttachedObject._slideItem != null && AttachedObject.IsProjectorFullyLit())
|
|
|
|
|
{
|
|
|
|
|
AttachedObject._slideItem.slidesContainer.TryPlayMusicForCurrentSlideInclusive();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Locator.GetSlideReelMusicManager().OnExitSlideProjector();
|
|
|
|
|
}
|
2022-03-03 03:46:33 +00:00
|
|
|
|
}
|
2022-03-03 04:47:32 +00:00
|
|
|
|
}
|