From ca38f789fed418c36bd997cf7fe3a1a82a0c5d9e Mon Sep 17 00:00:00 2001
From: Mister_Nebula <41904486+misternebula@users.noreply.github.com>
Date: Sun, 1 Nov 2020 12:11:36 +0000
Subject: [PATCH] add events
---
QSB/Events/EventList.cs | 7 +++---
QSB/Events/EventNames.cs | 1 +
QSB/Instruments/Events/PlayInstrumentEvent.cs | 23 +++++++++++++++++
.../Events/PlayInstrumentMessage.cs | 25 +++++++++++++++++++
QSB/Instruments/InstrumentType.cs | 17 +++++++++++++
QSB/QSB.csproj | 3 +++
6 files changed, 72 insertions(+), 4 deletions(-)
create mode 100644 QSB/Instruments/Events/PlayInstrumentEvent.cs
create mode 100644 QSB/Instruments/Events/PlayInstrumentMessage.cs
create mode 100644 QSB/Instruments/InstrumentType.cs
diff --git a/QSB/Events/EventList.cs b/QSB/Events/EventList.cs
index 39aeac52..cb848797 100644
--- a/QSB/Events/EventList.cs
+++ b/QSB/Events/EventList.cs
@@ -3,6 +3,7 @@ using QSB.ConversationSync;
using QSB.DeathSync;
using QSB.ElevatorSync;
using QSB.GeyserSync;
+using QSB.Instruments.Events;
using QSB.OrbSync;
using QSB.TimeSync;
using QSB.Tools;
@@ -11,9 +12,6 @@ using System.Collections.Generic;
namespace QSB.Events
{
- ///
- /// Creates instances of all of the events QSB uses.
- ///
public static class EventList
{
public static bool Ready { get; private set; }
@@ -43,7 +41,8 @@ namespace QSB.Events
new OrbSlotEvent(),
new OrbUserEvent(),
new ConversationEvent(),
- new ConversationStartEndEvent()
+ new ConversationStartEndEvent(),
+ new PlayInstrumentEvent()
};
_eventList.ForEach(ev => ev.SetupListener());
diff --git a/QSB/Events/EventNames.cs b/QSB/Events/EventNames.cs
index 23a60a4e..8d687c31 100644
--- a/QSB/Events/EventNames.cs
+++ b/QSB/Events/EventNames.cs
@@ -34,5 +34,6 @@
public static string QSBOrbUser = "QSBOrbUser";
public static string QSBConversation = "QSBConversation";
public static string QSBConversationStartEnd = "QSBConversationStartEnd";
+ public static string QSBPlayInstrument = "QSBPlayInstrument";
}
}
diff --git a/QSB/Instruments/Events/PlayInstrumentEvent.cs b/QSB/Instruments/Events/PlayInstrumentEvent.cs
new file mode 100644
index 00000000..db0312dc
--- /dev/null
+++ b/QSB/Instruments/Events/PlayInstrumentEvent.cs
@@ -0,0 +1,23 @@
+using QSB.Events;
+using QSB.Messaging;
+
+namespace QSB.Instruments.Events
+{
+ public class PlayInstrumentEvent : QSBEvent
+ {
+ public override EventType Type => EventType.FullStateRequest;
+
+ public override void SetupListener() => GlobalMessenger.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
+
+ public override void CloseListener() => GlobalMessenger.RemoveListener(EventNames.QSBPlayerStatesRequest, Handler);
+
+ private void Handler(InstrumentType type, bool state) => SendEvent(CreateMessage(type, state));
+
+ private PlayInstrumentMessage CreateMessage(InstrumentType type, bool state) => new PlayInstrumentMessage
+ {
+ AboutId = LocalPlayerId,
+ Type = type,
+ State = state
+ };
+ }
+}
diff --git a/QSB/Instruments/Events/PlayInstrumentMessage.cs b/QSB/Instruments/Events/PlayInstrumentMessage.cs
new file mode 100644
index 00000000..0f4c3627
--- /dev/null
+++ b/QSB/Instruments/Events/PlayInstrumentMessage.cs
@@ -0,0 +1,25 @@
+using QSB.Messaging;
+using UnityEngine.Networking;
+
+namespace QSB.Instruments.Events
+{
+ public class PlayInstrumentMessage : PlayerMessage
+ {
+ public InstrumentType Type;
+ public bool State;
+
+ public override void Deserialize(NetworkReader reader)
+ {
+ base.Deserialize(reader);
+ Type = (InstrumentType)reader.ReadInt32();
+ State = reader.ReadBoolean();
+ }
+
+ public override void Serialize(NetworkWriter writer)
+ {
+ base.Serialize(writer);
+ writer.Write((int)Type);
+ writer.Write(State);
+ }
+ }
+}
diff --git a/QSB/Instruments/InstrumentType.cs b/QSB/Instruments/InstrumentType.cs
new file mode 100644
index 00000000..9401d84a
--- /dev/null
+++ b/QSB/Instruments/InstrumentType.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace QSB.Instruments
+{
+ public enum InstrumentType
+ {
+ CHERT,
+ ESKER,
+ FELDSPAR,
+ GABBRO,
+ REIBECK,
+ SOLANUM
+ }
+}
\ No newline at end of file
diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj
index 68c9ca7a..404297f2 100644
--- a/QSB/QSB.csproj
+++ b/QSB/QSB.csproj
@@ -148,6 +148,9 @@
+
+
+