Skip to content

Commit

Permalink
Upstreamed sound and fixed yml files
Browse files Browse the repository at this point in the history
  • Loading branch information
blueDev2 committed Mar 31, 2024
1 parent 9b50f50 commit d396fdd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.

This file was deleted.

9 changes: 0 additions & 9 deletions Content.Server/Sound/EmitSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public override void Initialize()

SubscribeLocalEvent<EmitSoundOnTriggerComponent, TriggerEvent>(HandleEmitSoundOnTrigger);
SubscribeLocalEvent<EmitSoundOnUIOpenComponent, AfterActivatableUIOpenEvent>(HandleEmitSoundOnUIOpen);
SubscribeLocalEvent<EmitSoundOnInteractUsingComponent, InteractUsingEvent>(HandleEmitSoundOnInteractUsing);
}

private void HandleEmitSoundOnUIOpen(EntityUid uid, EmitSoundOnUIOpenComponent component, AfterActivatableUIOpenEvent args)
Expand All @@ -54,12 +53,4 @@ private void HandleEmitSoundOnTrigger(EntityUid uid, EmitSoundOnTriggerComponent
TryEmitSound(uid, component, args.User, false);
args.Handled = true;
}
private void HandleEmitSoundOnInteractUsing(EntityUid uid, EmitSoundOnInteractUsingComponent component, InteractUsingEvent args)
{
var curUsedItemID = Prototype(args.Used)?.ID;
if (component.UsedItemID == curUsedItemID)
{
TryEmitSound(uid, component, args.User, false);
}
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
14 changes: 11 additions & 3 deletions Content.Shared/Sound/SharedEmitSoundSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace Content.Shared.Sound;
[UsedImplicitly]
public abstract class SharedEmitSoundSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly INetManager _netMan = default!;
[Dependency] private readonly ITileDefinitionManager _tileDefMan = default!;
[Dependency] protected readonly IRobustRandom Random = default!;
Expand All @@ -41,6 +41,7 @@ public override void Initialize()
SubscribeLocalEvent<EmitSoundOnActivateComponent, ActivateInWorldEvent>(OnEmitSoundOnActivateInWorld);
SubscribeLocalEvent<EmitSoundOnPickupComponent, GotEquippedHandEvent>(OnEmitSoundOnPickup);
SubscribeLocalEvent<EmitSoundOnDropComponent, DroppedEvent>(OnEmitSoundOnDrop);
SubscribeLocalEvent<EmitSoundOnInteractUsingComponent, InteractUsingEvent>(OnEmitSoundOnInteractUsing);

SubscribeLocalEvent<EmitSoundOnCollideComponent, StartCollideEvent>(OnEmitSoundOnCollide);
}
Expand Down Expand Up @@ -102,6 +103,13 @@ private void OnEmitSoundOnDrop(EntityUid uid, EmitSoundOnDropComponent component
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)
Expand All @@ -124,7 +132,7 @@ private void OnEmitSoundOnCollide(EntityUid uid, EmitSoundOnCollideComponent com
!args.OtherFixture.Hard ||
!TryComp<PhysicsComponent>(uid, out var physics) ||
physics.LinearVelocity.Length() < component.MinimumVelocity ||
_timing.CurTime < component.NextSound ||
Timing.CurTime < component.NextSound ||
MetaData(uid).EntityPaused)
{
return;
Expand All @@ -136,7 +144,7 @@ private void OnEmitSoundOnCollide(EntityUid uid, EmitSoundOnCollideComponent com

var fraction = MathF.Min(1f, (physics.LinearVelocity.Length() - component.MinimumVelocity) / MaxVolumeVelocity);
var volume = MinVolume + (MaxVolume - MinVolume) * fraction;
component.NextSound = _timing.CurTime + EmitSoundOnCollideComponent.CollideCooldown;
component.NextSound = Timing.CurTime + EmitSoundOnCollideComponent.CollideCooldown;
var sound = component.Sound;

if (_netMan.IsServer && sound != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@
- type: Item
size: Small
sprite: DeltaV/Objects/Specific/Justice/gavel.rsi
- type: Tag
tags:
- Gavel

Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@
- type: EmitSoundOnInteractUsing
sound:
path: /Audio/DeltaV/Items/gavel.ogg
UsedItemID: Gavel
whitelist:
tags:
- Gavel

0 comments on commit d396fdd

Please sign in to comment.