Files
OldThink/Content.Client/Instruments/InstrumentComponent.cs

71 lines
1.9 KiB
C#
Raw Normal View History

2021-06-09 22:19:39 +02:00
using Content.Shared.Instruments;
using Robust.Client.Audio.Midi;
using Robust.Shared.Audio.Midi;
2021-11-28 01:47:36 +01:00
namespace Content.Client.Instruments;
2020-05-21 15:20:37 +02:00
2023-09-12 14:43:06 +10:00
[RegisterComponent]
public sealed partial class InstrumentComponent : SharedInstrumentComponent
2021-11-28 01:47:36 +01:00
{
public event Action? OnMidiPlaybackEnded;
[ViewVariables]
2021-11-28 01:47:36 +01:00
public IMidiRenderer? Renderer;
[ViewVariables]
2021-11-28 01:47:36 +01:00
public uint SequenceDelay;
[ViewVariables]
2021-11-28 01:47:36 +01:00
public uint SequenceStartTick;
[ViewVariables]
2021-11-28 01:47:36 +01:00
public TimeSpan LastMeasured = TimeSpan.MinValue;
2020-05-21 15:20:37 +02:00
[ViewVariables]
2021-11-28 01:47:36 +01:00
public int SentWithinASec;
2020-05-18 13:29:31 +02:00
2021-11-28 01:47:36 +01:00
/// <summary>
/// A queue of MidiEvents to be sent to the server.
/// </summary>
[ViewVariables]
public readonly List<RobustMidiEvent> MidiEventBuffer = new();
2020-05-18 13:29:31 +02:00
2021-11-28 01:47:36 +01:00
/// <summary>
/// Whether a midi song will loop or not.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public bool LoopMidi { get; set; } = false;
2020-05-18 13:29:31 +02:00
2021-11-28 01:47:36 +01:00
/// <summary>
/// Whether this instrument is handheld or not.
/// </summary>
[DataField("handheld")]
public bool Handheld { get; set; } // TODO: Replace this by simply checking if the entity has an ItemComponent.
2021-11-28 01:47:36 +01:00
/// <summary>
/// Whether there's a midi song being played or not.
/// </summary>
[ViewVariables]
public bool IsMidiOpen => Renderer?.Status == MidiRendererStatus.File;
2020-05-18 13:29:31 +02:00
2021-11-28 01:47:36 +01:00
/// <summary>
/// Whether the midi renderer is listening for midi input or not.
/// </summary>
[ViewVariables]
public bool IsInputOpen => Renderer?.Status == MidiRendererStatus.Input;
2021-11-28 01:47:36 +01:00
/// <summary>
/// Whether the midi renderer is alive or not.
/// </summary>
[ViewVariables]
public bool IsRendererAlive => Renderer != null;
2021-11-28 01:47:36 +01:00
[ViewVariables]
public int PlayerTotalTick => Renderer?.PlayerTotalTick ?? 0;
2021-11-28 01:47:36 +01:00
[ViewVariables]
public int PlayerTick => Renderer?.PlayerTick ?? 0;
2021-11-28 01:47:36 +01:00
public void PlaybackEndedInvoke() => OnMidiPlaybackEnded?.Invoke();
}