Skip to content

Commit

Permalink
Add selectable sounds system (RMC-14#5517)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dutch-VanDerLinde authored Feb 5, 2025
1 parent 89df888 commit 2605450
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Robust.Shared.GameStates;
using Robust.Shared.Audio;

namespace Content.Shared._RMC14.SelectableSounds;

/// <summary>
/// A component which lets you toggle sounds on things like an EmitSoundOnUseComponent with a verb
/// </summary>
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class RMCSelectableSoundsComponent : Component
{
[DataField, AutoNetworkedField]
public Dictionary<LocId, SoundSpecifier> Sounds = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Content.Shared._RMC14.Sound;
using Content.Shared.Popups;
using Content.Shared.Sound.Components;
using Content.Shared.Verbs;
using Robust.Shared.Collections;

namespace Content.Shared._RMC14.SelectableSounds;

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

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

SubscribeLocalEvent<RMCSelectableSoundsComponent, GetVerbsEvent<AlternativeVerb>>(OnGetAltVerbs);
}

private void OnGetAltVerbs(Entity<RMCSelectableSoundsComponent> ent, ref GetVerbsEvent<AlternativeVerb> args)
{
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
return;

var user = args.User;
var verbs = new ValueList<AlternativeVerb>();

foreach (var soundEntry in ent.Comp.Sounds)
{
var name = Loc.GetString(soundEntry.Key);
var sound = soundEntry.Value;

var newVerb = new AlternativeVerb()
{
Text = name,
IconEntity = GetNetEntity(ent.Owner),
Category = VerbCategory.SelectType,
Act = () =>
{
if (TryComp<EmitSoundOnUseComponent>(ent.Owner, out var use))
use.Sound = sound;

if (TryComp<EmitSoundOnActionComponent>(ent.Owner, out var action))
action.Sound = sound;

var msg = Loc.GetString("rmc-sound-select", ("sound", name));
_popup.PopupClient(msg, user, user);
},
};

verbs.Add(newVerb);
}

args.Verbs.UnionWith(verbs);
}
}
5 changes: 5 additions & 0 deletions Resources/Locale/en-US/_RMC14/selectable_sounds.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rmc-sound-select = Changed sound to: {$sound}
rmc-sound-select-whistle = Trench Whistle
rmc-sound-select-crowbar = Crowbar
rmc-sound-select-detector = Motion Detector
19 changes: 19 additions & 0 deletions Resources/Prototypes/_RMC14/Entities/Objects/Fun/misc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- type: entity
parent: RMCWhistle
id: RMCDebugSoundDevice
name: unknown device
description: "???"
suffix: DO NOT MAP
components:
- type: Sprite
sprite: Objects/Devices/declaration_of_war.rsi
state: declarator
color: Blue
- type: RMCSelectableSounds
sounds:
rmc-sound-select-whistle: # Loc ID
collection: TrenchWhistle
rmc-sound-select-crowbar:
path: /Audio/_RMC14/Handling/crowbar_pickup.ogg
rmc-sound-select-detector:
path: /Audio/_RMC14/Effects/motion_detector.ogg

0 comments on commit 2605450

Please sign in to comment.