93 lines
2.6 KiB
C#
Raw Normal View History

using Cysharp.Threading.Tasks;
using QSB.EchoesOfTheEye.SlideProjectors.Messages;
2022-03-02 20:47:32 -08:00
using QSB.Messaging;
using QSB.Player;
2022-01-21 21:54:58 +00:00
using QSB.Utility;
using QSB.WorldSync;
using System.Threading;
2022-01-21 21:54:58 +00:00
2022-03-02 19:46:33 -08:00
namespace QSB.EchoesOfTheEye.SlideProjectors.WorldObjects;
public class QSBSlideProjector : WorldObject<SlideProjector>
2022-01-21 21:54:58 +00:00
{
2022-03-02 20:47:32 -08:00
private uint _user;
2022-01-21 21:54:58 +00:00
public override async UniTask Init(CancellationToken ct) =>
QSBPlayerManager.OnRemovePlayer += OnPlayerLeave;
public override void OnRemoval() =>
QSBPlayerManager.OnRemovePlayer -= OnPlayerLeave;
private void OnPlayerLeave(PlayerInfo obj) =>
this.SendMessage(new UseSlideProjectorMessage(false));
2022-03-02 20:47:32 -08:00
public override void SendInitialState(uint to) =>
2022-03-04 02:57:31 -08:00
this.SendMessage(new UseSlideProjectorMessage(_user) { To = to });
2022-01-30 09:43:20 +00:00
2022-03-02 20:47:32 -08:00
/// <summary>
/// called both locally and remotely
/// </summary>
public void SetUser(uint user)
2022-03-02 19:46:33 -08:00
{
2022-03-02 20:47:32 -08:00
DebugLog.DebugWrite($"{this} - user = {user}");
AttachedObject._interactReceiver.SetInteractionEnabled(user == 0 || user == _user);
_user = user;
2022-03-02 19:46:33 -08:00
}
2022-03-02 19:46:33 -08:00
public void NextSlide()
{
var hasChangedSlide = false;
if (AttachedObject._slideItem != null && AttachedObject._slideItem.slidesContainer.NextSlideAvailable())
2022-01-30 09:43:20 +00:00
{
2022-03-02 19:46:33 -08:00
hasChangedSlide = AttachedObject._slideItem.slidesContainer.IncreaseSlideIndex();
if (hasChangedSlide)
2022-02-01 10:44:41 +00:00
{
2022-03-02 19:46:33 -08:00
if (AttachedObject._oneShotSource != null)
2022-02-01 10:44:41 +00:00
{
2022-03-02 19:46:33 -08:00
AttachedObject._oneShotSource.PlayOneShot(AudioType.Projector_Next);
}
2022-02-01 10:44:41 +00:00
2022-03-02 19:46:33 -08:00
if (AttachedObject.IsProjectorFullyLit())
{
AttachedObject._slideItem.slidesContainer.SetCurrentRead();
AttachedObject._slideItem.slidesContainer.TryPlayMusicForCurrentSlideTransition(true);
2022-02-01 10:44:41 +00:00
}
}
2022-03-02 19:46:33 -08:00
}
2022-02-01 10:44:41 +00:00
2022-03-02 19:46:33 -08:00
if (AttachedObject._gearInterface != null)
{
var audioVolume = hasChangedSlide ? 0f : 0.5f;
AttachedObject._gearInterface.AddRotation(45f, audioVolume);
2022-02-01 10:44:41 +00:00
}
2022-03-02 19:46:33 -08:00
}
2022-02-01 10:44:41 +00:00
2022-03-02 19:46:33 -08:00
public void PreviousSlide()
{
var hasChangedSlide = false;
if (AttachedObject._slideItem != null && AttachedObject._slideItem.slidesContainer.PrevSlideAvailable())
2022-02-01 10:44:41 +00:00
{
2022-03-02 19:46:33 -08:00
hasChangedSlide = AttachedObject._slideItem.slidesContainer.DecreaseSlideIndex();
if (hasChangedSlide)
2022-02-01 10:44:41 +00:00
{
2022-03-02 19:46:33 -08:00
if (AttachedObject._oneShotSource != null)
2022-02-01 10:44:41 +00:00
{
2022-03-02 19:46:33 -08:00
AttachedObject._oneShotSource.PlayOneShot(AudioType.Projector_Prev);
}
2022-02-01 10:44:41 +00:00
2022-03-02 19:46:33 -08:00
if (AttachedObject.IsProjectorFullyLit())
{
AttachedObject._slideItem.slidesContainer.SetCurrentRead();
AttachedObject._slideItem.slidesContainer.TryPlayMusicForCurrentSlideTransition(false);
2022-02-01 10:44:41 +00:00
}
}
2022-03-02 19:46:33 -08:00
}
2022-02-01 10:44:41 +00:00
2022-03-02 19:46:33 -08:00
if (AttachedObject._gearInterface != null)
{
var audioVolume = hasChangedSlide ? 0f : 0.5f;
AttachedObject._gearInterface.AddRotation(-45f, audioVolume);
2022-01-21 21:54:58 +00:00
}
}
2022-03-02 20:47:32 -08:00
}