]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Add new component to Make sound on interact (#26523)
authorblueDev2 <89804215+blueDev2@users.noreply.github.com>
Sun, 31 Mar 2024 02:20:44 +0000 (22:20 -0400)
committerGitHub <noreply@github.com>
Sun, 31 Mar 2024 02:20:44 +0000 (13:20 +1100)
* Adds new Component: EmitSoundOnInteractUsing

* Missed an import

* File-scoping

* Replace ID check with Prototype check

* Moved component and system to shared. Set prediction to true.

* Removed impoper imports and changed namespace of component to reflect changed folder.

* Following function naming theme

* All this code is basically deltanedas's, but it was a learning experience for me

* Update Content.Shared/Sound/Components/EmitSoundOnInteractUsingComponent.cs

* Update Content.Shared/Sound/Components/EmitSoundOnInteractUsingComponent.cs

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Content.Shared/Sound/Components/EmitSoundOnInteractUsingComponent.cs [new file with mode: 0644]
Content.Shared/Sound/SharedEmitSoundSystem.cs

diff --git a/Content.Shared/Sound/Components/EmitSoundOnInteractUsingComponent.cs b/Content.Shared/Sound/Components/EmitSoundOnInteractUsingComponent.cs
new file mode 100644 (file)
index 0000000..49118d9
--- /dev/null
@@ -0,0 +1,15 @@
+using Content.Shared.Whitelist;
+using Robust.Shared.Prototypes;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Sound.Components;
+
+/// <summary>
+/// Whenever this item is used upon by an entity, with a tag or component within a whitelist, in the hand of a user, play a sound
+/// </summary>
+[RegisterComponent, NetworkedComponent]
+public sealed partial class EmitSoundOnInteractUsingComponent : BaseEmitSoundComponent
+{
+    [DataField(required: true)]
+    public EntityWhitelist Whitelist = new();
+}
index cd7828fc6b35f579933b42e351a37987c0bd14c0..329626964ef6a07783444fa28517367d5184b8b0 100644 (file)
@@ -41,6 +41,7 @@ public abstract class SharedEmitSoundSystem : EntitySystem
         SubscribeLocalEvent<EmitSoundOnActivateComponent, ActivateInWorldEvent>(OnEmitSoundOnActivateInWorld);
         SubscribeLocalEvent<EmitSoundOnPickupComponent, GotEquippedHandEvent>(OnEmitSoundOnPickup);
         SubscribeLocalEvent<EmitSoundOnDropComponent, DroppedEvent>(OnEmitSoundOnDrop);
+        SubscribeLocalEvent<EmitSoundOnInteractUsingComponent, InteractUsingEvent>(OnEmitSoundOnInteractUsing);
 
         SubscribeLocalEvent<EmitSoundOnCollideComponent, StartCollideEvent>(OnEmitSoundOnCollide);
     }
@@ -102,6 +103,13 @@ public abstract class SharedEmitSoundSystem : EntitySystem
         TryEmitSound(uid, component, args.User);
     }
 
+    private void OnEmitSoundOnInteractUsing(Entity<EmitSoundOnInteractUsingComponent> ent, ref InteractUsingEvent args)
+    {
+        if (ent.Comp.Whitelist.IsValid(args.Used, EntityManager))
+        {
+            TryEmitSound(ent, ent.Comp, args.User);
+        }
+    }
     protected void TryEmitSound(EntityUid uid, BaseEmitSoundComponent component, EntityUid? user=null, bool predict=true)
     {
         if (component.Sound == null)