replacing sound (collection) names with SoundSpecifier - part 1

This commit is contained in:
Galactic Chimp
2021-07-10 17:35:33 +02:00
parent 4500b66f28
commit ce3c59e0e6
131 changed files with 934 additions and 587 deletions

View File

@@ -1,6 +1,7 @@
using Content.Server.Chemistry.Components;
using Content.Server.Fluids.Components;
using Content.Shared.Audio;
using Content.Shared.Sound;
using Content.Shared.Throwing;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
@@ -19,10 +20,13 @@ namespace Content.Server.Nutrition.Components
[DataField("paralyzeTime")]
public float ParalyzeTime { get; set; } = 1f;
[DataField("sound")]
private SoundSpecifier _sound = new SoundCollectionSpecifier("desacration");
public void PlaySound()
{
SoundSystem.Play(Filter.Pvs(Owner), AudioHelpers.GetRandomFileFromSoundCollection("desecration"), Owner,
AudioHelpers.WithVariation(0.125f));
if(_sound.TryGetSound(out var sound))
SoundSystem.Play(Filter.Pvs(Owner), sound, Owner, AudioHelpers.WithVariation(0.125f));
}
void IThrowCollide.DoHit(ThrowCollideEventArgs eventArgs)

View File

@@ -15,6 +15,7 @@ using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification;
using Content.Shared.Notification.Managers;
using Content.Shared.Nutrition.Components;
using Content.Shared.Sound;
using Content.Shared.Throwing;
using JetBrains.Annotations;
using Robust.Server.GameObjects;
@@ -46,7 +47,7 @@ namespace Content.Server.Nutrition.Components
[ViewVariables]
[DataField("useSound")]
private string _useSound = "/Audio/Items/drink.ogg";
private SoundSpecifier _useSound = new SoundPathSpecifier("/Audio/Items/drink.ogg");
[ViewVariables]
[DataField("isOpen")]
@@ -75,11 +76,11 @@ namespace Content.Server.Nutrition.Components
public bool Empty => Owner.GetComponentOrNull<ISolutionInteractionsComponent>()?.DrainAvailable <= 0;
[DataField("openSounds")]
private string _soundCollection = "canOpenSounds";
private SoundSpecifier _openSounds = new SoundCollectionSpecifier("canOpenSounds");
[DataField("pressurized")]
private bool _pressurized = default;
[DataField("burstSound")]
private string _burstSound = "/Audio/Effects/flash_bang.ogg";
private SoundSpecifier _burstSound = new SoundPathSpecifier("/Audio/Effects/flash_bang.ogg");
protected override void Initialize()
{
@@ -127,10 +128,9 @@ namespace Content.Server.Nutrition.Components
if (!Opened)
{
//Do the opening stuff like playing the sounds.
var soundCollection = _prototypeManager.Index<SoundCollectionPrototype>(_soundCollection);
var file = _random.Pick(soundCollection.PickFiles);
if(_openSounds.TryGetSound(out var openSound))
SoundSystem.Play(Filter.Pvs(args.User), openSound, args.User, AudioParams.Default);
SoundSystem.Play(Filter.Pvs(args.User), file, args.User, AudioParams.Default);
Opened = true;
return false;
}
@@ -220,9 +220,9 @@ namespace Content.Server.Nutrition.Components
return false;
}
if (!string.IsNullOrEmpty(_useSound))
if (_useSound.TryGetSound(out var useSound))
{
SoundSystem.Play(Filter.Pvs(target), _useSound, target, AudioParams.Default.WithVolume(-2f));
SoundSystem.Play(Filter.Pvs(target), useSound, target, AudioParams.Default.WithVolume(-2f));
}
target.PopupMessage(Loc.GetString("drink-component-try-use-drink-success-slurp"));
@@ -254,8 +254,8 @@ namespace Content.Server.Nutrition.Components
var solution = interactions.Drain(interactions.DrainAvailable);
solution.SpillAt(Owner, "PuddleSmear");
SoundSystem.Play(Filter.Pvs(Owner), _burstSound, Owner,
AudioParams.Default.WithVolume(-4));
if(_burstSound.TryGetSound(out var burstSound))
SoundSystem.Play(Filter.Pvs(Owner), burstSound, Owner, AudioParams.Default.WithVolume(-4));
}
}
}

View File

@@ -13,6 +13,7 @@ using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Notification;
using Content.Shared.Notification.Managers;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Localization;
@@ -30,7 +31,7 @@ namespace Content.Server.Nutrition.Components
{
public override string Name => "Food";
[ViewVariables] [DataField("useSound")] protected virtual string? UseSound { get; set; } = "/Audio/Items/eatfood.ogg";
[ViewVariables] [DataField("useSound")] protected virtual SoundSpecifier UseSound { get; set; } = new SoundPathSpecifier("/Audio/Items/eatfood.ogg");
[ViewVariables] [DataField("trash", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))] protected virtual string? TrashPrototype { get; set; }
@@ -160,9 +161,9 @@ namespace Content.Server.Nutrition.Components
firstStomach.TryTransferSolution(split);
if (UseSound != null)
if (UseSound.TryGetSound(out var useSound))
{
SoundSystem.Play(Filter.Pvs(trueTarget), UseSound, trueTarget, AudioParams.Default.WithVolume(-1f));
SoundSystem.Play(Filter.Pvs(trueTarget), useSound, trueTarget, AudioParams.Default.WithVolume(-1f));
}
trueTarget.PopupMessage(user, Loc.GetString("food-nom"));

View File

@@ -5,6 +5,7 @@ using Content.Server.Items;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
@@ -27,7 +28,7 @@ namespace Content.Server.Nutrition.Components
private string _slice = string.Empty;
[DataField("sound")] [ViewVariables(VVAccess.ReadWrite)]
private string _sound = "/Audio/Items/Culinary/chop.ogg";
private SoundSpecifier _sound = new SoundPathSpecifier("/Audio/Items/Culinary/chop.ogg");
[DataField("count")] [ViewVariables(VVAccess.ReadWrite)]
private ushort _totalCount = 5;
@@ -66,8 +67,9 @@ namespace Content.Server.Nutrition.Components
}
}
SoundSystem.Play(Filter.Pvs(Owner), _sound, Owner.Transform.Coordinates,
AudioParams.Default.WithVolume(-2));
if(_sound.TryGetSound(out var sound))
SoundSystem.Play(Filter.Pvs(Owner), sound, Owner.Transform.Coordinates,
AudioParams.Default.WithVolume(-2));
Count--;
if (Count < 1)

View File

@@ -3,6 +3,7 @@ using System;
using System.Threading.Tasks;
using Content.Shared.Interaction;
using Content.Shared.Interaction.Helpers;
using Content.Shared.Sound;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -47,7 +48,7 @@ namespace Content.Server.Nutrition.Components
/// </summary>
[ViewVariables]
[DataField("breakSound")]
private string? _breakSound = "/Audio/Items/snap.ogg";
private SoundSpecifier _breakSound = new SoundPathSpecifier("/Audio/Items/snap.ogg");
public void AddType(UtensilType type)
{
@@ -71,9 +72,9 @@ namespace Content.Server.Nutrition.Components
internal void TryBreak(IEntity user)
{
if (_breakSound != null && IoCManager.Resolve<IRobustRandom>().Prob(_breakChance))
if (_breakSound.TryGetSound(out var breakSound) && IoCManager.Resolve<IRobustRandom>().Prob(_breakChance))
{
SoundSystem.Play(Filter.Pvs(user), _breakSound, user, AudioParams.Default.WithVolume(-2f));
SoundSystem.Play(Filter.Pvs(user), breakSound, user, AudioParams.Default.WithVolume(-2f));
Owner.Delete();
}
}