Remove instruments compref (#19560)

This commit is contained in:
metalgearsloth
2023-09-12 14:43:06 +10:00
committed by GitHub
parent f05f94fdc0
commit fd60d39bc7
7 changed files with 94 additions and 27 deletions

View File

@@ -6,12 +6,12 @@ using JetBrains.Annotations;
using Robust.Client.Audio.Midi;
using Robust.Shared.Audio.Midi;
using Robust.Shared.Configuration;
using Robust.Shared.GameStates;
using Robust.Shared.Network;
using Robust.Shared.Timing;
namespace Content.Client.Instruments;
[UsedImplicitly]
public sealed class InstrumentSystem : SharedInstrumentSystem
{
[Dependency] private readonly IClientNetManager _netManager = default!;
@@ -37,6 +37,27 @@ public sealed class InstrumentSystem : SharedInstrumentSystem
SubscribeNetworkEvent<InstrumentStopMidiEvent>(OnMidiStop);
SubscribeLocalEvent<InstrumentComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<InstrumentComponent, ComponentHandleState>(OnHandleState);
}
private void OnHandleState(EntityUid uid, SharedInstrumentComponent component, ref ComponentHandleState args)
{
if (args.Current is not InstrumentComponentState state)
return;
component.Playing = state.Playing;
component.InstrumentProgram = state.InstrumentProgram;
component.InstrumentBank = state.InstrumentBank;
component.AllowPercussion = state.AllowPercussion;
component.AllowProgramChange = state.AllowProgramChange;
component.RespectMidiLimits = state.RespectMidiLimits;
component.Master = EnsureEntity<InstrumentComponent>(state.Master, uid);
component.FilteredChannels = state.FilteredChannels;
if (component.Playing)
SetupRenderer(uid, true, component);
else
EndRenderer(uid, true, component);
}
public override void Shutdown()
@@ -71,9 +92,19 @@ public sealed class InstrumentSystem : SharedInstrumentSystem
RaiseNetworkEvent(new InstrumentSetFilteredChannelEvent(GetNetEntity(uid), channel, value));
}
public override bool ResolveInstrument(EntityUid uid, ref SharedInstrumentComponent? component)
{
if (component is not null)
return true;
TryComp<InstrumentComponent>(uid, out var localComp);
component = localComp;
return component != null;
}
public override void SetupRenderer(EntityUid uid, bool fromStateChange, SharedInstrumentComponent? component = null)
{
if (!Resolve(uid, ref component))
if (!ResolveInstrument(uid, ref component))
return;
if (component is not InstrumentComponent instrument)
@@ -156,7 +187,7 @@ public sealed class InstrumentSystem : SharedInstrumentSystem
public override void EndRenderer(EntityUid uid, bool fromStateChange, SharedInstrumentComponent? component = null)
{
if (!Resolve(uid, ref component, false))
if (!ResolveInstrument(uid, ref component))
return;
if (component is not InstrumentComponent instrument)