Files
tbd-station-14/Content.Shared/Sound/SoundSpecifier.cs
2022-05-28 13:03:21 +02:00

73 lines
2.2 KiB
C#

using Content.Shared.Audio;
using JetBrains.Annotations;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Serialization.TypeSerializers.Implementations;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Utility;
namespace Content.Shared.Sound
{
[ImplicitDataDefinitionForInheritors]
public abstract class SoundSpecifier
{
[ViewVariables(VVAccess.ReadWrite), DataField("params")]
public AudioParams Params = AudioParams.Default;
// TODO: remove most uses of this function, and just make the audio-system take in a SoundSpecifier
public abstract string GetSound(IRobustRandom? rand = null, IPrototypeManager? proto = null);
}
public sealed class SoundPathSpecifier : SoundSpecifier
{
public const string Node = "path";
[DataField(Node, customTypeSerializer: typeof(ResourcePathSerializer), required: true)]
public ResourcePath? Path { get; }
[UsedImplicitly]
public SoundPathSpecifier()
{
}
public SoundPathSpecifier(string path)
{
Path = new ResourcePath(path);
}
public SoundPathSpecifier(ResourcePath path)
{
Path = path;
}
public override string GetSound(IRobustRandom? rand = null, IPrototypeManager? proto = null)
{
return Path == null ? string.Empty : Path.ToString();
}
}
public sealed class SoundCollectionSpecifier : SoundSpecifier
{
public const string Node = "collection";
[DataField(Node, customTypeSerializer: typeof(PrototypeIdSerializer<SoundCollectionPrototype>), required: true)]
public string? Collection { get; }
[UsedImplicitly]
public SoundCollectionSpecifier()
{
}
public SoundCollectionSpecifier(string collection)
{
Collection = collection;
}
public override string GetSound(IRobustRandom? rand = null, IPrototypeManager? proto = null)
{
return Collection == null ? string.Empty : AudioHelpers.GetRandomFileFromSoundCollection(Collection, rand, proto);
}
}
}