mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-04 12:39:52 +00:00
Merge pull request #492 from misternebula/picture-frame-doors
Add picture frame door sync
This commit is contained in:
commit
c9f01fc269
@ -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);
|
||||||
|
}
|
@ -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()));
|
||||||
|
}
|
@ -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>();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
using QSB.WorldSync;
|
||||||
|
|
||||||
|
namespace QSB.EchoesOfTheEye.PictureFrameDoors.WorldObjects;
|
||||||
|
|
||||||
|
internal interface IQSBPictureFrameDoor : IWorldObject
|
||||||
|
{
|
||||||
|
public void SetOpenState(bool open);
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user