add events

This commit is contained in:
Mister_Nebula 2020-11-01 12:11:36 +00:00
parent 36b877c358
commit ca38f789fe
6 changed files with 72 additions and 4 deletions

View File

@ -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
{
/// <summary>
/// Creates instances of all of the events QSB uses.
/// </summary>
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());

View File

@ -34,5 +34,6 @@
public static string QSBOrbUser = "QSBOrbUser";
public static string QSBConversation = "QSBConversation";
public static string QSBConversationStartEnd = "QSBConversationStartEnd";
public static string QSBPlayInstrument = "QSBPlayInstrument";
}
}

View File

@ -0,0 +1,23 @@
using QSB.Events;
using QSB.Messaging;
namespace QSB.Instruments.Events
{
public class PlayInstrumentEvent : QSBEvent<PlayInstrumentMessage>
{
public override EventType Type => EventType.FullStateRequest;
public override void SetupListener() => GlobalMessenger<InstrumentType, bool>.AddListener(EventNames.QSBPlayerStatesRequest, Handler);
public override void CloseListener() => GlobalMessenger<InstrumentType, bool>.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
};
}
}

View File

@ -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);
}
}
}

View File

@ -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
}
}

View File

@ -148,6 +148,9 @@
<Compile Include="Events\EventNames.cs" />
<Compile Include="DeathSync\PlayerDeathEvent.cs" />
<Compile Include="Events\IQSBEvent.cs" />
<Compile Include="Instruments\Events\PlayInstrumentEvent.cs" />
<Compile Include="Instruments\Events\PlayInstrumentMessage.cs" />
<Compile Include="Instruments\InstrumentType.cs" />
<Compile Include="Instruments\QSBCamera\CameraController.cs" />
<Compile Include="Instruments\QSBCamera\CameraManager.cs" />
<Compile Include="Instruments\QSBCamera\CameraMode.cs" />