Make instruments ECS (#5516)
This commit is contained in:
committed by
GitHub
parent
f5c3b1935b
commit
47a19f94d4
@@ -9,6 +9,7 @@ using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -98,7 +99,8 @@ namespace Content.Client.Instruments.UI
|
||||
// While we're waiting, load it into memory.
|
||||
await Task.WhenAll(Timer.Delay(100), file.CopyToAsync(memStream));
|
||||
|
||||
if (!_owner.Instrument?.OpenMidi(memStream.GetBuffer().AsSpan(0, (int) memStream.Length)) ?? true)
|
||||
if (_owner.Instrument is not {} instrument
|
||||
|| !EntitySystem.Get<InstrumentSystem>().OpenMidi(instrument.OwnerUid, memStream.GetBuffer().AsSpan(0, (int) memStream.Length), instrument))
|
||||
return;
|
||||
|
||||
MidiPlaybackSetButtonsDisabled(false);
|
||||
@@ -108,16 +110,19 @@ namespace Content.Client.Instruments.UI
|
||||
|
||||
private void MidiInputButtonOnOnToggled(ButtonToggledEventArgs obj)
|
||||
{
|
||||
var instrumentSystem = EntitySystem.Get<InstrumentSystem>();
|
||||
|
||||
if (obj.Pressed)
|
||||
{
|
||||
if (!PlayCheck())
|
||||
return;
|
||||
|
||||
MidiStopButtonOnPressed(null);
|
||||
_owner.Instrument?.OpenInput();
|
||||
if(_owner.Instrument is {} instrument)
|
||||
instrumentSystem.OpenInput(instrument.OwnerUid, instrument);
|
||||
}
|
||||
else
|
||||
_owner.Instrument?.CloseInput();
|
||||
else if(_owner.Instrument is {} instrument)
|
||||
instrumentSystem.CloseInput(instrument.OwnerUid, false, instrument);
|
||||
}
|
||||
|
||||
private bool PlayCheck()
|
||||
@@ -149,28 +154,35 @@ namespace Content.Client.Instruments.UI
|
||||
private void MidiStopButtonOnPressed(ButtonEventArgs? obj)
|
||||
{
|
||||
MidiPlaybackSetButtonsDisabled(true);
|
||||
_owner.Instrument?.CloseMidi();
|
||||
|
||||
if (_owner.Instrument is not { } instrument)
|
||||
return;
|
||||
|
||||
EntitySystem.Get<InstrumentSystem>().CloseMidi(instrument.OwnerUid, false, instrument);
|
||||
}
|
||||
|
||||
private void MidiLoopButtonOnOnToggled(ButtonToggledEventArgs obj)
|
||||
{
|
||||
if (_owner.Instrument != null)
|
||||
_owner.Instrument.LoopMidi = obj.Pressed;
|
||||
if (_owner.Instrument == null)
|
||||
return;
|
||||
|
||||
_owner.Instrument.LoopMidi = obj.Pressed;
|
||||
_owner.Instrument.DirtyRenderer = true;
|
||||
}
|
||||
|
||||
private void PlaybackSliderSeek(Range _)
|
||||
{
|
||||
// Do not seek while still grabbing.
|
||||
if (PlaybackSlider.Grabbed || _owner.Instrument == null) return;
|
||||
if (PlaybackSlider.Grabbed || _owner.Instrument is not {} instrument) return;
|
||||
|
||||
_owner.Instrument.PlayerTick = (int)Math.Ceiling((double) PlaybackSlider.Value);
|
||||
EntitySystem.Get<InstrumentSystem>().SetPlayerTick(instrument.OwnerUid, (int)Math.Ceiling(PlaybackSlider.Value), instrument);
|
||||
}
|
||||
|
||||
private void PlaybackSliderKeyUp(GUIBoundKeyEventArgs args)
|
||||
{
|
||||
if (args.Function != EngineKeyFunctions.UIClick || _owner.Instrument == null) return;
|
||||
if (args.Function != EngineKeyFunctions.UIClick || _owner.Instrument is not {} instrument) return;
|
||||
|
||||
_owner.Instrument.PlayerTick = (int)Math.Ceiling((double) PlaybackSlider.Value);
|
||||
EntitySystem.Get<InstrumentSystem>().SetPlayerTick(instrument.OwnerUid, (int)Math.Ceiling(PlaybackSlider.Value), instrument);
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
|
||||
Reference in New Issue
Block a user