#3935 - Refactored ToysComponent functionality into ECS (#4127)

* #3935 - toys properly play sounds when: Activated, Landed (after throwing) and Used in hand

* #3935 - extracted BaseEmitSoundComponent

* #3935 - refactored EmitSound components to use ECS

* #3935 - added new components to client ignored components

* #3935 - added suggested stuff for EmitSoundSystem et al.

* #3935 added suggestions from PR

* #3935 implemented suggestions from PR

* #3935 updated namespace
This commit is contained in:
Galactic Chimp
2021-06-19 11:35:56 +02:00
committed by GitHub
parent 4093e2b5ba
commit 53671aeee7
9 changed files with 128 additions and 99 deletions

View File

@@ -1,42 +1,15 @@
using Content.Shared.Audio;
using Content.Shared.Throwing;
using Robust.Shared.Audio;
using Content.Server.Sound;
using Robust.Shared.GameObjects;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Throwing
{
/// <summary>
/// Simple sound emitter that emits sound on use in hand
/// Simple sound emitter that emits sound on ThrowEvent
/// </summary>
[RegisterComponent]
public class EmitSoundOnThrowComponent : Component, ILand
public class EmitSoundOnThrowComponent : BaseEmitSoundComponent
{
/// <inheritdoc />
///
public override string Name => "EmitSoundOnThrow";
[DataField("sound")]
public string? _soundName;
[DataField("variation")]
public float _pitchVariation;
public void PlaySoundEffect()
{
if (!string.IsNullOrWhiteSpace(_soundName))
{
if (_pitchVariation > 0.0)
{
SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioHelpers.WithVariation(_pitchVariation).WithVolume(-2f));
}
SoundSystem.Play(Filter.Pvs(Owner), _soundName, Owner, AudioParams.Default.WithVolume(-2f));
}
}
void ILand.Land(LandEventArgs eventArgs)
{
PlaySoundEffect();
}
}
}