#4219 revert of single sound removal in EmitSoundSystem
This commit is contained in:
@@ -10,6 +10,7 @@ namespace Content.Server.Interaction.Components
|
||||
public class EmitSoundOnUseComponent : BaseEmitSoundComponent
|
||||
{
|
||||
/// <inheritdoc />
|
||||
///
|
||||
public override string Name => "EmitSoundOnUse";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ namespace Content.Server.Sound
|
||||
/// </summary>
|
||||
public abstract class BaseEmitSoundComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float PitchVariation { get; set; }
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("soundCollection")] public string? SoundCollectionName { get; set; }
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("sound")] public string? _soundName;
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float _pitchVariation;
|
||||
[ViewVariables(VVAccess.ReadWrite)] [DataField("soundCollection")] public string? _soundCollectionName;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Content.Server.Sound
|
||||
public class EmitSoundOnActivateComponent : BaseEmitSoundComponent
|
||||
{
|
||||
/// <inheritdoc />
|
||||
///
|
||||
public override string Name => "EmitSoundOnActivate";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Content.Server.Sound
|
||||
public class EmitSoundOnLandComponent : BaseEmitSoundComponent
|
||||
{
|
||||
/// <inheritdoc />
|
||||
///
|
||||
public override string Name => "EmitSoundOnLand";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#nullable enable
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Server.Interaction.Components;
|
||||
using Content.Server.Sound;
|
||||
using Content.Server.Throwing;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Audio;
|
||||
@@ -13,7 +13,8 @@ using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Log;
|
||||
|
||||
namespace Content.Server.Sound
|
||||
|
||||
namespace Content.Server.GameObjects.EntitySystems
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class EmitSoundSystem : EntitySystem
|
||||
@@ -33,20 +34,27 @@ namespace Content.Server.Sound
|
||||
|
||||
private void PlaySound(BaseEmitSoundComponent component)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(component.SoundCollectionName))
|
||||
if (!string.IsNullOrWhiteSpace(component._soundCollectionName))
|
||||
{
|
||||
PlayRandomSoundFromCollection(component);
|
||||
}
|
||||
else if(!string.IsNullOrWhiteSpace(component._soundName))
|
||||
{
|
||||
PlaySingleSound(component._soundName, component);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Warning($"{nameof(component)}: {component.Owner} has no {nameof(component.SoundCollectionName)} to play.");
|
||||
Logger.Warning($"{nameof(component)} Uid:{component.Owner.Uid} has neither {nameof(component._soundCollectionName)} nor {nameof(component._soundName)} to play.");
|
||||
}
|
||||
}
|
||||
|
||||
private void PlayRandomSoundFromCollection(BaseEmitSoundComponent component)
|
||||
{
|
||||
var file = SelectRandomSoundFromSoundCollection(component.SoundCollectionName!);
|
||||
PlaySingleSound(file, component);
|
||||
if (!string.IsNullOrWhiteSpace(component._soundCollectionName))
|
||||
{
|
||||
var file = SelectRandomSoundFromSoundCollection(component._soundCollectionName);
|
||||
PlaySingleSound(file, component);
|
||||
}
|
||||
}
|
||||
|
||||
private string SelectRandomSoundFromSoundCollection(string soundCollectionName)
|
||||
@@ -57,10 +65,15 @@ namespace Content.Server.Sound
|
||||
|
||||
private static void PlaySingleSound(string soundName, BaseEmitSoundComponent component)
|
||||
{
|
||||
if (component.PitchVariation > 0.0)
|
||||
if (string.IsNullOrWhiteSpace(soundName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (component._pitchVariation > 0.0)
|
||||
{
|
||||
SoundSystem.Play(Filter.Pvs(component.Owner), soundName, component.Owner,
|
||||
AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f));
|
||||
AudioHelpers.WithVariation(component._pitchVariation).WithVolume(-2f));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace Content.Server.Throwing
|
||||
public class EmitSoundOnThrowComponent : BaseEmitSoundComponent
|
||||
{
|
||||
/// <inheritdoc />
|
||||
///
|
||||
public override string Name => "EmitSoundOnThrow";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user