Instrument band support, submodule update to 138.0.0 (#17995)
This commit is contained in:
committed by
GitHub
parent
69ff0ae2e6
commit
a2893dd6c3
@@ -1,33 +1,38 @@
|
||||
using System.Collections;
|
||||
using Robust.Shared.Audio.Midi;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Instruments;
|
||||
|
||||
[NetworkedComponent, Access(typeof(SharedInstrumentSystem))]
|
||||
public abstract class SharedInstrumentComponent : Component
|
||||
[NetworkedComponent]
|
||||
[AutoGenerateComponentState(true)]
|
||||
[Access(typeof(SharedInstrumentSystem))]
|
||||
public abstract partial class SharedInstrumentComponent : Component
|
||||
{
|
||||
[ViewVariables]
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
public bool Playing { get; set; }
|
||||
|
||||
[DataField("program"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("program"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public byte InstrumentProgram { get; set; }
|
||||
|
||||
[DataField("bank"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("bank"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public byte InstrumentBank { get; set; }
|
||||
|
||||
[DataField("allowPercussion"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("allowPercussion"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool AllowPercussion { get; set; }
|
||||
|
||||
[DataField("allowProgramChange"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("allowProgramChange"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool AllowProgramChange { get ; set; }
|
||||
|
||||
[DataField("respectMidiLimits"), ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("respectMidiLimits"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public bool RespectMidiLimits { get; set; } = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[Access(typeof(SharedInstrumentSystem), Other = AccessPermissions.ReadWrite)] // FIXME Friends
|
||||
public bool DirtyRenderer { get; set; }
|
||||
[ViewVariables(VVAccess.ReadWrite), AutoNetworkedField]
|
||||
public EntityUid? Master { get; set; } = null;
|
||||
|
||||
[ViewVariables, AutoNetworkedField]
|
||||
public BitArray FilteredChannels { get; set; } = new(RobustMidiEvent.MaxChannels, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +50,40 @@ public sealed class InstrumentStopMidiEvent : EntityEventArgs
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send from the client to the server to set a master instrument.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class InstrumentSetMasterEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Uid { get; }
|
||||
public EntityUid? Master { get; }
|
||||
|
||||
public InstrumentSetMasterEvent(EntityUid uid, EntityUid? master)
|
||||
{
|
||||
Uid = uid;
|
||||
Master = master;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send from the client to the server to set a master instrument channel.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class InstrumentSetFilteredChannelEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Uid { get; }
|
||||
public int Channel { get; }
|
||||
public bool Value { get; }
|
||||
|
||||
public InstrumentSetFilteredChannelEvent(EntityUid uid, int channel, bool value)
|
||||
{
|
||||
Uid = uid;
|
||||
Channel = channel;
|
||||
Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This message is sent to the client to start the synth.
|
||||
/// </summary>
|
||||
@@ -75,27 +114,6 @@ public sealed class InstrumentMidiEventEvent : EntityEventArgs
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class InstrumentState : ComponentState
|
||||
{
|
||||
public bool Playing { get; }
|
||||
public byte InstrumentProgram { get; }
|
||||
public byte InstrumentBank { get; }
|
||||
public bool AllowPercussion { get; }
|
||||
public bool AllowProgramChange { get; }
|
||||
public bool RespectMidiLimits { get; }
|
||||
|
||||
public InstrumentState(bool playing, byte instrumentProgram, byte instrumentBank, bool allowPercussion, bool allowProgramChange, bool respectMidiLimits)
|
||||
{
|
||||
Playing = playing;
|
||||
InstrumentProgram = instrumentProgram;
|
||||
InstrumentBank = instrumentBank;
|
||||
AllowPercussion = allowPercussion;
|
||||
AllowProgramChange = allowProgramChange;
|
||||
RespectMidiLimits = respectMidiLimits;
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
public enum InstrumentUiKey
|
||||
{
|
||||
|
||||
@@ -1,57 +1,32 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Instruments;
|
||||
|
||||
public abstract class SharedInstrumentSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedInstrumentComponent, ComponentGetState>(OnGetState);
|
||||
SubscribeLocalEvent<SharedInstrumentComponent, ComponentHandleState>(OnHandleState);
|
||||
SubscribeLocalEvent<SharedInstrumentComponent, AfterAutoHandleStateEvent>(AfterHandleInstrumentState);
|
||||
}
|
||||
|
||||
public virtual void SetupRenderer(EntityUid uid, bool fromStateChange, SharedInstrumentComponent? instrument = null)
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void EndRenderer(EntityUid uid, bool fromStateChange, SharedInstrumentComponent? instrument = null)
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
public void SetInstrumentProgram(SharedInstrumentComponent component, byte program, byte bank)
|
||||
{
|
||||
component.InstrumentBank = bank;
|
||||
component.InstrumentProgram = program;
|
||||
component.DirtyRenderer = true;
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
private void OnGetState(EntityUid uid, SharedInstrumentComponent instrument, ref ComponentGetState args)
|
||||
private void AfterHandleInstrumentState(EntityUid uid, SharedInstrumentComponent instrument, ref AfterAutoHandleStateEvent args)
|
||||
{
|
||||
args.State =
|
||||
new InstrumentState(instrument.Playing, instrument.InstrumentProgram, instrument.InstrumentBank,
|
||||
instrument.AllowPercussion, instrument.AllowProgramChange, instrument.RespectMidiLimits);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, SharedInstrumentComponent instrument, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not InstrumentState state)
|
||||
return;
|
||||
|
||||
if (state.Playing)
|
||||
{
|
||||
if(instrument.Playing)
|
||||
SetupRenderer(uid, true, instrument);
|
||||
}
|
||||
else
|
||||
{
|
||||
EndRenderer(uid, true, instrument);
|
||||
}
|
||||
|
||||
instrument.Playing = state.Playing;
|
||||
instrument.AllowPercussion = state.AllowPercussion;
|
||||
instrument.AllowProgramChange = state.AllowProgramChange;
|
||||
instrument.InstrumentBank = state.InstrumentBank;
|
||||
instrument.InstrumentProgram = state.InstrumentProgram;
|
||||
instrument.DirtyRenderer = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Instruments.UI;
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class InstrumentBandRequestBuiMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class InstrumentBandResponseBuiMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public (EntityUid, string)[] Nearby { get; set; }
|
||||
|
||||
public InstrumentBandResponseBuiMessage((EntityUid, string)[] nearby)
|
||||
{
|
||||
Nearby = nearby;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user