Skip to content

Commit

Permalink
Fix invalid UI hover/click sounds breaking client (space-wizards#30067)
Browse files Browse the repository at this point in the history
  • Loading branch information
PJB3005 authored and Baa14453 committed Oct 19, 2024
1 parent de50d3f commit b4b657d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Content.Client/Audio/AudioUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void SetClickSound(string value)
{
if (!string.IsNullOrEmpty(value))
{
var resource = _cache.GetResource<AudioResource>(value);
var resource = GetSoundOrFallback(value, CCVars.UIClickSound.DefaultValue);
var source =
_audioManager.CreateAudioSource(resource);

Expand All @@ -77,7 +77,7 @@ private void SetHoverSound(string value)
{
if (!string.IsNullOrEmpty(value))
{
var hoverResource = _cache.GetResource<AudioResource>(value);
var hoverResource = GetSoundOrFallback(value, CCVars.UIHoverSound.DefaultValue);
var hoverSource =
_audioManager.CreateAudioSource(hoverResource);

Expand All @@ -95,4 +95,12 @@ private void SetHoverSound(string value)
UIManager.SetHoverSound(null);
}
}

private AudioResource GetSoundOrFallback(string path, string fallback)
{
if (!_cache.TryGetResource(path, out AudioResource? resource))
return _cache.GetResource<AudioResource>(fallback);

return resource;
}
}

0 comments on commit b4b657d

Please sign in to comment.