Attempt to reduce audio helper resolves (#8493)
This commit is contained in:
@@ -8,9 +8,19 @@ namespace Content.Shared.Audio
|
||||
/// <summary>
|
||||
/// Returns a random pitch.
|
||||
/// </summary>
|
||||
[Obsolete("Use variant that takes in IRobustRandom instead.")]
|
||||
public static AudioParams WithVariation(float amplitude)
|
||||
{
|
||||
var scale = (float)(IoCManager.Resolve<IRobustRandom>().NextGaussian(1, amplitude));
|
||||
return WithVariation(amplitude, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a random pitch.
|
||||
/// </summary>
|
||||
public static AudioParams WithVariation(float amplitude, IRobustRandom? rand)
|
||||
{
|
||||
IoCManager.Resolve(ref rand);
|
||||
var scale = (float) rand.NextGaussian(1, amplitude);
|
||||
return AudioParams.Default.WithPitchScale(scale);
|
||||
}
|
||||
|
||||
@@ -43,16 +53,18 @@ namespace Content.Shared.Audio
|
||||
/// Returns a pitch multiplier shifted by a random number of semitones within variation.
|
||||
/// </summary>
|
||||
/// <param name="variation">Max number of semitones to shift in either direction. Values above 12 have no effect.</param>
|
||||
public static AudioParams WithSemitoneVariation(int variation)
|
||||
public static AudioParams WithSemitoneVariation(int variation, IRobustRandom? rand)
|
||||
{
|
||||
IoCManager.Resolve(ref rand);
|
||||
variation = Math.Clamp(variation, 0, 12);
|
||||
return ShiftSemitone(IoCManager.Resolve<IRobustRandom>().Next(-variation, variation));
|
||||
return ShiftSemitone(rand.Next(-variation, variation));
|
||||
}
|
||||
|
||||
public static string GetRandomFileFromSoundCollection(string name)
|
||||
public static string GetRandomFileFromSoundCollection(string name, IRobustRandom? rand, IPrototypeManager? proto)
|
||||
{
|
||||
var soundCollection = IoCManager.Resolve<IPrototypeManager>().Index<SoundCollectionPrototype>(name);
|
||||
return IoCManager.Resolve<IRobustRandom>().Pick(soundCollection.PickFiles).ToString();
|
||||
IoCManager.Resolve(ref rand, ref proto);
|
||||
var soundCollection = proto.Index<SoundCollectionPrototype>(name);
|
||||
return rand.Pick(soundCollection.PickFiles).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
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;
|
||||
@@ -13,7 +15,8 @@ namespace Content.Shared.Sound
|
||||
[ViewVariables(VVAccess.ReadWrite), DataField("params")]
|
||||
public AudioParams Params = AudioParams.Default;
|
||||
|
||||
public abstract string GetSound();
|
||||
// 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
|
||||
@@ -38,7 +41,7 @@ namespace Content.Shared.Sound
|
||||
Path = path;
|
||||
}
|
||||
|
||||
public override string GetSound()
|
||||
public override string GetSound(IRobustRandom? rand = null, IPrototypeManager? proto = null)
|
||||
{
|
||||
return Path == null ? string.Empty : Path.ToString();
|
||||
}
|
||||
@@ -61,9 +64,9 @@ namespace Content.Shared.Sound
|
||||
Collection = collection;
|
||||
}
|
||||
|
||||
public override string GetSound()
|
||||
public override string GetSound(IRobustRandom? rand = null, IPrototypeManager? proto = null)
|
||||
{
|
||||
return Collection == null ? string.Empty : AudioHelpers.GetRandomFileFromSoundCollection(Collection);
|
||||
return Collection == null ? string.Empty : AudioHelpers.GetRandomFileFromSoundCollection(Collection, rand, proto);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user