Merge pull request #492 from misternebula/picture-frame-doors

Add picture frame door sync
This commit is contained in:
_nebula 2022-03-11 16:41:37 +00:00 committed by GitHub
commit c9f01fc269
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,12 @@
using QSB.EchoesOfTheEye.PictureFrameDoors.WorldObjects;
using QSB.Messaging;
namespace QSB.EchoesOfTheEye.PictureFrameDoors.Messages;
internal class PictureFrameDoorMessage : QSBWorldObjectMessage<IQSBPictureFrameDoor, bool>
{
public PictureFrameDoorMessage(bool open) : base(open) { }
public override void OnReceiveRemote()
=> WorldObject.SetOpenState(Data);
}

View File

@ -0,0 +1,18 @@
using HarmonyLib;
using QSB.EchoesOfTheEye.PictureFrameDoors.Messages;
using QSB.EchoesOfTheEye.PictureFrameDoors.WorldObjects;
using QSB.Messaging;
using QSB.Patches;
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.PictureFrameDoors.Patches;
internal class PictureFrameDoorInterfacePatches : QSBPatch
{
public override QSBPatchTypes Type => QSBPatchTypes.OnClientConnect;
[HarmonyPostfix]
[HarmonyPatch(typeof(PictureFrameDoorInterface), nameof(PictureFrameDoorInterface.ToggleOpenState))]
public static void ToggleOpenState(PictureFrameDoorInterface __instance)
=> __instance.GetWorldObject<IQSBPictureFrameDoor>().SendMessage(new PictureFrameDoorMessage(__instance._door.IsOpen()));
}

View File

@ -0,0 +1,17 @@
using Cysharp.Threading.Tasks;
using QSB.EchoesOfTheEye.PictureFrameDoors.WorldObjects;
using QSB.WorldSync;
using System.Threading;
namespace QSB.EchoesOfTheEye.PictureFrameDoors;
internal class PictureFrameDoorsManager : WorldObjectManager
{
public override WorldObjectScene WorldObjectScene => WorldObjectScene.SolarSystem;
public override async UniTask BuildWorldObjects(OWScene scene, CancellationToken ct)
{
QSBWorldSync.Init<QSBPictureFrameDoorInterface, PictureFrameDoorInterface>(typeof(GlitchedCodeDoorInterface));
QSBWorldSync.Init<QSBGlitchedCodeDoorInterface, GlitchedCodeDoorInterface>();
}
}

View File

@ -0,0 +1,8 @@
using QSB.WorldSync;
namespace QSB.EchoesOfTheEye.PictureFrameDoors.WorldObjects;
internal interface IQSBPictureFrameDoor : IWorldObject
{
public void SetOpenState(bool open);
}

View File

@ -0,0 +1,26 @@
namespace QSB.EchoesOfTheEye.PictureFrameDoors.WorldObjects;
internal class QSBGlitchedCodeDoorInterface : QSBPictureFrameDoor<GlitchedCodeDoorInterface>
{
public override void SetOpenState(bool open)
{
if (AttachedObject._door.IsOpen() == open)
{
AttachedObject.UpdatePrompt();
AttachedObject.CheckPlayGlitchAudio();
return;
}
if (open)
{
AttachedObject._door.Open();
}
else
{
AttachedObject._door.Close();
}
AttachedObject.UpdatePrompt();
AttachedObject.CheckPlayGlitchAudio();
}
}

View File

@ -0,0 +1,15 @@
using QSB.EchoesOfTheEye.PictureFrameDoors.Messages;
using QSB.Messaging;
using QSB.WorldSync;
using UnityEngine;
namespace QSB.EchoesOfTheEye.PictureFrameDoors.WorldObjects;
public abstract class QSBPictureFrameDoor<T> : WorldObject<T>, IQSBPictureFrameDoor
where T : MonoBehaviour
{
public override void SendInitialState(uint to)
=> (this as IQSBPictureFrameDoor).SendMessage(new PictureFrameDoorMessage((AttachedObject as PictureFrameDoorInterface)._door.IsOpen()));
public abstract void SetOpenState(bool open);
}

View File

@ -0,0 +1,24 @@
namespace QSB.EchoesOfTheEye.PictureFrameDoors.WorldObjects;
internal class QSBPictureFrameDoorInterface : QSBPictureFrameDoor<PictureFrameDoorInterface>
{
public override void SetOpenState(bool open)
{
if (AttachedObject._door.IsOpen() == open)
{
AttachedObject.UpdatePrompt();
return;
}
if (open)
{
AttachedObject._door.Open();
}
else
{
AttachedObject._door.Close();
}
AttachedObject.UpdatePrompt();
}
}