Instrument band support, submodule update to 138.0.0 (#17995)

This commit is contained in:
Vera Aguilera Puerto
2023-07-16 21:12:53 +02:00
committed by GitHub
parent 69ff0ae2e6
commit a2893dd6c3
16 changed files with 722 additions and 178 deletions

View File

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