mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-06 01:00:16 +00:00
elevator
This commit is contained in:
parent
347f8d1945
commit
af82e29e4c
@ -1,29 +0,0 @@
|
||||
using QSB.ElevatorSync.WorldObjects;
|
||||
using QSB.Events;
|
||||
using QSB.WorldSync;
|
||||
using QSB.WorldSync.Events;
|
||||
|
||||
namespace QSB.ElevatorSync.Messages
|
||||
{
|
||||
public class ElevatorEvent : QSBEvent<BoolWorldObjectMessage>
|
||||
{
|
||||
public override bool RequireWorldObjectsReady => true;
|
||||
|
||||
public override void SetupListener() => GlobalMessenger<int, bool>.AddListener(EventNames.QSBStartLift, Handler);
|
||||
public override void CloseListener() => GlobalMessenger<int, bool>.RemoveListener(EventNames.QSBStartLift, Handler);
|
||||
|
||||
private void Handler(int id, bool isGoingUp) => SendEvent(CreateMessage(id, isGoingUp));
|
||||
|
||||
private BoolWorldObjectMessage CreateMessage(int id, bool isGoingUp) => new()
|
||||
{
|
||||
State = isGoingUp,
|
||||
ObjectId = id
|
||||
};
|
||||
|
||||
public override void OnReceiveRemote(bool server, BoolWorldObjectMessage message)
|
||||
{
|
||||
var elevator = QSBWorldSync.GetWorldFromId<QSBElevator>(message.ObjectId);
|
||||
elevator?.RemoteCall(message.State);
|
||||
}
|
||||
}
|
||||
}
|
14
QSB/ElevatorSync/Messages/ElevatorMessage.cs
Normal file
14
QSB/ElevatorSync/Messages/ElevatorMessage.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using QSB.ElevatorSync.WorldObjects;
|
||||
using QSB.Messaging;
|
||||
|
||||
namespace QSB.ElevatorSync.Messages
|
||||
{
|
||||
public class ElevatorMessage : QSBBoolWorldObjectMessage<QSBElevator>
|
||||
{
|
||||
public ElevatorMessage(bool isGoingUp) => Value = isGoingUp;
|
||||
|
||||
public ElevatorMessage() { }
|
||||
|
||||
public override void OnReceiveRemote() => WorldObject.RemoteCall(Value);
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
using HarmonyLib;
|
||||
using OWML.Utils;
|
||||
using QSB.ElevatorSync.Messages;
|
||||
using QSB.ElevatorSync.WorldObjects;
|
||||
using QSB.Events;
|
||||
using QSB.Messaging;
|
||||
using QSB.Patches;
|
||||
using QSB.WorldSync;
|
||||
|
||||
@ -16,9 +18,9 @@ namespace QSB.ElevatorSync.Patches
|
||||
[HarmonyPatch(typeof(Elevator), nameof(Elevator.StartLift))]
|
||||
public static void Elevator_StartLift(Elevator __instance)
|
||||
{
|
||||
var isGoingUp = __instance.GetValue<bool>("_goingToTheEnd");
|
||||
var id = QSBWorldSync.GetIdFromUnity<QSBElevator>(__instance);
|
||||
QSBEventManager.FireEvent(EventNames.QSBStartLift, id, isGoingUp);
|
||||
var isGoingUp = __instance._goingToTheEnd;
|
||||
var qsbElevator = QSBWorldSync.GetWorldFromUnity<QSBElevator>(__instance);
|
||||
qsbElevator.SendMessage(new ElevatorMessage(isGoingUp));
|
||||
}
|
||||
}
|
||||
}
|
@ -27,7 +27,6 @@
|
||||
|
||||
// Custom event names -- change if you want! These can be anything, as long as both
|
||||
// sides of the GlobalMessenger (fireevent and addlistener) reference the same thing.
|
||||
public const string QSBStartLift = nameof(QSBStartLift);
|
||||
public const string QSBGeyserState = nameof(QSBGeyserState);
|
||||
public const string QSBConversation = nameof(QSBConversation);
|
||||
public const string QSBConversationStartEnd = nameof(QSBConversationStartEnd);
|
||||
|
Loading…
Reference in New Issue
Block a user