#4219 single sounds in EmitSoundSystem should work now

This commit is contained in:
Galactic Chimp
2021-06-27 21:48:57 +02:00
parent a0889a9151
commit 4a2b9832ce
6 changed files with 14 additions and 36 deletions

View File

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

View File

@@ -6,13 +6,13 @@ namespace Content.Server.Sound
{
/// <summary>
/// Base sound emitter which defines most of the data fields.
/// Default behavior first try to play the sound collection,
/// and if one isn't assigned, then it will try to play the single sound.
/// Default behavior is to first try to play the sound collection,
/// and if one isn't assigned, then try to play the single sound.
/// </summary>
public abstract class BaseEmitSoundComponent : Component
{
[ViewVariables(VVAccess.ReadWrite)] [DataField("sound")] public string? _soundName;
[ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float _pitchVariation;
[ViewVariables(VVAccess.ReadWrite)] [DataField("soundCollection")] public string? _soundCollectionName;
[ViewVariables(VVAccess.ReadWrite)] [DataField("sound")] public string? SoundName { get; set; } = default!;
[ViewVariables(VVAccess.ReadWrite)] [DataField("variation")] public float PitchVariation { get; set; } = 0.0f;
[ViewVariables(VVAccess.ReadWrite)] [DataField("soundCollection")] public string? SoundCollectionName { get; set; } = default!;
}
}

View File

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

View File

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

View File

@@ -2,7 +2,6 @@ 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,8 +12,7 @@ using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Log;
namespace Content.Server.GameObjects.EntitySystems
namespace Content.Server.Sound
{
[UsedImplicitly]
public class EmitSoundSystem : EntitySystem
@@ -34,28 +32,25 @@ namespace Content.Server.GameObjects.EntitySystems
private void PlaySound(BaseEmitSoundComponent component)
{
if (!string.IsNullOrWhiteSpace(component._soundCollectionName))
if (!string.IsNullOrWhiteSpace(component.SoundCollectionName))
{
PlayRandomSoundFromCollection(component);
}
else if(!string.IsNullOrWhiteSpace(component._soundName))
else if (!string.IsNullOrWhiteSpace(component.SoundName))
{
PlaySingleSound(component._soundName, component);
PlaySingleSound(component.SoundName, component);
}
else
{
Logger.Warning($"{nameof(component)} Uid:{component.Owner.Uid} has neither {nameof(component._soundCollectionName)} nor {nameof(component._soundName)} 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)
{
if (!string.IsNullOrWhiteSpace(component._soundCollectionName))
{
var file = SelectRandomSoundFromSoundCollection(component._soundCollectionName);
var file = SelectRandomSoundFromSoundCollection(component.SoundCollectionName!);
PlaySingleSound(file, component);
}
}
private string SelectRandomSoundFromSoundCollection(string soundCollectionName)
{
@@ -64,22 +59,9 @@ namespace Content.Server.GameObjects.EntitySystems
}
private static void PlaySingleSound(string soundName, BaseEmitSoundComponent component)
{
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));
}
else
{
SoundSystem.Play(Filter.Pvs(component.Owner), soundName, component.Owner,
AudioParams.Default.WithVolume(-2f));
}
AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f));
}
}
}

View File

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