Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Different Styles for Instruments #9250

Merged
merged 3 commits into from
Jul 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Content.Server/Instruments/SwappableInstrumentComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Content.Server.Instruments;

[RegisterComponent]
public sealed class SwappableInstrumentComponent : Component
{
/// <summary>
/// Used to store the different instruments that can be swapped between.
/// string = display name of the instrument
/// byte 1 = instrument midi program
/// byte 2 = instrument midi bank
/// </summary>
[DataField("instrumentList", required: true)]
public Dictionary<string, (byte, byte)> InstrumentList = new();
}
51 changes: 51 additions & 0 deletions Content.Server/Instruments/SwappableInstrumentSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Shared.Instruments;
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Robust.Shared.Player;

namespace Content.Server.Instruments;

public sealed class SwappableInstrumentSystem : EntitySystem
{
[Dependency] private readonly SharedInstrumentSystem _sharedInstrument = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<SwappableInstrumentComponent, GetVerbsEvent<AlternativeVerb>>(AddStyleVerb);
}

private void AddStyleVerb(EntityUid uid, SwappableInstrumentComponent component, GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanInteract || !args.CanAccess || component.InstrumentList.Count <= 1)
return;

if (!TryComp<SharedInstrumentComponent>(uid, out var instrument))
return;

if (instrument.Playing) //no changing while playing
return;

var priority = 0;
foreach (var entry in component.InstrumentList)
{
AlternativeVerb selection = new()
{
Text = entry.Key,
Category = VerbCategory.InstrumentStyle,
Priority = priority,
Act = () =>
{
_sharedInstrument.SetInstrumentProgram(instrument, entry.Value.Item1, entry.Value.Item2);
_popup.PopupEntity(Loc.GetString("swappable-instrument-component-style-set", ("style", entry.Key)),
args.User, Filter.Entities(args.User));
}
};

priority--;
args.Verbs.Add(selection);
}
}
}
6 changes: 6 additions & 0 deletions Content.Shared/Instruments/SharedInstrumentSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public virtual void SetupRenderer(EntityUid uid, bool fromStateChange, SharedIns
public virtual void EndRenderer(EntityUid uid, bool fromStateChange, SharedInstrumentComponent? instrument = null)
{ }

public void SetInstrumentProgram(SharedInstrumentComponent component, byte program, byte bank)
{
component.InstrumentProgram = program;
component.InstrumentBank = bank;
}

private void OnGetState(EntityUid uid, SharedInstrumentComponent instrument, ref ComponentGetState args)
{
args.State =
Expand Down
3 changes: 3 additions & 0 deletions Content.Shared/Verbs/VerbCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public VerbCategory(string text, string? icon, bool iconsOnly = false)
public static readonly VerbCategory Split =
new("verb-categories-split", null);

public static readonly VerbCategory InstrumentStyle =
new("verb-categories-instrument-style", null);

public static readonly VerbCategory SetSensor = new("verb-categories-set-sensor", null);
}
}
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/instruments/instruments-component.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ instruments-component-menu-no-midi-support = MIDI support is currently not
FluidSynth or a development package
for FluidSynth.

# SwappableInstrumentComponent
swappable-instrument-component-style-set = Style set to "{$style}"

1 change: 1 addition & 0 deletions Resources/Locale/en-US/verbs/verb-system.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ verb-categories-rotate = Rotate
verb-categories-smite = Smite
verb-categories-transfer = Set Transfer Amount
verb-categories-split = Split
verb-categories-instrument-style = Instrument Style
verb-categories-set-sensor = Sensor
verb-categories-timer = Set Delay

Expand Down
31 changes: 29 additions & 2 deletions Resources/Prototypes/Entities/Objects/Fun/instruments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
components:
- type: Instrument
program: 62
- type: SwappableInstrument
instrumentList:
"Electro": {62: 0} #i needed generic sounding synth presets, sue me
"Bubbles": {63: 0}
- type: Sprite
sprite: Objects/Fun/Instruments/h_synthesizer.rsi
state: icon
Expand All @@ -43,7 +47,11 @@
description: Anyway, here's Wonderwall.
components:
- type: Instrument
program: 25
program: 24
- type: SwappableInstrument
instrumentList:
"Nylon": {24: 0}
"Steel": {25: 0}
- type: Sprite
sprite: Objects/Fun/Instruments/guitar.rsi
state: icon
Expand Down Expand Up @@ -82,6 +90,10 @@
components:
- type: Instrument
program: 56
- type: SwappableInstrument
instrumentList:
"Standard": {56: 0}
"Muted": {59: 0}
- type: Sprite
sprite: Objects/Fun/Instruments/trumpet.rsi
state: icon
Expand Down Expand Up @@ -117,6 +129,11 @@
components:
- type: Instrument
program: 27
- type: SwappableInstrument
instrumentList:
"Clean": {27: 0}
"Jazz": {25: 0}
"Muted": {28: 0}
- type: Sprite
sprite: Objects/Fun/Instruments/eguitar.rsi
state: icon
Expand All @@ -134,6 +151,10 @@
components:
- type: Instrument
program: 21
- type: SwappableInstrument
instrumentList:
"Standard": {21: 0}
"Tango": {23: 0}
- type: Sprite
sprite: Objects/Fun/Instruments/accordion.rsi
state: icon
Expand Down Expand Up @@ -240,7 +261,13 @@
description: An instrument. You could probably grind this into raw jazz.
components:
- type: Instrument
program: 67
program: 66
- type: SwappableInstrument
instrumentList:
"Soprano": {64: 0}
"Alto": {65: 0}
"Tenor": {66: 0}
"Baritone": {67: 0}
- type: Sprite
sprite: Objects/Fun/Instruments/saxophone.rsi
state: icon
Expand Down