#4219 revert of single sound removal in EmitSoundSystem

This commit is contained in:
Galactic Chimp
2021-06-27 21:30:28 +02:00
parent c8e3775ea5
commit a0889a9151
6 changed files with 28 additions and 10 deletions

View File

@@ -10,6 +10,7 @@ namespace Content.Server.Interaction.Components
public class EmitSoundOnUseComponent : BaseEmitSoundComponent public class EmitSoundOnUseComponent : BaseEmitSoundComponent
{ {
/// <inheritdoc /> /// <inheritdoc />
///
public override string Name => "EmitSoundOnUse"; public override string Name => "EmitSoundOnUse";
} }
} }

View File

@@ -11,7 +11,8 @@ namespace Content.Server.Sound
/// </summary> /// </summary>
public abstract class BaseEmitSoundComponent : Component public abstract class BaseEmitSoundComponent : Component
{ {
[ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float PitchVariation { get; set; } [ViewVariables(VVAccess.ReadWrite)] [DataField("sound")] public string? _soundName;
[ViewVariables(VVAccess.ReadWrite)] [DataField("soundCollection")] public string? SoundCollectionName { get; set; } [ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float _pitchVariation;
[ViewVariables(VVAccess.ReadWrite)] [DataField("soundCollection")] public string? _soundCollectionName;
} }
} }

View File

@@ -9,6 +9,7 @@ namespace Content.Server.Sound
public class EmitSoundOnActivateComponent : BaseEmitSoundComponent public class EmitSoundOnActivateComponent : BaseEmitSoundComponent
{ {
/// <inheritdoc /> /// <inheritdoc />
///
public override string Name => "EmitSoundOnActivate"; public override string Name => "EmitSoundOnActivate";
} }
} }

View File

@@ -9,6 +9,7 @@ namespace Content.Server.Sound
public class EmitSoundOnLandComponent : BaseEmitSoundComponent public class EmitSoundOnLandComponent : BaseEmitSoundComponent
{ {
/// <inheritdoc /> /// <inheritdoc />
///
public override string Name => "EmitSoundOnLand"; public override string Name => "EmitSoundOnLand";
} }
} }

View File

@@ -1,8 +1,8 @@
#nullable enable
using Content.Shared.Audio; using Content.Shared.Audio;
using Content.Shared.Interaction; using Content.Shared.Interaction;
using Content.Shared.Throwing; using Content.Shared.Throwing;
using Content.Server.Interaction.Components; using Content.Server.Interaction.Components;
using Content.Server.Sound;
using Content.Server.Throwing; using Content.Server.Throwing;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Shared.Audio; using Robust.Shared.Audio;
@@ -13,7 +13,8 @@ using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
using Robust.Shared.Log; using Robust.Shared.Log;
namespace Content.Server.Sound
namespace Content.Server.GameObjects.EntitySystems
{ {
[UsedImplicitly] [UsedImplicitly]
public class EmitSoundSystem : EntitySystem public class EmitSoundSystem : EntitySystem
@@ -33,20 +34,27 @@ namespace Content.Server.Sound
private void PlaySound(BaseEmitSoundComponent component) private void PlaySound(BaseEmitSoundComponent component)
{ {
if (!string.IsNullOrWhiteSpace(component.SoundCollectionName)) if (!string.IsNullOrWhiteSpace(component._soundCollectionName))
{ {
PlayRandomSoundFromCollection(component); PlayRandomSoundFromCollection(component);
} }
else if(!string.IsNullOrWhiteSpace(component._soundName))
{
PlaySingleSound(component._soundName, component);
}
else 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) private void PlayRandomSoundFromCollection(BaseEmitSoundComponent component)
{ {
var file = SelectRandomSoundFromSoundCollection(component.SoundCollectionName!); if (!string.IsNullOrWhiteSpace(component._soundCollectionName))
PlaySingleSound(file, component); {
var file = SelectRandomSoundFromSoundCollection(component._soundCollectionName);
PlaySingleSound(file, component);
}
} }
private string SelectRandomSoundFromSoundCollection(string soundCollectionName) private string SelectRandomSoundFromSoundCollection(string soundCollectionName)
@@ -57,10 +65,15 @@ namespace Content.Server.Sound
private static void PlaySingleSound(string soundName, BaseEmitSoundComponent component) 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, SoundSystem.Play(Filter.Pvs(component.Owner), soundName, component.Owner,
AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f)); AudioHelpers.WithVariation(component._pitchVariation).WithVolume(-2f));
} }
else else
{ {

View File

@@ -10,6 +10,7 @@ namespace Content.Server.Throwing
public class EmitSoundOnThrowComponent : BaseEmitSoundComponent public class EmitSoundOnThrowComponent : BaseEmitSoundComponent
{ {
/// <inheritdoc /> /// <inheritdoc />
///
public override string Name => "EmitSoundOnThrow"; public override string Name => "EmitSoundOnThrow";
} }
} }