#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 public class EmitSoundOnUseComponent : BaseEmitSoundComponent
{ {
/// <inheritdoc /> /// <inheritdoc />
///
public override string Name => "EmitSoundOnUse"; public override string Name => "EmitSoundOnUse";
} }
} }

View File

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

View File

@@ -9,7 +9,6 @@ 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

@@ -2,7 +2,6 @@ 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,8 +12,7 @@ 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
@@ -34,28 +32,25 @@ namespace Content.Server.GameObjects.EntitySystems
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)) else if (!string.IsNullOrWhiteSpace(component.SoundName))
{ {
PlaySingleSound(component._soundName, component); PlaySingleSound(component.SoundName, component);
} }
else 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) private void PlayRandomSoundFromCollection(BaseEmitSoundComponent component)
{ {
if (!string.IsNullOrWhiteSpace(component._soundCollectionName)) var file = SelectRandomSoundFromSoundCollection(component.SoundCollectionName!);
{
var file = SelectRandomSoundFromSoundCollection(component._soundCollectionName);
PlaySingleSound(file, component); PlaySingleSound(file, component);
} }
}
private string SelectRandomSoundFromSoundCollection(string soundCollectionName) private string SelectRandomSoundFromSoundCollection(string soundCollectionName)
{ {
@@ -64,22 +59,9 @@ namespace Content.Server.GameObjects.EntitySystems
} }
private static void PlaySingleSound(string soundName, BaseEmitSoundComponent component) 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, SoundSystem.Play(Filter.Pvs(component.Owner), soundName, component.Owner,
AudioHelpers.WithVariation(component._pitchVariation).WithVolume(-2f)); AudioHelpers.WithVariation(component.PitchVariation).WithVolume(-2f));
}
else
{
SoundSystem.Play(Filter.Pvs(component.Owner), soundName, component.Owner,
AudioParams.Default.WithVolume(-2f));
}
} }
} }
} }

View File

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