Skip to content

Commit

Permalink
Return GetSound to original string return, obsolete it, replace with …
Browse files Browse the repository at this point in the history
…new ResolveSound() method.

This fixes all but one compile error in current content (the remaining one is a content bug anyway).
  • Loading branch information
PJB3005 committed Dec 24, 2024
1 parent ef1b41b commit efbf8bd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Robust.Server/Audio/AudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPredicted(Soun
if (sound == null)
return null;

var audio = PlayPvs(GetSound(sound), source, audioParams ?? sound.Params);
var audio = PlayPvs(ResolveSound(sound), source, audioParams ?? sound.Params);

if (audio == null)
return null;
Expand All @@ -201,7 +201,7 @@ public override (EntityUid Entity, AudioComponent Component)? PlayPredicted(Soun
if (sound == null)
return null;

var audio = PlayPvs(GetSound(sound), coordinates, audioParams ?? sound.Params);
var audio = PlayPvs(ResolveSound(sound), coordinates, audioParams ?? sound.Params);

if (audio == null)
return null;
Expand Down
37 changes: 24 additions & 13 deletions Robust.Shared/Audio/Systems/SharedAudioSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ public float GetAudioDistance(float length)
}

/// <summary>
/// Resolves the filepath to a sound file.
/// Resolve a sound specifier so it can be consistently played back on all clients.
/// </summary>
public ResolvedSoundSpecifier GetSound(SoundSpecifier specifier)
public ResolvedSoundSpecifier ResolveSound(SoundSpecifier specifier)
{
switch (specifier)
{
Expand All @@ -294,8 +294,19 @@ public ResolvedSoundSpecifier GetSound(SoundSpecifier specifier)
return new ResolvedPathSpecifier(string.Empty);
}

/// <summary>
/// Resolves the filepath to a sound file.
/// </summary>
[Obsolete("Use ResolveSound() and pass around resolved sound specifiers instead.")]
public string GetSound(SoundSpecifier specifier)
{
var resolved = ResolveSound(specifier);
return GetAudioPath(resolved);
}

#region AudioParams

[return: NotNullIfNotNull(nameof(specifier))]
public string? GetAudioPath(ResolvedSoundSpecifier? specifier)
{
return specifier switch {
Expand Down Expand Up @@ -442,7 +453,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 +470,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 +489,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 +524,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 +535,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 +546,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 +556,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 +566,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 +645,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 +656,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 +667,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 efbf8bd

Please sign in to comment.