mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-24 09:08:04 +03:00
# Description Adds a new trait that lets characters play midi without needing an instrument. Singer a 1-point positive trait. For now it's only available for vulps and felinids as they are naturally more vocal than other species. Also refactored harpy singing system a bit. # TODO - [X] Find out whatever causes this. Not critical, but probably should be fixed... <details><p>  </p></details> <details><summary><h1>Media</h1></summary> <p> Outdated   </p> </details> # Changelog 🆑 - add: Added a new positive trait - singer. It allows you to play midi songs without an instrument, similarly to harpies. --------- Signed-off-by: Mnemotechnican <69920617+Mnemotechnician@users.noreply.github.com> Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com>
94 lines
3.4 KiB
C#
94 lines
3.4 KiB
C#
using Content.Shared.Actions;
|
|
using Content.Shared.DeltaV.Harpy.Components;
|
|
using Content.Shared.Instruments;
|
|
using Content.Shared.Traits.Assorted.Components;
|
|
using Content.Shared.Traits.Assorted.Prototypes;
|
|
using Content.Shared.Zombies;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Shared.Traits.Assorted.Systems;
|
|
|
|
public abstract class SharedSingerSystem : EntitySystem
|
|
{
|
|
[Dependency] protected readonly IPrototypeManager ProtoMan = default!;
|
|
|
|
[Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
[Dependency] private readonly SharedInstrumentSystem _instrument = default!;
|
|
[Dependency] private readonly SharedUserInterfaceSystem _ui = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<EntityZombifiedEvent>(OnZombified);
|
|
SubscribeLocalEvent<SingerComponent, ComponentStartup>(OnStartup);
|
|
SubscribeLocalEvent<SingerComponent, ComponentShutdown>(OnShutdown);
|
|
SubscribeLocalEvent<SingerComponent, BoundUIClosedEvent>(OnBoundUIClosed);
|
|
SubscribeLocalEvent<SingerComponent, BoundUIOpenedEvent>(OnBoundUIOpened);
|
|
}
|
|
|
|
private void OnStartup(Entity<SingerComponent> ent, ref ComponentStartup args)
|
|
{
|
|
if (!ProtoMan.TryIndex(ent.Comp.Proto, out var singer))
|
|
return;
|
|
|
|
_actionsSystem.AddAction(ent, ref ent.Comp.MidiAction, singer.MidiActionId);
|
|
|
|
var instrumentComp = EnsureInstrumentComp(ent);
|
|
var defaultData = singer.InstrumentList[singer.DefaultInstrument];
|
|
_instrument.SetInstrumentProgram(instrumentComp, defaultData.Item1, defaultData.Item2);
|
|
SetUpSwappableInstrument(ent, singer);
|
|
|
|
if (singer.MidiUi is {} uiData && !_ui.TryGetUi(ent, uiData.UiKey, out _))
|
|
_ui.AddUi(ent.Owner, uiData);
|
|
}
|
|
|
|
private void OnShutdown(Entity<SingerComponent> ent, ref ComponentShutdown args)
|
|
{
|
|
_actionsSystem.RemoveAction(ent, ent.Comp.MidiAction);
|
|
}
|
|
|
|
private void OnZombified(ref EntityZombifiedEvent args)
|
|
{
|
|
CloseMidiUi(args.Target);
|
|
}
|
|
|
|
private void OnBoundUIClosed(EntityUid uid, SingerComponent component, BoundUIClosedEvent args)
|
|
{
|
|
if (args.UiKey is not InstrumentUiKey)
|
|
return;
|
|
|
|
TryComp(uid, out AppearanceComponent? appearance);
|
|
_appearance.SetData(uid, HarpyVisualLayers.Singing, SingingVisualLayer.False, appearance);
|
|
}
|
|
|
|
private void OnBoundUIOpened(EntityUid uid, SingerComponent component, BoundUIOpenedEvent args)
|
|
{
|
|
if (args.UiKey is not InstrumentUiKey)
|
|
return;
|
|
|
|
TryComp(uid, out AppearanceComponent? appearance);
|
|
_appearance.SetData(uid, HarpyVisualLayers.Singing, SingingVisualLayer.True, appearance);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Closes the MIDI UI if it is open. Does nothing on client side.
|
|
/// </summary>
|
|
public virtual void CloseMidiUi(EntityUid uid)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets up the swappable instrument on the entity, only on the server.
|
|
/// </summary>
|
|
protected virtual void SetUpSwappableInstrument(EntityUid uid, SingerInstrumentPrototype singer)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Ensures an InstrumentComponent on the entity. Uses client-side comp on client and server-side comp on the server.
|
|
/// </summary>
|
|
protected abstract SharedInstrumentComponent EnsureInstrumentComp(EntityUid uid);
|
|
}
|