Skip to content

Commit

Permalink
start hacking in some level of BC
Browse files Browse the repository at this point in the history
  • Loading branch information
sowelipililimute committed Nov 30, 2024
1 parent e7f63da commit 560f59a
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Robust.Client/Audio/AudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public float GetOcclusion(MapCoordinates listener, Vector2 delta, float distance

private bool TryGetAudio(ResolvedSoundSpecifier specifier, [NotNullWhen(true)] out AudioResource? audio)
{
var filename = GetAudioPath(specifier) ?? string.Empty;
var filename = GetSoundPath(specifier) ?? string.Empty;
if (_resourceCache.TryGetResource(new ResPath(filename), out audio))
return true;

Expand Down
2 changes: 1 addition & 1 deletion Robust.Shared/Audio/ResolvedSoundSpecifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Robust.Shared.Audio;
[Serializable, NetSerializable]
public abstract partial class ResolvedSoundSpecifier {
[Obsolete("String literals for sounds are deprecated, use a SoundSpecifier or ResolvedSoundSpecifier as appropriate instead")]
public static implicit operator ResolvedSoundSpecifier(string s) => new ResolvedPathSpecifier(s);
public static implicit operator ResolvedSoundSpecifier(string? s) => s is string path ? new ResolvedPathSpecifier(path) : null!;
[Obsolete("String literals for sounds are deprecated, use a SoundSpecifier or ResolvedSoundSpecifier as appropriate instead")]
public static implicit operator ResolvedSoundSpecifier(ResPath s) => new ResolvedPathSpecifier(s);

Expand Down
88 changes: 73 additions & 15 deletions Robust.Shared/Audio/Systems/SharedAudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public float GetAudioDistance(float length)
/// <summary>
/// Resolves the filepath to a sound file.
/// </summary>
public ResolvedSoundSpecifier GetSound(SoundSpecifier specifier)
public ResolvedSoundSpecifier ResolveSound(SoundSpecifier specifier)
{
switch (specifier)
{
Expand All @@ -294,9 +294,67 @@ public ResolvedSoundSpecifier GetSound(SoundSpecifier specifier)
return new ResolvedPathSpecifier(string.Empty);
}

[Obsolete("Use ResolvedSound instead")]
public string GetSound(SoundSpecifier specifier)
{
switch (specifier)
{
case SoundPathSpecifier path:
return path.Path == default ? string.Empty : path.Path.ToString();

case SoundCollectionSpecifier collection:
{
if (collection.Collection == null)
return string.Empty;

var soundCollection = ProtoMan.Index<SoundCollectionPrototype>(collection.Collection);
return RandMan.Pick(soundCollection.PickFiles).ToString();
}
}

return string.Empty;
}

[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null) =>
PlayGlobal((ResolvedSoundSpecifier)filename, playerFilter, recordReplay, audioParams);
[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, ICommonSession recipient, AudioParams? audioParams = null) =>
PlayGlobal((ResolvedSoundSpecifier)filename, recipient, audioParams);
[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(string? filename, EntityUid recipient, AudioParams? audioParams = null) =>
PlayGlobal((ResolvedSoundSpecifier)filename, recipient, audioParams);

[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null) =>
PlayEntity((ResolvedSoundSpecifier)filename, playerFilter, uid, recordReplay, audioParams);
[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null) =>
PlayEntity((ResolvedSoundSpecifier)filename, recipient, uid, audioParams);
[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(string? filename, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null) =>
PlayEntity((ResolvedSoundSpecifier)filename, recipient, uid, audioParams);

[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename, EntityCoordinates coordinates, AudioParams? audioParams = null) =>
PlayPvs((ResolvedSoundSpecifier)filename, coordinates, audioParams);
[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(string? filename, EntityUid uid, AudioParams? audioParams = null) =>
PlayPvs((ResolvedSoundSpecifier)filename, uid, audioParams);

[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null) =>
PlayStatic((ResolvedSoundSpecifier)filename, playerFilter, coordinates, recordReplay, audioParams);
[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) =>
PlayStatic((ResolvedSoundSpecifier)filename, recipient, coordinates, audioParams);
[Obsolete("Use the ResolvedSoundSpecifier overload instead")]
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(string? filename, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null) =>
PlayStatic((ResolvedSoundSpecifier)filename, recipient, coordinates, audioParams);

#region AudioParams

public string? GetAudioPath(ResolvedSoundSpecifier? specifier)
public string? GetSoundPath(ResolvedSoundSpecifier? specifier)
{
return specifier switch {

Check warning on line 359 in Robust.Shared/Audio/Systems/SharedAudioSystem.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern 'not null' is not covered.

Check warning on line 359 in Robust.Shared/Audio/Systems/SharedAudioSystem.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern 'not null' is not covered.
ResolvedPathSpecifier path =>
Expand All @@ -312,7 +370,7 @@ collection.Collection is null ?
protected Entity<AudioComponent> SetupAudio(ResolvedSoundSpecifier? specifier, AudioParams? audioParams, bool initialize = true, TimeSpan? length = null)
{
var uid = EntityManager.CreateEntityUninitialized("Audio", MapCoordinates.Nullspace);
var fileName = GetAudioPath(specifier);
var fileName = GetSoundPath(specifier);
DebugTools.Assert(!string.IsNullOrEmpty(fileName) || length is not null);
MetadataSys.SetEntityName(uid, $"Audio ({fileName})", raiseEvents: false);
audioParams ??= AudioParams.Default;
Expand Down Expand Up @@ -400,7 +458,7 @@ public void SetVolume(EntityUid? entity, float value, AudioComponent? component
/// </summary>
public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
{
var filename = GetAudioPath(specifier) ?? string.Empty;
var filename = GetSoundPath(specifier) ?? string.Empty;
if (!filename.StartsWith("/"))
throw new ArgumentException("Path must be rooted");

Expand Down Expand Up @@ -442,7 +500,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
/// <param name="playerFilter">The set of players that will hear the sound.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, Filter playerFilter, bool recordReplay, AudioParams? audioParams = null)
{
return sound == null ? null : PlayGlobal(GetSound(sound), playerFilter, recordReplay, audioParams ?? sound.Params);
return sound == null ? null : PlayGlobal(ResolveSound(sound), playerFilter, recordReplay, audioParams ?? sound.Params);
}

/// <summary>
Expand All @@ -459,7 +517,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
/// <param name="recipient">The player that will hear the sound.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, ICommonSession recipient, AudioParams? audioParams = null)
{
return sound == null ? null : PlayGlobal(GetSound(sound), recipient, audioParams ?? sound.Params);
return sound == null ? null : PlayGlobal(ResolveSound(sound), recipient, audioParams ?? sound.Params);
}

public abstract void LoadStream<T>(Entity<AudioComponent> entity, T stream);
Expand All @@ -478,7 +536,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
/// <param name="recipient">The player that will hear the sound.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayGlobal(SoundSpecifier? sound, EntityUid recipient, AudioParams? audioParams = null)
{
return sound == null ? null : PlayGlobal(GetSound(sound), recipient, audioParams ?? sound.Params);
return sound == null ? null : PlayGlobal(ResolveSound(sound), recipient, audioParams ?? sound.Params);
}

/// <summary>
Expand Down Expand Up @@ -513,7 +571,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, Filter playerFilter, EntityUid uid, bool recordReplay, AudioParams? audioParams = null)
{
return sound == null ? null : PlayEntity(GetSound(sound), playerFilter, uid, recordReplay, audioParams ?? sound.Params);
return sound == null ? null : PlayEntity(ResolveSound(sound), playerFilter, uid, recordReplay, audioParams ?? sound.Params);
}

/// <summary>
Expand All @@ -524,7 +582,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, ICommonSession recipient, EntityUid uid, AudioParams? audioParams = null)
{
return sound == null ? null : PlayEntity(GetSound(sound), recipient, uid, audioParams ?? sound.Params);
return sound == null ? null : PlayEntity(ResolveSound(sound), recipient, uid, audioParams ?? sound.Params);
}

/// <summary>
Expand All @@ -535,7 +593,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayEntity(SoundSpecifier? sound, EntityUid recipient, EntityUid uid, AudioParams? audioParams = null)
{
return sound == null ? null : PlayEntity(GetSound(sound), recipient, uid, audioParams ?? sound.Params);
return sound == null ? null : PlayEntity(ResolveSound(sound), recipient, uid, audioParams ?? sound.Params);
}

/// <summary>
Expand All @@ -545,7 +603,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
/// <param name="uid">The UID of the entity "emitting" the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(SoundSpecifier? sound, EntityUid uid, AudioParams? audioParams = null)
{
return sound == null ? null : PlayPvs(GetSound(sound), uid, audioParams ?? sound.Params);
return sound == null ? null : PlayPvs(ResolveSound(sound), uid, audioParams ?? sound.Params);
}

/// <summary>
Expand All @@ -555,7 +613,7 @@ public TimeSpan GetAudioLength(ResolvedSoundSpecifier specifier)
/// <param name="coordinates">The EntityCoordinates to attach the audio source to.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayPvs(SoundSpecifier? sound, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return sound == null ? null : PlayPvs(GetSound(sound), coordinates, audioParams ?? sound.Params);
return sound == null ? null : PlayPvs(ResolveSound(sound), coordinates, audioParams ?? sound.Params);
}

/// <summary>
Expand Down Expand Up @@ -634,7 +692,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, Filter playerFilter, EntityCoordinates coordinates, bool recordReplay, AudioParams? audioParams = null)
{
return sound == null ? null : PlayStatic(GetSound(sound), playerFilter, coordinates, recordReplay, audioParams);
return sound == null ? null : PlayStatic(ResolveSound(sound), playerFilter, coordinates, recordReplay, audioParams);
}

/// <summary>
Expand All @@ -645,7 +703,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, ICommonSession recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return sound == null ? null : PlayStatic(GetSound(sound), recipient, coordinates, audioParams ?? sound.Params);
return sound == null ? null : PlayStatic(ResolveSound(sound), recipient, coordinates, audioParams ?? sound.Params);
}

/// <summary>
Expand All @@ -656,7 +714,7 @@ public abstract (EntityUid Entity, Components.AudioComponent Component)? PlayPvs
/// <param name="coordinates">The coordinates at which to play the audio.</param>
public (EntityUid Entity, Components.AudioComponent Component)? PlayStatic(SoundSpecifier? sound, EntityUid recipient, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return sound == null ? null : PlayStatic(GetSound(sound), recipient, coordinates, audioParams ?? sound.Params);
return sound == null ? null : PlayStatic(ResolveSound(sound), recipient, coordinates, audioParams ?? sound.Params);
}

// These are just here for replays now.
Expand Down

0 comments on commit 560f59a

Please sign in to comment.